GxEPD2_WS_ESP32_Driver.ino 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  1. // Display Library example for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
  2. // Requires HW SPI and Adafruit_GFX. Caution: the e-paper panels require 3.3V supply AND data lines!
  3. //
  4. // Display Library based on Demo Example from Good Display: http://www.e-paper-display.com/download_list/downloadcategoryid=34&isMode=false.html
  5. //
  6. // Author: Jean-Marc Zingg
  7. //
  8. // Version: see library.properties
  9. //
  10. // Library: https://github.com/ZinggJM/GxEPD2
  11. // GxEPD2_WS_ESP32_Driver : GxEPD2_Example variant for Universal e-Paper Raw Panel Driver Board, ESP32 WiFi / Bluetooth Wireless
  12. // https://www.waveshare.com/product/e-paper-esp32-driver-board.htm
  13. // Supporting Arduino Forum Topics:
  14. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  15. // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  16. // mapping of Waveshare ESP32 Driver Board
  17. // BUSY -> 25, RST -> 26, DC -> 27, CS-> 15, CLK -> 13, DIN -> 14
  18. // NOTE: this board uses "unusual" SPI pins and requires re-mapping of HW SPI to these pins in SPIClass
  19. // this example shows how this can be done easily, updated for use with HSPI
  20. //
  21. // The Wavehare ESP32 Driver Board uses uncommon SPI pins for the FPC connector. It uses HSPI pins, but SCK and MOSI are swapped.
  22. // To use HW SPI with the ESP32 Driver Board, HW SPI pins need be re-mapped in any case. Can be done using either HSPI or VSPI.
  23. // Other SPI clients can either be connected to the same SPI bus as the e-paper, or to the other HW SPI bus, or through SW SPI.
  24. // The logical configuration would be to use the e-paper connection on HSPI with re-mapped pins, and use VSPI for other SPI clients.
  25. // VSPI with standard VSPI pins is used by the global SPI instance of the Arduino IDE ESP32 package.
  26. // uncomment next line to use HSPI for EPD (and VSPI for SD), e.g. with Waveshare ESP32 Driver Board
  27. #define USE_HSPI_FOR_EPD
  28. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  29. // enable or disable GxEPD2_GFX base class
  30. #define ENABLE_GxEPD2_GFX 0
  31. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  32. //#include <GFX.h>
  33. // Note: if you use this with ENABLE_GxEPD2_GFX 1:
  34. // uncomment it in GxEPD2_GFX.h too, or add #include <GFX.h> before any #include <GxEPD2_GFX.h>
  35. #include <GxEPD2_BW.h>
  36. #include <GxEPD2_3C.h>
  37. #include <Fonts/FreeMonoBold9pt7b.h>
  38. // select the display class (only one), matching the kind of display panel
  39. #define GxEPD2_DISPLAY_CLASS GxEPD2_BW
  40. //#define GxEPD2_DISPLAY_CLASS GxEPD2_3C
  41. //#define GxEPD2_DISPLAY_CLASS GxEPD2_7C
  42. // select the display driver class (only one) for your panel
  43. //#define GxEPD2_DRIVER_CLASS GxEPD2_102 // GxEPD2_102 80x128, UC8175
  44. //#define GxEPD2_DRIVER_CLASS GxEPD2_154 // GDEP015OC1 200x200, IL3829, no longer available
  45. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_D67 // GDEH0154D67 200x200, SSD1681
  46. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_T8 // GDEW0154T8 152x152, UC8151 (IL0373)
  47. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_M09 // GDEW0154M09 200x200, JD79653A
  48. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_M10 // GDEW0154M10 152x152, UC8151D
  49. //#define GxEPD2_DRIVER_CLASS GxEPD2_213 // GDE0213B1 128x250, IL3895, phased out
  50. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_B72 // GDEH0213B72 128x250, SSD1675A (IL3897)
  51. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_B73 // GDEH0213B73 128x250, SSD1675B
  52. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_B74 // GDEM0213B74 128x250, SSD1680
  53. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_flex // GDEW0213I5F 104x212, UC8151 (IL0373)
  54. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_M21 // GDEW0213M21 104x212, UC8151 (IL0373)
  55. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_T5D // GDEW0213T5D 104x212, UC8151D
  56. //#define GxEPD2_DRIVER_CLASS GxEPD2_290 // GDEH029A1 128x296, SSD1608 (IL3820)
  57. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T5 // GDEW029T5 128x296, UC8151 (IL0373)
  58. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T5D // GDEW029T5D 128x296, UC8151D
  59. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_I6FD // GDEW029I6FD 128x296, UC8151D
  60. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T94 // GDEM029T94 128x296, SSD1680
  61. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T94_V2 // GDEM029T94 128x296, SSD1680, Waveshare 2.9" V2 variant
  62. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_M06 // GDEW029M06 128x296, UC8151D
  63. //#define GxEPD2_DRIVER_CLASS GxEPD2_260 // GDEW026T0 152x296, UC8151 (IL0373)
  64. //#define GxEPD2_DRIVER_CLASS GxEPD2_260_M01 // GDEW026M01 152x296, UC8151 (IL0373)
  65. //#define GxEPD2_DRIVER_CLASS GxEPD2_270 // GDEW027W3 176x264, EK79652 (IL91874)
  66. //#define GxEPD2_DRIVER_CLASS GxEPD2_371 // GDEW0371W7 240x416, UC8171 (IL0324)
  67. //#define GxEPD2_DRIVER_CLASS GxEPD2_370_TC1 // ED037TC1 280x480, SSD1677, Waveshare 3.7"
  68. //#define GxEPD2_DRIVER_CLASS GxEPD2_420 // GDEW042T2 400x300, UC8176 (IL0398)
  69. //#define GxEPD2_DRIVER_CLASS GxEPD2_420_M01 // GDEW042M01 400x300, UC8176 (IL0398)
  70. //#define GxEPD2_DRIVER_CLASS GxEPD2_583 // GDEW0583T7 600x448, UC8159c (IL0371)
  71. //#define GxEPD2_DRIVER_CLASS GxEPD2_583_T8 // GDEW0583T8 648x480, EK79655 (GD7965)
  72. //#define GxEPD2_DRIVER_CLASS GxEPD2_750 // GDEW075T8 640x384, UC8159c (IL0371)
  73. //#define GxEPD2_DRIVER_CLASS GxEPD2_750_T7 // GDEW075T7 800x480, EK79655 (GD7965)
  74. //#define GxEPD2_DRIVER_CLASS GxEPD2_750_YT7 // GDEY075T7 800x480, UC8179 (GD7965)
  75. //#define GxEPD2_DRIVER_CLASS GxEPD2_1160_T91 // GDEH116T91 960x640, SSD1677
  76. //#define GxEPD2_DRIVER_CLASS GxEPD2_1248 // GDEW1248T3 1304x984, UC8179
  77. // 3-color e-papers
  78. //#define GxEPD2_DRIVER_CLASS GxEPD2_154c // GDEW0154Z04 200x200, IL0376F, no longer available
  79. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_Z90c // GDEH0154Z90 200x200, SSD1681
  80. //#define GxEPD2_DRIVER_CLASS GxEPD2_213c // GDEW0213Z16 104x212, UC8151 (IL0373)
  81. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_Z19c // GDEW0213Z19 104x212, UC8151D
  82. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_Z98c // GDEY0213Z98 122x250, SSD1680
  83. //#define GxEPD2_DRIVER_CLASS GxEPD2_290c // GDEW029Z10 128x296, UC8151 (IL0373)
  84. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_Z13c // GDEH029Z13 128x296, UC8151D
  85. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_C90c // GDEM029C90 128x296, SSD1680
  86. //#define GxEPD2_DRIVER_CLASS GxEPD2_266c // GDEY0266Z90 152x296, SSD1680
  87. //#define GxEPD2_DRIVER_CLASS GxEPD2_270c // GDEW027C44 176x264, IL91874
  88. //#define GxEPD2_DRIVER_CLASS GxEPD2_420c // GDEW042Z15 400x300, UC8176 (IL0398)
  89. //#define GxEPD2_DRIVER_CLASS GxEPD2_420c_Z21 // GDEQ042Z21 400x300, UC8276
  90. //#define GxEPD2_DRIVER_CLASS GxEPD2_583c // GDEW0583Z21 600x448, UC8159c (IL0371)
  91. //#define GxEPD2_DRIVER_CLASS GxEPD2_583c_Z83 // GDEW0583Z83 648x480, EK79655 (GD7965)
  92. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c // GDEW075Z09 640x384, UC8159c (IL0371)
  93. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c_Z08 // GDEW075Z08 800x480, EK79655 (GD7965)
  94. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c_Z90 // GDEH075Z90 880x528, SSD1677
  95. // 7-color e-paper
  96. //#define GxEPD2_DRIVER_CLASS GxEPD2_565c // Waveshare 5.65" 7-color (3C graphics)
  97. // somehow there should be an easier way to do this
  98. #define GxEPD2_BW_IS_GxEPD2_BW true
  99. #define GxEPD2_3C_IS_GxEPD2_3C true
  100. #define GxEPD2_7C_IS_GxEPD2_7C true
  101. #define GxEPD2_1248_IS_GxEPD2_1248 true
  102. #define IS_GxEPD(c, x) (c##x)
  103. #define IS_GxEPD2_BW(x) IS_GxEPD(GxEPD2_BW_IS_, x)
  104. #define IS_GxEPD2_3C(x) IS_GxEPD(GxEPD2_3C_IS_, x)
  105. #define IS_GxEPD2_7C(x) IS_GxEPD(GxEPD2_7C_IS_, x)
  106. #define IS_GxEPD2_1248(x) IS_GxEPD(GxEPD2_1248_IS_, x)
  107. #if defined(ESP32)
  108. #define MAX_DISPLAY_BUFFER_SIZE 65536ul // e.g.
  109. #if IS_GxEPD2_BW(GxEPD2_DISPLAY_CLASS)
  110. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  111. #elif IS_GxEPD2_3C(GxEPD2_DISPLAY_CLASS)
  112. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  113. #elif IS_GxEPD2_7C(GxEPD2_DISPLAY_CLASS)
  114. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
  115. #endif
  116. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=*/ 15, /*DC=*/ 27, /*RST=*/ 26, /*BUSY=*/ 25));
  117. #endif
  118. // alternately you can copy the constructor from GxEPD2_display_selection.h of GxEPD_Example to here
  119. // and adapt it to the ESP32 Driver wiring, e.g.
  120. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=*/ 15, /*DC=*/ 27, /*RST=*/ 26, /*BUSY=*/ 25)); // GDEH0154D67
  121. // comment out unused bitmaps to reduce code space used
  122. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  123. #include "bitmaps/Bitmaps104x212.h" // 2.13" b/w flexible GDEW0213I5F
  124. #include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  125. #include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  126. #include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  127. #include "bitmaps/Bitmaps400x300.h" // 4.2" b/w
  128. #include "bitmaps/Bitmaps640x384.h" // 7.5" b/w
  129. // 3-color
  130. #include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  131. #include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  132. #include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  133. #include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  134. #include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r
  135. #if defined(ESP32) && defined(USE_HSPI_FOR_EPD)
  136. SPIClass hspi(HSPI);
  137. #endif
  138. void setup()
  139. {
  140. Serial.begin(115200);
  141. Serial.println();
  142. Serial.println("setup");
  143. // *** special handling for Waveshare ESP32 Driver board *** //
  144. // ********************************************************* //
  145. #if defined(ESP32) && defined(USE_HSPI_FOR_EPD)
  146. hspi.begin(13, 12, 14, 15); // remap hspi for EPD (swap pins)
  147. display.epd2.selectSPI(hspi, SPISettings(4000000, MSBFIRST, SPI_MODE0));
  148. #endif
  149. // *** end of special handling for Waveshare ESP32 Driver board *** //
  150. // **************************************************************** //
  151. display.init(115200);
  152. // first update should be full refresh
  153. helloWorld();
  154. delay(1000);
  155. // partial refresh mode can be used to full screen,
  156. // effective if display panel hasFastPartialUpdate
  157. helloFullScreenPartialMode();
  158. delay(1000);
  159. helloArduino();
  160. delay(1000);
  161. helloEpaper();
  162. delay(1000);
  163. showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
  164. delay(1000);
  165. drawBitmaps();
  166. if (display.epd2.hasPartialUpdate)
  167. {
  168. showPartialUpdate();
  169. delay(1000);
  170. } // else // on GDEW0154Z04 only full update available, doesn't look nice
  171. //drawCornerTest();
  172. //showBox(16, 16, 48, 32, false);
  173. //showBox(16, 56, 48, 32, true);
  174. display.powerOff();
  175. deepSleepTest();
  176. Serial.println("setup done");
  177. }
  178. void loop()
  179. {
  180. }
  181. // note for partial update window and setPartialWindow() method:
  182. // partial update window size and position is on byte boundary in physical x direction
  183. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  184. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  185. const char HelloWorld[] = "Hello World!";
  186. const char HelloArduino[] = "Hello Arduino!";
  187. const char HelloEpaper[] = "Hello E-Paper!";
  188. void helloWorld()
  189. {
  190. //Serial.println("helloWorld");
  191. display.setRotation(1);
  192. display.setFont(&FreeMonoBold9pt7b);
  193. display.setTextColor(GxEPD_BLACK);
  194. int16_t tbx, tby; uint16_t tbw, tbh;
  195. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  196. // center bounding box by transposition of origin:
  197. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  198. uint16_t y = ((display.height() - tbh) / 2) - tby;
  199. display.setFullWindow();
  200. display.firstPage();
  201. do
  202. {
  203. display.fillScreen(GxEPD_WHITE);
  204. display.setCursor(x, y);
  205. display.print(HelloWorld);
  206. }
  207. while (display.nextPage());
  208. //Serial.println("helloWorld done");
  209. }
  210. void helloWorldForDummies()
  211. {
  212. //Serial.println("helloWorld");
  213. const char text[] = "Hello World!";
  214. // most e-papers have width < height (portrait) as native orientation, especially the small ones
  215. // in GxEPD2 rotation 0 is used for native orientation (most TFT libraries use 0 fix for portrait orientation)
  216. // set rotation to 1 (rotate right 90 degrees) to have enough space on small displays (landscape)
  217. display.setRotation(1);
  218. // select a suitable font in Adafruit_GFX
  219. display.setFont(&FreeMonoBold9pt7b);
  220. // on e-papers black on white is more pleasant to read
  221. display.setTextColor(GxEPD_BLACK);
  222. // Adafruit_GFX has a handy method getTextBounds() to determine the boundary box for a text for the actual font
  223. int16_t tbx, tby; uint16_t tbw, tbh; // boundary box window
  224. display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh); // it works for origin 0, 0, fortunately (negative tby!)
  225. // center bounding box by transposition of origin:
  226. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  227. uint16_t y = ((display.height() - tbh) / 2) - tby;
  228. // full window mode is the initial mode, set it anyway
  229. display.setFullWindow();
  230. // here we use paged drawing, even if the processor has enough RAM for full buffer
  231. // so this can be used with any supported processor board.
  232. // the cost in code overhead and execution time penalty is marginal
  233. // tell the graphics class to use paged drawing mode
  234. display.firstPage();
  235. do
  236. {
  237. // this part of code is executed multiple times, as many as needed,
  238. // in case of full buffer it is executed once
  239. // IMPORTANT: each iteration needs to draw the same, to avoid strange effects
  240. // use a copy of values that might change, don't read e.g. from analog or pins in the loop!
  241. display.fillScreen(GxEPD_WHITE); // set the background to white (fill the buffer with value for white)
  242. display.setCursor(x, y); // set the postition to start printing text
  243. display.print(text); // print some text
  244. // end of part executed multiple times
  245. }
  246. // tell the graphics class to transfer the buffer content (page) to the controller buffer
  247. // the graphics class will command the controller to refresh to the screen when the last page has been transferred
  248. // returns true if more pages need be drawn and transferred
  249. // returns false if the last page has been transferred and the screen refreshed for panels without fast partial update
  250. // returns false for panels with fast partial update when the controller buffer has been written once more, to make the differential buffers equal
  251. // (for full buffered with fast partial update the (full) buffer is just transferred again, and false returned)
  252. while (display.nextPage());
  253. //Serial.println("helloWorld done");
  254. }
  255. void helloFullScreenPartialMode()
  256. {
  257. //Serial.println("helloFullScreenPartialMode");
  258. const char fullscreen[] = "full screen update";
  259. const char fpm[] = "fast partial mode";
  260. const char spm[] = "slow partial mode";
  261. const char npm[] = "no partial mode";
  262. display.setPartialWindow(0, 0, display.width(), display.height());
  263. display.setRotation(1);
  264. display.setFont(&FreeMonoBold9pt7b);
  265. display.setTextColor(GxEPD_BLACK);
  266. const char* updatemode;
  267. if (display.epd2.hasFastPartialUpdate)
  268. {
  269. updatemode = fpm;
  270. }
  271. else if (display.epd2.hasPartialUpdate)
  272. {
  273. updatemode = spm;
  274. }
  275. else
  276. {
  277. updatemode = npm;
  278. }
  279. // do this outside of the loop
  280. int16_t tbx, tby; uint16_t tbw, tbh;
  281. // center update text
  282. display.getTextBounds(fullscreen, 0, 0, &tbx, &tby, &tbw, &tbh);
  283. uint16_t utx = ((display.width() - tbw) / 2) - tbx;
  284. uint16_t uty = ((display.height() / 4) - tbh / 2) - tby;
  285. // center update mode
  286. display.getTextBounds(updatemode, 0, 0, &tbx, &tby, &tbw, &tbh);
  287. uint16_t umx = ((display.width() - tbw) / 2) - tbx;
  288. uint16_t umy = ((display.height() * 3 / 4) - tbh / 2) - tby;
  289. // center HelloWorld
  290. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  291. uint16_t hwx = ((display.width() - tbw) / 2) - tbx;
  292. uint16_t hwy = ((display.height() - tbh) / 2) - tby;
  293. display.firstPage();
  294. do
  295. {
  296. display.fillScreen(GxEPD_WHITE);
  297. display.setCursor(hwx, hwy);
  298. display.print(HelloWorld);
  299. display.setCursor(utx, uty);
  300. display.print(fullscreen);
  301. display.setCursor(umx, umy);
  302. display.print(updatemode);
  303. }
  304. while (display.nextPage());
  305. //Serial.println("helloFullScreenPartialMode done");
  306. }
  307. void helloArduino()
  308. {
  309. //Serial.println("helloArduino");
  310. display.setRotation(1);
  311. display.setFont(&FreeMonoBold9pt7b);
  312. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  313. int16_t tbx, tby; uint16_t tbw, tbh;
  314. // align with centered HelloWorld
  315. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  316. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  317. // height might be different
  318. display.getTextBounds(HelloArduino, 0, 0, &tbx, &tby, &tbw, &tbh);
  319. uint16_t y = ((display.height() / 4) - tbh / 2) - tby; // y is base line!
  320. // make the window big enough to cover (overwrite) descenders of previous text
  321. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  322. uint16_t wy = (display.height() / 4) - wh / 2;
  323. display.setPartialWindow(0, wy, display.width(), wh);
  324. display.firstPage();
  325. do
  326. {
  327. display.fillScreen(GxEPD_WHITE);
  328. //display.drawRect(x, y - tbh, tbw, tbh, GxEPD_BLACK);
  329. display.setCursor(x, y);
  330. display.print(HelloArduino);
  331. }
  332. while (display.nextPage());
  333. delay(1000);
  334. //Serial.println("helloArduino done");
  335. }
  336. void helloEpaper()
  337. {
  338. //Serial.println("helloEpaper");
  339. display.setRotation(1);
  340. display.setFont(&FreeMonoBold9pt7b);
  341. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  342. int16_t tbx, tby; uint16_t tbw, tbh;
  343. // align with centered HelloWorld
  344. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  345. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  346. // height might be different
  347. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  348. uint16_t y = (display.height() * 3 / 4) + tbh / 2; // y is base line!
  349. // make the window big enough to cover (overwrite) descenders of previous text
  350. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  351. uint16_t wy = (display.height() * 3 / 4) - wh / 2;
  352. display.setPartialWindow(0, wy, display.width(), wh);
  353. display.firstPage();
  354. do
  355. {
  356. display.fillScreen(GxEPD_WHITE);
  357. display.setCursor(x, y);
  358. display.print(HelloEpaper);
  359. }
  360. while (display.nextPage());
  361. //Serial.println("helloEpaper done");
  362. }
  363. void deepSleepTest()
  364. {
  365. //Serial.println("deepSleepTest");
  366. const char hibernating[] = "hibernating ...";
  367. const char wokeup[] = "woke up";
  368. const char from[] = "from deep sleep";
  369. const char again[] = "again";
  370. display.setRotation(1);
  371. display.setFont(&FreeMonoBold9pt7b);
  372. display.setTextColor(GxEPD_BLACK);
  373. int16_t tbx, tby; uint16_t tbw, tbh;
  374. // center text
  375. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  376. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  377. uint16_t y = ((display.height() - tbh) / 2) - tby;
  378. display.setFullWindow();
  379. display.firstPage();
  380. do
  381. {
  382. display.fillScreen(GxEPD_WHITE);
  383. display.setCursor(x, y);
  384. display.print(hibernating);
  385. }
  386. while (display.nextPage());
  387. display.hibernate();
  388. delay(5000);
  389. display.getTextBounds(wokeup, 0, 0, &tbx, &tby, &tbw, &tbh);
  390. uint16_t wx = (display.width() - tbw) / 2;
  391. uint16_t wy = (display.height() / 3) + tbh / 2; // y is base line!
  392. display.getTextBounds(from, 0, 0, &tbx, &tby, &tbw, &tbh);
  393. uint16_t fx = (display.width() - tbw) / 2;
  394. uint16_t fy = (display.height() * 2 / 3) + tbh / 2; // y is base line!
  395. display.firstPage();
  396. do
  397. {
  398. display.fillScreen(GxEPD_WHITE);
  399. display.setCursor(wx, wy);
  400. display.print(wokeup);
  401. display.setCursor(fx, fy);
  402. display.print(from);
  403. }
  404. while (display.nextPage());
  405. delay(5000);
  406. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  407. uint16_t hx = (display.width() - tbw) / 2;
  408. uint16_t hy = (display.height() / 3) + tbh / 2; // y is base line!
  409. display.getTextBounds(again, 0, 0, &tbx, &tby, &tbw, &tbh);
  410. uint16_t ax = (display.width() - tbw) / 2;
  411. uint16_t ay = (display.height() * 2 / 3) + tbh / 2; // y is base line!
  412. display.firstPage();
  413. do
  414. {
  415. display.fillScreen(GxEPD_WHITE);
  416. display.setCursor(hx, hy);
  417. display.print(hibernating);
  418. display.setCursor(ax, ay);
  419. display.print(again);
  420. }
  421. while (display.nextPage());
  422. display.hibernate();
  423. //Serial.println("deepSleepTest done");
  424. }
  425. void showBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial)
  426. {
  427. //Serial.println("showBox");
  428. display.setRotation(1);
  429. if (partial)
  430. {
  431. display.setPartialWindow(x, y, w, h);
  432. }
  433. else
  434. {
  435. display.setFullWindow();
  436. }
  437. display.firstPage();
  438. do
  439. {
  440. display.fillScreen(GxEPD_WHITE);
  441. display.fillRect(x, y, w, h, GxEPD_BLACK);
  442. }
  443. while (display.nextPage());
  444. //Serial.println("showBox done");
  445. }
  446. void drawCornerTest()
  447. {
  448. display.setFullWindow();
  449. display.setFont(&FreeMonoBold9pt7b);
  450. display.setTextColor(GxEPD_BLACK);
  451. for (uint16_t r = 0; r <= 4; r++)
  452. {
  453. display.setRotation(r);
  454. display.firstPage();
  455. do
  456. {
  457. display.fillScreen(GxEPD_WHITE);
  458. display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
  459. display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
  460. display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
  461. display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
  462. display.setCursor(display.width() / 2, display.height() / 2);
  463. display.print(display.getRotation());
  464. }
  465. while (display.nextPage());
  466. delay(2000);
  467. }
  468. }
  469. void showFont(const char name[], const GFXfont* f)
  470. {
  471. display.setFullWindow();
  472. display.setRotation(0);
  473. display.setTextColor(GxEPD_BLACK);
  474. display.firstPage();
  475. do
  476. {
  477. drawFont(name, f);
  478. }
  479. while (display.nextPage());
  480. }
  481. void drawFont(const char name[], const GFXfont* f)
  482. {
  483. //display.setRotation(0);
  484. display.fillScreen(GxEPD_WHITE);
  485. display.setTextColor(GxEPD_BLACK);
  486. display.setFont(f);
  487. display.setCursor(0, 0);
  488. display.println();
  489. display.println(name);
  490. display.println(" !\"#$%&'()*+,-./");
  491. display.println("0123456789:;<=>?");
  492. display.println("@ABCDEFGHIJKLMNO");
  493. display.println("PQRSTUVWXYZ[\\]^_");
  494. if (display.epd2.hasColor)
  495. {
  496. display.setTextColor(GxEPD_RED);
  497. }
  498. display.println("`abcdefghijklmno");
  499. display.println("pqrstuvwxyz{|}~ ");
  500. }
  501. // note for partial update window and setPartialWindow() method:
  502. // partial update window size and position is on byte boundary in physical x direction
  503. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  504. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  505. // showPartialUpdate() purposely uses values that are not multiples of 8 to test this
  506. void showPartialUpdate()
  507. {
  508. // some useful background
  509. helloWorld();
  510. // use asymmetric values for test
  511. uint16_t box_x = 10;
  512. uint16_t box_y = 15;
  513. uint16_t box_w = 70;
  514. uint16_t box_h = 20;
  515. uint16_t cursor_y = box_y + box_h - 6;
  516. float value = 13.95;
  517. uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
  518. display.setFont(&FreeMonoBold9pt7b);
  519. display.setTextColor(GxEPD_BLACK);
  520. // show where the update box is
  521. for (uint16_t r = 0; r < 4; r++)
  522. {
  523. display.setRotation(r);
  524. display.setPartialWindow(box_x, box_y, box_w, box_h);
  525. display.firstPage();
  526. do
  527. {
  528. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_BLACK);
  529. //display.fillScreen(GxEPD_BLACK);
  530. }
  531. while (display.nextPage());
  532. delay(2000);
  533. display.firstPage();
  534. do
  535. {
  536. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  537. }
  538. while (display.nextPage());
  539. delay(1000);
  540. }
  541. //return;
  542. // show updates in the update box
  543. for (uint16_t r = 0; r < 4; r++)
  544. {
  545. display.setRotation(r);
  546. display.setPartialWindow(box_x, box_y, box_w, box_h);
  547. for (uint16_t i = 1; i <= 10; i += incr)
  548. {
  549. display.firstPage();
  550. do
  551. {
  552. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  553. display.setCursor(box_x, cursor_y);
  554. display.print(value * i, 2);
  555. }
  556. while (display.nextPage());
  557. delay(500);
  558. }
  559. delay(1000);
  560. display.firstPage();
  561. do
  562. {
  563. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  564. }
  565. while (display.nextPage());
  566. delay(1000);
  567. }
  568. }
  569. void drawBitmaps()
  570. {
  571. display.setFullWindow();
  572. #ifdef _GxBitmaps104x212_H_
  573. drawBitmaps104x212();
  574. #endif
  575. #ifdef _GxBitmaps128x250_H_
  576. drawBitmaps128x250();
  577. #endif
  578. #ifdef _GxBitmaps128x296_H_
  579. drawBitmaps128x296();
  580. #endif
  581. #ifdef _GxBitmaps176x264_H_
  582. drawBitmaps176x264();
  583. #endif
  584. #ifdef _GxBitmaps400x300_H_
  585. drawBitmaps400x300();
  586. #endif
  587. #ifdef _GxBitmaps640x384_H_
  588. drawBitmaps640x384();
  589. #endif
  590. #ifdef _WS_Bitmaps800x600_H_
  591. drawBitmaps800x600();
  592. #endif
  593. // 3-color
  594. #ifdef _GxBitmaps3c104x212_H_
  595. drawBitmaps3c104x212();
  596. #endif
  597. #ifdef _GxBitmaps3c128x296_H_
  598. drawBitmaps3c128x296();
  599. #endif
  600. #ifdef _GxBitmaps3c176x264_H_
  601. drawBitmaps3c176x264();
  602. #endif
  603. #ifdef _GxBitmaps3c400x300_H_
  604. drawBitmaps3c400x300();
  605. #endif
  606. // show these after the specific bitmaps
  607. #ifdef _GxBitmaps200x200_H_
  608. drawBitmaps200x200();
  609. #endif
  610. // 3-color
  611. #ifdef _GxBitmaps3c200x200_H_
  612. drawBitmaps3c200x200();
  613. #endif
  614. }
  615. #ifdef _GxBitmaps200x200_H_
  616. void drawBitmaps200x200()
  617. {
  618. #if defined(__AVR)
  619. const unsigned char* bitmaps[] =
  620. {
  621. logo200x200, first200x200 //, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  622. };
  623. #elif defined(_BOARD_GENERIC_STM32F103C_H_)
  624. const unsigned char* bitmaps[] =
  625. {
  626. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200 //, sixth200x200, senventh200x200, eighth200x200
  627. };
  628. #else
  629. const unsigned char* bitmaps[] =
  630. {
  631. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  632. };
  633. #endif
  634. if ((display.epd2.panel == GxEPD2::GDEP015OC1) || (display.epd2.panel == GxEPD2::GDEH0154D67))
  635. {
  636. bool m = display.mirror(true);
  637. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  638. {
  639. display.firstPage();
  640. do
  641. {
  642. display.fillScreen(GxEPD_WHITE);
  643. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  644. }
  645. while (display.nextPage());
  646. delay(2000);
  647. }
  648. display.mirror(m);
  649. }
  650. //else
  651. {
  652. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  653. display.clearScreen(); // use default for white
  654. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  655. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  656. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  657. {
  658. display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  659. delay(2000);
  660. }
  661. }
  662. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  663. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  664. {
  665. int16_t x = -60;
  666. int16_t y = -60;
  667. for (uint16_t j = 0; j < 10; j++)
  668. {
  669. display.writeScreenBuffer(); // use default for white
  670. display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  671. display.refresh(true);
  672. if (display.epd2.hasFastPartialUpdate)
  673. {
  674. // for differential update: set previous buffer equal to current buffer in controller
  675. display.epd2.writeScreenBufferAgain(); // use default for white
  676. display.epd2.writeImageAgain(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  677. }
  678. delay(2000);
  679. x += 40;
  680. y += 40;
  681. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  682. }
  683. if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
  684. break; // comment out for full show
  685. }
  686. display.writeScreenBuffer(); // use default for white
  687. display.writeImage(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  688. display.writeImage(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  689. display.refresh(true);
  690. delay(2000);
  691. }
  692. #endif
  693. #ifdef _GxBitmaps104x212_H_
  694. void drawBitmaps104x212()
  695. {
  696. #if !defined(__AVR)
  697. const unsigned char* bitmaps[] =
  698. {
  699. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  700. };
  701. #else
  702. const unsigned char* bitmaps[] =
  703. {
  704. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  705. };
  706. #endif
  707. if (display.epd2.panel == GxEPD2::GDEW0213I5F)
  708. {
  709. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  710. {
  711. display.firstPage();
  712. do
  713. {
  714. display.fillScreen(GxEPD_WHITE);
  715. display.drawBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  716. }
  717. while (display.nextPage());
  718. delay(2000);
  719. }
  720. }
  721. }
  722. #endif
  723. #ifdef _GxBitmaps128x250_H_
  724. void drawBitmaps128x250()
  725. {
  726. #if !defined(__AVR)
  727. const unsigned char* bitmaps[] =
  728. {
  729. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  730. };
  731. #else
  732. const unsigned char* bitmaps[] =
  733. {
  734. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  735. };
  736. #endif
  737. if ((display.epd2.panel == GxEPD2::GDE0213B1) || (display.epd2.panel == GxEPD2::GDEH0213B72))
  738. {
  739. bool m = display.mirror(true);
  740. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  741. {
  742. display.firstPage();
  743. do
  744. {
  745. display.fillScreen(GxEPD_WHITE);
  746. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  747. }
  748. while (display.nextPage());
  749. delay(2000);
  750. }
  751. display.mirror(m);
  752. }
  753. }
  754. #endif
  755. #ifdef _GxBitmaps128x296_H_
  756. void drawBitmaps128x296()
  757. {
  758. #if !defined(__AVR)
  759. const unsigned char* bitmaps[] =
  760. {
  761. Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
  762. };
  763. #else
  764. const unsigned char* bitmaps[] =
  765. {
  766. Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
  767. };
  768. #endif
  769. if (display.epd2.panel == GxEPD2::GDEH029A1)
  770. {
  771. bool m = display.mirror(true);
  772. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  773. {
  774. display.firstPage();
  775. do
  776. {
  777. display.fillScreen(GxEPD_WHITE);
  778. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  779. }
  780. while (display.nextPage());
  781. delay(2000);
  782. }
  783. display.mirror(m);
  784. }
  785. }
  786. #endif
  787. #ifdef _GxBitmaps176x264_H_
  788. void drawBitmaps176x264()
  789. {
  790. #if !defined(__AVR)
  791. const unsigned char* bitmaps[] =
  792. {
  793. Bitmap176x264_1, Bitmap176x264_2, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  794. };
  795. #else
  796. const unsigned char* bitmaps[] =
  797. {
  798. Bitmap176x264_1, Bitmap176x264_2 //, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  799. };
  800. #endif
  801. if (display.epd2.panel == GxEPD2::GDEW027W3)
  802. {
  803. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  804. {
  805. display.firstPage();
  806. do
  807. {
  808. display.fillScreen(GxEPD_WHITE);
  809. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  810. }
  811. while (display.nextPage());
  812. delay(2000);
  813. }
  814. }
  815. }
  816. #endif
  817. #ifdef _GxBitmaps400x300_H_
  818. void drawBitmaps400x300()
  819. {
  820. #if !defined(__AVR)
  821. const unsigned char* bitmaps[] =
  822. {
  823. Bitmap400x300_1, Bitmap400x300_2
  824. };
  825. #else
  826. const unsigned char* bitmaps[] = {}; // not enough code space
  827. #endif
  828. if (display.epd2.panel == GxEPD2::GDEW042T2)
  829. {
  830. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  831. {
  832. display.firstPage();
  833. do
  834. {
  835. display.fillScreen(GxEPD_WHITE);
  836. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  837. }
  838. while (display.nextPage());
  839. delay(2000);
  840. }
  841. }
  842. }
  843. #endif
  844. #ifdef _GxBitmaps640x384_H_
  845. void drawBitmaps640x384()
  846. {
  847. #if !defined(__AVR)
  848. const unsigned char* bitmaps[] =
  849. {
  850. Bitmap640x384_1, Bitmap640x384_2
  851. };
  852. #else
  853. const unsigned char* bitmaps[] = {}; // not enough code space
  854. #endif
  855. if ((display.epd2.panel == GxEPD2::GDEW075T8) || (display.epd2.panel == GxEPD2::GDEW075Z09))
  856. {
  857. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  858. {
  859. display.firstPage();
  860. do
  861. {
  862. display.fillScreen(GxEPD_WHITE);
  863. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  864. }
  865. while (display.nextPage());
  866. delay(2000);
  867. }
  868. }
  869. }
  870. #endif
  871. #ifdef _WS_Bitmaps800x600_H_
  872. void drawBitmaps800x600()
  873. {
  874. #if defined(ESP8266) || defined(ESP32)
  875. if (display.epd2.panel == GxEPD2::ED060SCT)
  876. {
  877. // Serial.print("sizeof(WS_zoo_800x600) is "); Serial.println(sizeof(WS_zoo_800x600));
  878. display.drawNative(WS_zoo_800x600, 0, 0, 0, 800, 600, false, false, true);
  879. delay(2000);
  880. // Serial.print("sizeof(WS_pic_1200x825) is "); Serial.println(sizeof(WS_pic_1200x825));
  881. // display.drawNative((const uint8_t*)WS_pic_1200x825, 0, 0, 0, 1200, 825, false, false, true);
  882. // delay(2000);
  883. // Serial.print("sizeof(WS_acaa_1024x731) is "); Serial.println(sizeof(WS_acaa_1024x731));
  884. // display.drawNative(WS_acaa_1024x731, 0, 0, 0, 1024, 731, false, false, true);
  885. // delay(2000);
  886. }
  887. #endif
  888. }
  889. #endif
  890. struct bitmap_pair
  891. {
  892. const unsigned char* black;
  893. const unsigned char* red;
  894. };
  895. #ifdef _GxBitmaps3c200x200_H_
  896. void drawBitmaps3c200x200()
  897. {
  898. bitmap_pair bitmap_pairs[] =
  899. {
  900. //{Bitmap3c200x200_black, Bitmap3c200x200_red},
  901. {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
  902. };
  903. if (display.epd2.panel == GxEPD2::GDEW0154Z04)
  904. {
  905. display.firstPage();
  906. do
  907. {
  908. display.fillScreen(GxEPD_WHITE);
  909. // Bitmap3c200x200_black has 2 bits per pixel
  910. // taken from Adafruit_GFX.cpp, modified
  911. int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
  912. uint8_t byte = 0;
  913. for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
  914. {
  915. for (int16_t i = 0; i < display.epd2.WIDTH; i++)
  916. {
  917. if (i & 3) byte <<= 2;
  918. else
  919. {
  920. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  921. byte = pgm_read_byte(&Bitmap3c200x200_black[j * byteWidth * 2 + i / 4]);
  922. #else
  923. byte = Bitmap3c200x200_black[j * byteWidth * 2 + i / 4];
  924. #endif
  925. }
  926. if (!(byte & 0x80))
  927. {
  928. display.drawPixel(i, j, GxEPD_BLACK);
  929. }
  930. }
  931. }
  932. display.drawInvertedBitmap(0, 0, Bitmap3c200x200_red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  933. }
  934. while (display.nextPage());
  935. delay(2000);
  936. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  937. {
  938. display.firstPage();
  939. do
  940. {
  941. display.fillScreen(GxEPD_WHITE);
  942. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  943. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  944. }
  945. while (display.nextPage());
  946. delay(2000);
  947. }
  948. }
  949. if (display.epd2.hasColor)
  950. {
  951. display.clearScreen(); // use default for white
  952. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  953. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  954. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  955. {
  956. display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  957. delay(2000);
  958. }
  959. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  960. {
  961. int16_t x = -60;
  962. int16_t y = -60;
  963. for (uint16_t j = 0; j < 10; j++)
  964. {
  965. display.writeScreenBuffer(); // use default for white
  966. display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  967. display.refresh();
  968. delay(1000);
  969. x += 40;
  970. y += 40;
  971. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  972. }
  973. }
  974. display.writeScreenBuffer(); // use default for white
  975. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
  976. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, int16_t(display.epd2.WIDTH) - 200, int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, false, true);
  977. display.refresh();
  978. delay(2000);
  979. }
  980. }
  981. #endif
  982. #ifdef _GxBitmaps3c104x212_H_
  983. void drawBitmaps3c104x212()
  984. {
  985. #if !defined(__AVR)
  986. bitmap_pair bitmap_pairs[] =
  987. {
  988. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  989. {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  990. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  991. };
  992. #else
  993. bitmap_pair bitmap_pairs[] =
  994. {
  995. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  996. //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  997. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  998. };
  999. #endif
  1000. if (display.epd2.panel == GxEPD2::GDEW0213Z16)
  1001. {
  1002. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1003. {
  1004. display.firstPage();
  1005. do
  1006. {
  1007. display.fillScreen(GxEPD_WHITE);
  1008. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1009. if (bitmap_pairs[i].red == WS_Bitmap3c104x212_red)
  1010. {
  1011. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1012. }
  1013. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1014. }
  1015. while (display.nextPage());
  1016. delay(2000);
  1017. }
  1018. }
  1019. }
  1020. #endif
  1021. #ifdef _GxBitmaps3c128x296_H_
  1022. void drawBitmaps3c128x296()
  1023. {
  1024. #if !defined(__AVR)
  1025. bitmap_pair bitmap_pairs[] =
  1026. {
  1027. {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1028. {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1029. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1030. };
  1031. #else
  1032. bitmap_pair bitmap_pairs[] =
  1033. {
  1034. //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1035. //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1036. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1037. };
  1038. #endif
  1039. if (display.epd2.panel == GxEPD2::GDEW029Z10)
  1040. {
  1041. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1042. {
  1043. display.firstPage();
  1044. do
  1045. {
  1046. display.fillScreen(GxEPD_WHITE);
  1047. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1048. if (bitmap_pairs[i].red == WS_Bitmap3c128x296_red)
  1049. {
  1050. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1051. }
  1052. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1053. }
  1054. while (display.nextPage());
  1055. delay(2000);
  1056. }
  1057. }
  1058. }
  1059. #endif
  1060. #ifdef _GxBitmaps3c176x264_H_
  1061. void drawBitmaps3c176x264()
  1062. {
  1063. bitmap_pair bitmap_pairs[] =
  1064. {
  1065. {Bitmap3c176x264_black, Bitmap3c176x264_red}
  1066. };
  1067. if (display.epd2.panel == GxEPD2::GDEW027C44)
  1068. {
  1069. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1070. {
  1071. display.firstPage();
  1072. do
  1073. {
  1074. display.fillScreen(GxEPD_WHITE);
  1075. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1076. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1077. }
  1078. while (display.nextPage());
  1079. delay(2000);
  1080. }
  1081. }
  1082. }
  1083. #endif
  1084. #ifdef _GxBitmaps3c400x300_H_
  1085. void drawBitmaps3c400x300()
  1086. {
  1087. #if !defined(__AVR)
  1088. bitmap_pair bitmap_pairs[] =
  1089. {
  1090. {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
  1091. {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
  1092. {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
  1093. };
  1094. #else
  1095. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1096. #endif
  1097. if (display.epd2.panel == GxEPD2::GDEW042Z15)
  1098. {
  1099. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1100. {
  1101. display.firstPage();
  1102. do
  1103. {
  1104. display.fillScreen(GxEPD_WHITE);
  1105. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1106. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1107. }
  1108. while (display.nextPage());
  1109. delay(2000);
  1110. }
  1111. }
  1112. }
  1113. #endif