GxEPD2_Example.ino 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  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. // Supporting Arduino Forum Topics:
  12. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  13. // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  14. // see GxEPD2_wiring_examples.h for wiring suggestions and examples
  15. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  16. // enable or disable GxEPD2_GFX base class
  17. #define ENABLE_GxEPD2_GFX 0
  18. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  19. //#include <GFX.h>
  20. // Note: if you use this with ENABLE_GxEPD2_GFX 1:
  21. // uncomment it in GxEPD2_GFX.h too, or add #include <GFX.h> before any #include <GxEPD2_GFX.h>
  22. #include <GxEPD2_BW.h>
  23. #include <GxEPD2_3C.h>
  24. #include <GxEPD2_7C.h>
  25. #include <Fonts/FreeMonoBold9pt7b.h>
  26. // select the display constructor line in one of the following files (old style):
  27. #include "GxEPD2_display_selection.h"
  28. #include "GxEPD2_display_selection_added.h"
  29. //#include "GxEPD2_display_selection_more.h" // private
  30. // or select the display class and display driver class in the following file (new style):
  31. #include "GxEPD2_display_selection_new_style.h"
  32. #if !defined(__AVR) && !defined(_BOARD_GENERIC_STM32F103C_H_)
  33. // note 16.11.2019: the compiler may exclude code based on constant if statements (display.epd2.panel == constant),
  34. // therefore bitmaps may get optimized out by the linker
  35. // comment out unused bitmaps to reduce code space used
  36. #include "bitmaps/Bitmaps152x152.h" // 1.54" b/w
  37. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  38. #include "bitmaps/Bitmaps104x212.h" // 2.13" b/w flexible GDEW0213I5F
  39. #include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  40. #include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  41. #include "bitmaps/Bitmaps152x296.h" // 2.6" b/w
  42. #include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  43. #include "bitmaps/Bitmaps240x416.h" // 3.71" b/w
  44. #include "bitmaps/Bitmaps400x300.h" // 4.2" b/w
  45. #include "bitmaps/Bitmaps648x480.h" // 5.38" b/w
  46. #include "bitmaps/Bitmaps640x384.h" // 7.5" b/w
  47. #include "bitmaps/Bitmaps800x480.h" // 7.5" b/w
  48. // 3-color
  49. #include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  50. #include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  51. #include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  52. #include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  53. #include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r
  54. #if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
  55. #include "bitmaps/Bitmaps3c800x480.h" // 7.5" b/w/r
  56. #include "bitmaps/Bitmaps3c880x528.h" // 7.5" b/w/r
  57. #include "bitmaps/WS_Bitmaps800x600.h" // 6.0" grey
  58. #include "bitmaps/WS_Bitmaps7c192x143.h" // 5.65" 7-color
  59. #endif
  60. #if defined(ESP32)
  61. #include "bitmaps/Bitmaps1304x984.h" // 12.48" b/w
  62. #endif
  63. #else
  64. // select only one to fit in code space
  65. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  66. //#include "bitmaps/Bitmaps104x212.h" // 2.13" b/w flexible GDEW0213I5F
  67. //#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  68. //#include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  69. //#include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  70. ////#include "bitmaps/Bitmaps400x300.h" // 4.2" b/w // not enough code space
  71. ////#include "bitmaps/Bitmaps640x384.h" // 7.5" b/w // not enough code space
  72. // 3-color
  73. //#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  74. //#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  75. //#include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  76. //#include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  77. ////#include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r // not enough code space
  78. #endif
  79. void setup()
  80. {
  81. Serial.begin(115200);
  82. Serial.println();
  83. Serial.println("setup");
  84. delay(100);
  85. display.init(115200);
  86. // first update should be full refresh
  87. helloWorld();
  88. delay(1000);
  89. // partial refresh mode can be used to full screen,
  90. // effective if display panel hasFastPartialUpdate
  91. helloFullScreenPartialMode();
  92. delay(1000);
  93. //stripeTest(); return; // GDEH029Z13 issue
  94. helloArduino();
  95. delay(1000);
  96. helloEpaper();
  97. delay(1000);
  98. //helloValue(123.9, 1);
  99. //delay(1000);
  100. showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
  101. delay(1000);
  102. drawBitmaps();
  103. #if !defined(__AVR) // takes too long!
  104. if (display.epd2.panel == GxEPD2::ACeP565)
  105. {
  106. //draw7colorlines();
  107. //delay(2000);
  108. draw7colors();
  109. delay(4000);
  110. }
  111. #endif
  112. if (display.epd2.hasPartialUpdate)
  113. {
  114. showPartialUpdate();
  115. delay(1000);
  116. } // else // on GDEW0154Z04 only full update available, doesn't look nice
  117. //drawCornerTest();
  118. //showBox(16, 16, 48, 32, false);
  119. //showBox(16, 56, 48, 32, true);
  120. display.powerOff();
  121. deepSleepTest();
  122. #if defined(ESP32) && defined(_GxBitmaps1304x984_H_)
  123. drawBitmaps1304x984();
  124. display.powerOff();
  125. #endif
  126. Serial.println("setup done");
  127. }
  128. void loop()
  129. {
  130. }
  131. // note for partial update window and setPartialWindow() method:
  132. // partial update window size and position is on byte boundary in physical x direction
  133. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  134. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  135. const char HelloWorld[] = "Hello World!";
  136. const char HelloArduino[] = "Hello Arduino!";
  137. const char HelloEpaper[] = "Hello E-Paper!";
  138. void helloWorld()
  139. {
  140. //Serial.println("helloWorld");
  141. display.setRotation(1);
  142. display.setFont(&FreeMonoBold9pt7b);
  143. display.setTextColor(GxEPD_BLACK);
  144. int16_t tbx, tby; uint16_t tbw, tbh;
  145. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  146. // center bounding box by transposition of origin:
  147. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  148. uint16_t y = ((display.height() - tbh) / 2) - tby;
  149. display.setFullWindow();
  150. display.firstPage();
  151. do
  152. {
  153. display.fillScreen(GxEPD_WHITE);
  154. display.setCursor(x, y);
  155. display.print(HelloWorld);
  156. }
  157. while (display.nextPage());
  158. //Serial.println("helloWorld done");
  159. }
  160. void helloWorldForDummies()
  161. {
  162. //Serial.println("helloWorld");
  163. const char text[] = "Hello World!";
  164. // most e-papers have width < height (portrait) as native orientation, especially the small ones
  165. // in GxEPD2 rotation 0 is used for native orientation (most TFT libraries use 0 fix for portrait orientation)
  166. // set rotation to 1 (rotate right 90 degrees) to have enough space on small displays (landscape)
  167. display.setRotation(1);
  168. // select a suitable font in Adafruit_GFX
  169. display.setFont(&FreeMonoBold9pt7b);
  170. // on e-papers black on white is more pleasant to read
  171. display.setTextColor(GxEPD_BLACK);
  172. // Adafruit_GFX has a handy method getTextBounds() to determine the boundary box for a text for the actual font
  173. int16_t tbx, tby; uint16_t tbw, tbh; // boundary box window
  174. display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh); // it works for origin 0, 0, fortunately (negative tby!)
  175. // center bounding box by transposition of origin:
  176. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  177. uint16_t y = ((display.height() - tbh) / 2) - tby;
  178. // full window mode is the initial mode, set it anyway
  179. display.setFullWindow();
  180. // here we use paged drawing, even if the processor has enough RAM for full buffer
  181. // so this can be used with any supported processor board.
  182. // the cost in code overhead and execution time penalty is marginal
  183. // tell the graphics class to use paged drawing mode
  184. display.firstPage();
  185. do
  186. {
  187. // this part of code is executed multiple times, as many as needed,
  188. // in case of full buffer it is executed once
  189. // IMPORTANT: each iteration needs to draw the same, to avoid strange effects
  190. // use a copy of values that might change, don't read e.g. from analog or pins in the loop!
  191. display.fillScreen(GxEPD_WHITE); // set the background to white (fill the buffer with value for white)
  192. display.setCursor(x, y); // set the postition to start printing text
  193. display.print(text); // print some text
  194. // end of part executed multiple times
  195. }
  196. // tell the graphics class to transfer the buffer content (page) to the controller buffer
  197. // the graphics class will command the controller to refresh to the screen when the last page has been transferred
  198. // returns true if more pages need be drawn and transferred
  199. // returns false if the last page has been transferred and the screen refreshed for panels without fast partial update
  200. // returns false for panels with fast partial update when the controller buffer has been written once more, to make the differential buffers equal
  201. // (for full buffered with fast partial update the (full) buffer is just transferred again, and false returned)
  202. while (display.nextPage());
  203. //Serial.println("helloWorld done");
  204. }
  205. void helloFullScreenPartialMode()
  206. {
  207. //Serial.println("helloFullScreenPartialMode");
  208. const char fullscreen[] = "full screen update";
  209. const char fpm[] = "fast partial mode";
  210. const char spm[] = "slow partial mode";
  211. const char npm[] = "no partial mode";
  212. display.setPartialWindow(0, 0, display.width(), display.height());
  213. display.setRotation(1);
  214. display.setFont(&FreeMonoBold9pt7b);
  215. display.setTextColor(GxEPD_BLACK);
  216. const char* updatemode;
  217. if (display.epd2.hasFastPartialUpdate)
  218. {
  219. updatemode = fpm;
  220. }
  221. else if (display.epd2.hasPartialUpdate)
  222. {
  223. updatemode = spm;
  224. }
  225. else
  226. {
  227. updatemode = npm;
  228. }
  229. // do this outside of the loop
  230. int16_t tbx, tby; uint16_t tbw, tbh;
  231. // center update text
  232. display.getTextBounds(fullscreen, 0, 0, &tbx, &tby, &tbw, &tbh);
  233. uint16_t utx = ((display.width() - tbw) / 2) - tbx;
  234. uint16_t uty = ((display.height() / 4) - tbh / 2) - tby;
  235. // center update mode
  236. display.getTextBounds(updatemode, 0, 0, &tbx, &tby, &tbw, &tbh);
  237. uint16_t umx = ((display.width() - tbw) / 2) - tbx;
  238. uint16_t umy = ((display.height() * 3 / 4) - tbh / 2) - tby;
  239. // center HelloWorld
  240. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  241. uint16_t hwx = ((display.width() - tbw) / 2) - tbx;
  242. uint16_t hwy = ((display.height() - tbh) / 2) - tby;
  243. display.firstPage();
  244. do
  245. {
  246. display.fillScreen(GxEPD_WHITE);
  247. display.setCursor(hwx, hwy);
  248. display.print(HelloWorld);
  249. display.setCursor(utx, uty);
  250. display.print(fullscreen);
  251. display.setCursor(umx, umy);
  252. display.print(updatemode);
  253. }
  254. while (display.nextPage());
  255. //Serial.println("helloFullScreenPartialMode done");
  256. }
  257. void helloArduino()
  258. {
  259. //Serial.println("helloArduino");
  260. display.setRotation(1);
  261. display.setFont(&FreeMonoBold9pt7b);
  262. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  263. int16_t tbx, tby; uint16_t tbw, tbh;
  264. // align with centered HelloWorld
  265. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  266. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  267. // height might be different
  268. display.getTextBounds(HelloArduino, 0, 0, &tbx, &tby, &tbw, &tbh);
  269. uint16_t y = ((display.height() / 4) - tbh / 2) - tby; // y is base line!
  270. // make the window big enough to cover (overwrite) descenders of previous text
  271. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  272. uint16_t wy = (display.height() / 4) - wh / 2;
  273. display.setPartialWindow(0, wy, display.width(), wh);
  274. display.firstPage();
  275. do
  276. {
  277. display.fillScreen(GxEPD_WHITE);
  278. //display.drawRect(x, y - tbh, tbw, tbh, GxEPD_BLACK);
  279. display.setCursor(x, y);
  280. display.print(HelloArduino);
  281. }
  282. while (display.nextPage());
  283. delay(1000);
  284. //Serial.println("helloArduino done");
  285. }
  286. void helloEpaper()
  287. {
  288. //Serial.println("helloEpaper");
  289. display.setRotation(1);
  290. display.setFont(&FreeMonoBold9pt7b);
  291. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  292. int16_t tbx, tby; uint16_t tbw, tbh;
  293. // align with centered HelloWorld
  294. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  295. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  296. // height might be different
  297. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  298. uint16_t y = (display.height() * 3 / 4) + tbh / 2; // y is base line!
  299. // make the window big enough to cover (overwrite) descenders of previous text
  300. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  301. uint16_t wy = (display.height() * 3 / 4) - wh / 2;
  302. display.setPartialWindow(0, wy, display.width(), wh);
  303. display.firstPage();
  304. do
  305. {
  306. display.fillScreen(GxEPD_WHITE);
  307. display.setCursor(x, y);
  308. display.print(HelloEpaper);
  309. }
  310. while (display.nextPage());
  311. //Serial.println("helloEpaper done");
  312. }
  313. // test partial window issue on GDEW0213Z19 and GDEH029Z13
  314. void stripeTest()
  315. {
  316. helloStripe(104);
  317. delay(2000);
  318. helloStripe(96);
  319. }
  320. const char HelloStripe[] = "Hello Stripe!";
  321. void helloStripe(uint16_t pw_xe) // end of partial window in physcal x direction
  322. {
  323. //Serial.print("HelloStripe("); Serial.print(pw_xe); Serial.println(")");
  324. display.setRotation(3);
  325. display.setFont(&FreeMonoBold9pt7b);
  326. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  327. int16_t tbx, tby; uint16_t tbw, tbh;
  328. display.getTextBounds(HelloStripe, 0, 0, &tbx, &tby, &tbw, &tbh);
  329. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  330. uint16_t wy = pw_xe - wh;
  331. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  332. uint16_t y = wy - tby;
  333. display.setPartialWindow(0, wy, display.width(), wh);
  334. display.firstPage();
  335. do
  336. {
  337. display.fillScreen(GxEPD_WHITE);
  338. display.setCursor(x, y);
  339. display.print(HelloStripe);
  340. }
  341. while (display.nextPage());
  342. //Serial.println("HelloStripe done");
  343. }
  344. #if defined(ESP8266) || defined(ESP32)
  345. #include <StreamString.h>
  346. #define PrintString StreamString
  347. #else
  348. class PrintString : public Print, public String
  349. {
  350. public:
  351. size_t write(uint8_t data) override
  352. {
  353. return concat(char(data));
  354. };
  355. };
  356. #endif
  357. void helloValue(double v, int digits)
  358. {
  359. //Serial.println("helloValue");
  360. display.setRotation(1);
  361. display.setFont(&FreeMonoBold9pt7b);
  362. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  363. PrintString valueString;
  364. valueString.print(v, digits);
  365. int16_t tbx, tby; uint16_t tbw, tbh;
  366. display.getTextBounds(valueString, 0, 0, &tbx, &tby, &tbw, &tbh);
  367. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  368. uint16_t y = (display.height() * 3 / 4) + tbh / 2; // y is base line!
  369. // show what happens, if we use the bounding box for partial window
  370. uint16_t wx = (display.width() - tbw) / 2;
  371. uint16_t wy = (display.height() * 3 / 4) - tbh / 2;
  372. display.setPartialWindow(wx, wy, tbw, tbh);
  373. display.firstPage();
  374. do
  375. {
  376. display.fillScreen(GxEPD_WHITE);
  377. display.setCursor(x, y);
  378. display.print(valueString);
  379. }
  380. while (display.nextPage());
  381. delay(2000);
  382. // make the partial window big enough to cover the previous text
  383. uint16_t ww = tbw; // remember window width
  384. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  385. // adjust, because HelloEpaper was aligned, not centered (could calculate this to be precise)
  386. ww = max(ww, uint16_t(tbw + 12)); // 12 seems ok
  387. wx = (display.width() - tbw) / 2;
  388. // make the window big enough to cover (overwrite) descenders of previous text
  389. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  390. wy = (display.height() * 3 / 4) - wh / 2;
  391. display.setPartialWindow(wx, wy, ww, wh);
  392. // alternately use the whole width for partial window
  393. //display.setPartialWindow(0, wy, display.width(), wh);
  394. display.firstPage();
  395. do
  396. {
  397. display.fillScreen(GxEPD_WHITE);
  398. display.setCursor(x, y);
  399. display.print(valueString);
  400. }
  401. while (display.nextPage());
  402. //Serial.println("helloValue done");
  403. }
  404. void deepSleepTest()
  405. {
  406. //Serial.println("deepSleepTest");
  407. const char hibernating[] = "hibernating ...";
  408. const char wokeup[] = "woke up";
  409. const char from[] = "from deep sleep";
  410. const char again[] = "again";
  411. display.setRotation(1);
  412. display.setFont(&FreeMonoBold9pt7b);
  413. display.setTextColor(GxEPD_BLACK);
  414. int16_t tbx, tby; uint16_t tbw, tbh;
  415. // center text
  416. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  417. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  418. uint16_t y = ((display.height() - tbh) / 2) - tby;
  419. display.setFullWindow();
  420. display.firstPage();
  421. do
  422. {
  423. display.fillScreen(GxEPD_WHITE);
  424. display.setCursor(x, y);
  425. display.print(hibernating);
  426. }
  427. while (display.nextPage());
  428. display.hibernate();
  429. delay(5000);
  430. display.getTextBounds(wokeup, 0, 0, &tbx, &tby, &tbw, &tbh);
  431. uint16_t wx = (display.width() - tbw) / 2;
  432. uint16_t wy = (display.height() / 3) + tbh / 2; // y is base line!
  433. display.getTextBounds(from, 0, 0, &tbx, &tby, &tbw, &tbh);
  434. uint16_t fx = (display.width() - tbw) / 2;
  435. uint16_t fy = (display.height() * 2 / 3) + tbh / 2; // y is base line!
  436. display.firstPage();
  437. do
  438. {
  439. display.fillScreen(GxEPD_WHITE);
  440. display.setCursor(wx, wy);
  441. display.print(wokeup);
  442. display.setCursor(fx, fy);
  443. display.print(from);
  444. }
  445. while (display.nextPage());
  446. delay(5000);
  447. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  448. uint16_t hx = (display.width() - tbw) / 2;
  449. uint16_t hy = (display.height() / 3) + tbh / 2; // y is base line!
  450. display.getTextBounds(again, 0, 0, &tbx, &tby, &tbw, &tbh);
  451. uint16_t ax = (display.width() - tbw) / 2;
  452. uint16_t ay = (display.height() * 2 / 3) + tbh / 2; // y is base line!
  453. display.firstPage();
  454. do
  455. {
  456. display.fillScreen(GxEPD_WHITE);
  457. display.setCursor(hx, hy);
  458. display.print(hibernating);
  459. display.setCursor(ax, ay);
  460. display.print(again);
  461. }
  462. while (display.nextPage());
  463. display.hibernate();
  464. //Serial.println("deepSleepTest done");
  465. }
  466. void showBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial)
  467. {
  468. //Serial.println("showBox");
  469. display.setRotation(1);
  470. if (partial)
  471. {
  472. display.setPartialWindow(x, y, w, h);
  473. }
  474. else
  475. {
  476. display.setFullWindow();
  477. }
  478. display.firstPage();
  479. do
  480. {
  481. display.fillScreen(GxEPD_WHITE);
  482. display.fillRect(x, y, w, h, GxEPD_BLACK);
  483. }
  484. while (display.nextPage());
  485. //Serial.println("showBox done");
  486. }
  487. void drawCornerTest()
  488. {
  489. display.setFullWindow();
  490. display.setFont(&FreeMonoBold9pt7b);
  491. display.setTextColor(GxEPD_BLACK);
  492. for (uint16_t r = 0; r <= 4; r++)
  493. {
  494. display.setRotation(r);
  495. display.firstPage();
  496. do
  497. {
  498. display.fillScreen(GxEPD_WHITE);
  499. display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
  500. display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
  501. display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
  502. display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
  503. display.setCursor(display.width() / 2, display.height() / 2);
  504. display.print(display.getRotation());
  505. }
  506. while (display.nextPage());
  507. delay(2000);
  508. }
  509. }
  510. void showFont(const char name[], const GFXfont* f)
  511. {
  512. display.setFullWindow();
  513. display.setRotation(0);
  514. display.setTextColor(GxEPD_BLACK);
  515. display.firstPage();
  516. do
  517. {
  518. drawFont(name, f);
  519. }
  520. while (display.nextPage());
  521. }
  522. void drawFont(const char name[], const GFXfont* f)
  523. {
  524. //display.setRotation(0);
  525. display.fillScreen(GxEPD_WHITE);
  526. display.setTextColor(GxEPD_BLACK);
  527. display.setFont(f);
  528. display.setCursor(0, 0);
  529. display.println();
  530. display.println(name);
  531. display.println(" !\"#$%&'()*+,-./");
  532. display.println("0123456789:;<=>?");
  533. display.println("@ABCDEFGHIJKLMNO");
  534. display.println("PQRSTUVWXYZ[\\]^_");
  535. if (display.epd2.hasColor)
  536. {
  537. display.setTextColor(GxEPD_RED);
  538. }
  539. display.println("`abcdefghijklmno");
  540. display.println("pqrstuvwxyz{|}~ ");
  541. }
  542. // note for partial update window and setPartialWindow() method:
  543. // partial update window size and position is on byte boundary in physical x direction
  544. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  545. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  546. // showPartialUpdate() purposely uses values that are not multiples of 8 to test this
  547. void showPartialUpdate()
  548. {
  549. // some useful background
  550. helloWorld();
  551. // use asymmetric values for test
  552. uint16_t box_x = 10;
  553. uint16_t box_y = 15;
  554. uint16_t box_w = 70;
  555. uint16_t box_h = 20;
  556. uint16_t cursor_y = box_y + box_h - 6;
  557. float value = 13.95;
  558. uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
  559. display.setFont(&FreeMonoBold9pt7b);
  560. display.setTextColor(GxEPD_BLACK);
  561. // show where the update box is
  562. for (uint16_t r = 0; r < 4; r++)
  563. {
  564. display.setRotation(r);
  565. display.setPartialWindow(box_x, box_y, box_w, box_h);
  566. display.firstPage();
  567. do
  568. {
  569. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_BLACK);
  570. //display.fillScreen(GxEPD_BLACK);
  571. }
  572. while (display.nextPage());
  573. delay(2000);
  574. display.firstPage();
  575. do
  576. {
  577. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  578. }
  579. while (display.nextPage());
  580. delay(1000);
  581. }
  582. //return;
  583. // show updates in the update box
  584. for (uint16_t r = 0; r < 4; r++)
  585. {
  586. display.setRotation(r);
  587. display.setPartialWindow(box_x, box_y, box_w, box_h);
  588. for (uint16_t i = 1; i <= 10; i += incr)
  589. {
  590. display.firstPage();
  591. do
  592. {
  593. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  594. display.setCursor(box_x, cursor_y);
  595. display.print(value * i, 2);
  596. }
  597. while (display.nextPage());
  598. delay(500);
  599. }
  600. delay(1000);
  601. display.firstPage();
  602. do
  603. {
  604. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  605. }
  606. while (display.nextPage());
  607. delay(1000);
  608. }
  609. }
  610. void drawBitmaps()
  611. {
  612. display.setFullWindow();
  613. #ifdef _GxBitmaps152x152_H_
  614. drawBitmaps152x152();
  615. #endif
  616. #ifdef _GxBitmaps104x212_H_
  617. drawBitmaps104x212();
  618. #endif
  619. #ifdef _GxBitmaps128x250_H_
  620. drawBitmaps128x250();
  621. #endif
  622. #ifdef _GxBitmaps128x296_H_
  623. drawBitmaps128x296();
  624. #endif
  625. #ifdef _GxBitmaps176x264_H_
  626. drawBitmaps176x264();
  627. #endif
  628. #ifdef _GxBitmaps400x300_H_
  629. drawBitmaps400x300();
  630. #endif
  631. #ifdef _GxBitmaps640x384_H_
  632. drawBitmaps640x384();
  633. #endif
  634. #ifdef _GxBitmaps648x480_H_
  635. drawBitmaps648x480();
  636. #endif
  637. #ifdef _GxBitmaps800x480_H_
  638. drawBitmaps800x480();
  639. #endif
  640. #ifdef _WS_Bitmaps800x600_H_
  641. drawBitmaps800x600();
  642. #endif
  643. #if defined(ESP32) && defined(_GxBitmaps1304x984_H_)
  644. drawBitmaps1304x984();
  645. #endif
  646. // 3-color
  647. #ifdef _GxBitmaps3c104x212_H_
  648. drawBitmaps3c104x212();
  649. #endif
  650. #ifdef _GxBitmaps3c128x296_H_
  651. drawBitmaps3c128x296();
  652. #endif
  653. #ifdef _GxBitmaps152x296_H_
  654. drawBitmaps152x296();
  655. #endif
  656. #ifdef _GxBitmaps3c176x264_H_
  657. drawBitmaps3c176x264();
  658. #endif
  659. #ifdef _GxBitmaps240x416_H_
  660. drawBitmaps240x416();
  661. #endif
  662. #ifdef _GxBitmaps3c400x300_H_
  663. drawBitmaps3c400x300();
  664. #endif
  665. #ifdef _GxBitmaps3c800x480_H_
  666. drawBitmaps3c800x480();
  667. #endif
  668. #ifdef _GxBitmaps3c880x528_H_
  669. drawBitmaps3c880x528();
  670. #endif
  671. #if defined(_WS_Bitmaps7c192x143_H_)
  672. drawBitmaps7c192x143();
  673. #endif
  674. if ((display.epd2.WIDTH >= 200) && (display.epd2.HEIGHT >= 200))
  675. {
  676. // show these after the specific bitmaps
  677. #ifdef _GxBitmaps200x200_H_
  678. drawBitmaps200x200();
  679. #endif
  680. // 3-color
  681. #ifdef _GxBitmaps3c200x200_H_
  682. drawBitmaps3c200x200();
  683. #endif
  684. }
  685. }
  686. #ifdef _GxBitmaps152x152_H_
  687. void drawBitmaps152x152()
  688. {
  689. #if !defined(__AVR)
  690. const unsigned char* bitmaps[] =
  691. {
  692. Bitmap152x152_1, Bitmap152x152_2, Bitmap152x152_3
  693. };
  694. #else
  695. const unsigned char* bitmaps[] =
  696. {
  697. Bitmap152x152_1, Bitmap152x152_2, Bitmap152x152_3
  698. };
  699. #endif
  700. if ((display.epd2.WIDTH == 152) && (display.epd2.HEIGHT == 152))
  701. {
  702. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  703. {
  704. display.firstPage();
  705. do
  706. {
  707. display.fillScreen(GxEPD_WHITE);
  708. display.drawInvertedBitmap(0, 0, bitmaps[i], 152, 152, GxEPD_BLACK);
  709. }
  710. while (display.nextPage());
  711. delay(2000);
  712. }
  713. }
  714. }
  715. #endif
  716. #ifdef _GxBitmaps200x200_H_
  717. void drawBitmaps200x200()
  718. {
  719. #if defined(ARDUINO_AVR_PRO)
  720. const unsigned char* bitmaps[] =
  721. {
  722. logo200x200
  723. };
  724. #elif defined(__AVR)
  725. const unsigned char* bitmaps[] =
  726. {
  727. logo200x200, //first200x200
  728. };
  729. #elif defined(_BOARD_GENERIC_STM32F103C_H_) || defined(STM32F1xx)
  730. const unsigned char* bitmaps[] =
  731. {
  732. logo200x200, first200x200, second200x200, third200x200, //fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  733. };
  734. #else
  735. const unsigned char* bitmaps[] =
  736. {
  737. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  738. };
  739. #endif
  740. if ((display.epd2.WIDTH == 200) && (display.epd2.HEIGHT == 200) && !display.epd2.hasColor)
  741. {
  742. bool m = display.mirror(true);
  743. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  744. {
  745. display.firstPage();
  746. do
  747. {
  748. display.fillScreen(GxEPD_WHITE);
  749. display.drawInvertedBitmap(0, 0, bitmaps[i], 200, 200, GxEPD_BLACK);
  750. }
  751. while (display.nextPage());
  752. delay(2000);
  753. }
  754. display.mirror(m);
  755. }
  756. //else
  757. {
  758. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  759. display.clearScreen(); // use default for white
  760. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  761. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  762. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  763. {
  764. display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  765. delay(2000);
  766. }
  767. }
  768. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  769. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  770. {
  771. int16_t x = -60;
  772. int16_t y = -60;
  773. for (uint16_t j = 0; j < 10; j++)
  774. {
  775. display.writeScreenBuffer(); // use default for white
  776. display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  777. display.refresh(true);
  778. if (display.epd2.hasFastPartialUpdate)
  779. {
  780. // for differential update: set previous buffer equal to current buffer in controller
  781. display.epd2.writeScreenBufferAgain(); // use default for white
  782. display.epd2.writeImageAgain(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  783. }
  784. delay(2000);
  785. x += display.epd2.WIDTH / 4;
  786. y += display.epd2.HEIGHT / 4;
  787. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  788. }
  789. if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
  790. break; // comment out for full show
  791. }
  792. display.writeScreenBuffer(); // use default for white
  793. display.writeImage(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  794. display.writeImage(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  795. display.refresh(true);
  796. // for differential update: set previous buffer equal to current buffer in controller
  797. display.epd2.writeScreenBufferAgain(); // use default for white
  798. display.epd2.writeImageAgain(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  799. display.epd2.writeImageAgain(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  800. delay(2000);
  801. }
  802. #endif
  803. #ifdef _GxBitmaps104x212_H_
  804. void drawBitmaps104x212()
  805. {
  806. #if !defined(__AVR)
  807. const unsigned char* bitmaps[] =
  808. {
  809. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  810. };
  811. #else
  812. const unsigned char* bitmaps[] =
  813. {
  814. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  815. };
  816. #endif
  817. if ((display.epd2.WIDTH == 104) && (display.epd2.HEIGHT == 212) && !display.epd2.hasColor)
  818. {
  819. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  820. {
  821. display.firstPage();
  822. do
  823. {
  824. display.fillScreen(GxEPD_WHITE);
  825. display.drawBitmap(0, 0, bitmaps[i], 104, 212, GxEPD_BLACK);
  826. }
  827. while (display.nextPage());
  828. delay(2000);
  829. }
  830. }
  831. }
  832. #endif
  833. #ifdef _GxBitmaps128x250_H_
  834. void drawBitmaps128x250()
  835. {
  836. #if !defined(__AVR)
  837. const unsigned char* bitmaps[] =
  838. {
  839. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  840. };
  841. #else
  842. const unsigned char* bitmaps[] =
  843. {
  844. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  845. };
  846. #endif
  847. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 250) && !display.epd2.hasColor)
  848. {
  849. bool m = display.mirror(true);
  850. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  851. {
  852. display.firstPage();
  853. do
  854. {
  855. display.fillScreen(GxEPD_WHITE);
  856. display.drawInvertedBitmap(0, 0, bitmaps[i], 128, 250, GxEPD_BLACK);
  857. }
  858. while (display.nextPage());
  859. delay(2000);
  860. }
  861. display.mirror(m);
  862. }
  863. }
  864. #endif
  865. #ifdef _GxBitmaps128x296_H_
  866. void drawBitmaps128x296()
  867. {
  868. #if !defined(__AVR)
  869. const unsigned char* bitmaps[] =
  870. {
  871. Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
  872. };
  873. #else
  874. const unsigned char* bitmaps[] =
  875. {
  876. Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
  877. };
  878. #endif
  879. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 296) && !display.epd2.hasColor)
  880. {
  881. bool m = display.mirror(true);
  882. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  883. {
  884. display.firstPage();
  885. do
  886. {
  887. display.fillScreen(GxEPD_WHITE);
  888. display.drawInvertedBitmap(0, 0, bitmaps[i], 128, 296, GxEPD_BLACK);
  889. }
  890. while (display.nextPage());
  891. delay(2000);
  892. }
  893. display.mirror(m);
  894. }
  895. }
  896. #endif
  897. #ifdef _GxBitmaps152x296_H_
  898. void drawBitmaps152x296()
  899. {
  900. #if !defined(__AVR)
  901. const unsigned char* bitmaps[] =
  902. {
  903. Bitmap152x296_1, Bitmap152x296_2, Bitmap152x296_3
  904. };
  905. #else
  906. const unsigned char* bitmaps[] =
  907. {
  908. Bitmap152x296_1, Bitmap152x296_2, Bitmap152x296_3
  909. };
  910. #endif
  911. if ((display.epd2.WIDTH == 152) && (display.epd2.HEIGHT == 296) && !display.epd2.hasColor)
  912. {
  913. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  914. {
  915. display.firstPage();
  916. do
  917. {
  918. display.fillScreen(GxEPD_WHITE);
  919. display.drawInvertedBitmap(0, 0, bitmaps[i], 152, 296, GxEPD_BLACK);
  920. }
  921. while (display.nextPage());
  922. delay(2000);
  923. }
  924. }
  925. }
  926. #endif
  927. #ifdef _GxBitmaps176x264_H_
  928. void drawBitmaps176x264()
  929. {
  930. #if !defined(__AVR)
  931. const unsigned char* bitmaps[] =
  932. {
  933. Bitmap176x264_1, Bitmap176x264_2, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  934. };
  935. #else
  936. const unsigned char* bitmaps[] =
  937. {
  938. Bitmap176x264_1, Bitmap176x264_2 //, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  939. };
  940. #endif
  941. if ((display.epd2.WIDTH == 176) && (display.epd2.HEIGHT == 264) && !display.epd2.hasColor)
  942. {
  943. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  944. {
  945. display.firstPage();
  946. do
  947. {
  948. display.fillScreen(GxEPD_WHITE);
  949. display.drawInvertedBitmap(0, 0, bitmaps[i], 176, 264, GxEPD_BLACK);
  950. }
  951. while (display.nextPage());
  952. delay(2000);
  953. }
  954. }
  955. }
  956. #endif
  957. #ifdef _GxBitmaps240x416_H_
  958. void drawBitmaps240x416()
  959. {
  960. #if !defined(__AVR)
  961. const unsigned char* bitmaps[] =
  962. {
  963. Bitmap240x416_1, Bitmap240x416_2, Bitmap240x416_3
  964. };
  965. #else
  966. const unsigned char* bitmaps[] =
  967. {
  968. Bitmap240x460_1, Bitmap240x460_2, Bitmap240x460_3
  969. };
  970. #endif
  971. if ((display.epd2.WIDTH == 240) && (display.epd2.HEIGHT == 416) && !display.epd2.hasColor)
  972. {
  973. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  974. {
  975. display.firstPage();
  976. do
  977. {
  978. display.fillScreen(GxEPD_WHITE);
  979. display.drawInvertedBitmap(0, 0, bitmaps[i], 240, 416, GxEPD_BLACK);
  980. }
  981. while (display.nextPage());
  982. delay(2000);
  983. }
  984. }
  985. }
  986. #endif
  987. #ifdef _GxBitmaps400x300_H_
  988. void drawBitmaps400x300()
  989. {
  990. #if !defined(__AVR)
  991. const unsigned char* bitmaps[] =
  992. {
  993. Bitmap400x300_1, Bitmap400x300_2
  994. };
  995. #else
  996. const unsigned char* bitmaps[] = {}; // not enough code space
  997. #endif
  998. if ((display.epd2.WIDTH == 400) && (display.epd2.HEIGHT == 300) && !display.epd2.hasColor)
  999. {
  1000. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1001. {
  1002. display.firstPage();
  1003. do
  1004. {
  1005. display.fillScreen(GxEPD_WHITE);
  1006. display.drawInvertedBitmap(0, 0, bitmaps[i], 400, 300, GxEPD_BLACK);
  1007. }
  1008. while (display.nextPage());
  1009. delay(2000);
  1010. }
  1011. }
  1012. }
  1013. #endif
  1014. #ifdef _GxBitmaps640x384_H_
  1015. void drawBitmaps640x384()
  1016. {
  1017. #if !defined(__AVR)
  1018. const unsigned char* bitmaps[] =
  1019. {
  1020. Bitmap640x384_1, Bitmap640x384_2
  1021. };
  1022. #else
  1023. const unsigned char* bitmaps[] = {}; // not enough code space
  1024. #endif
  1025. if ((display.epd2.WIDTH == 640) && (display.epd2.HEIGHT == 384))
  1026. {
  1027. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1028. {
  1029. display.firstPage();
  1030. do
  1031. {
  1032. display.fillScreen(GxEPD_WHITE);
  1033. display.drawInvertedBitmap(0, 0, bitmaps[i], 640, 384, GxEPD_BLACK);
  1034. }
  1035. while (display.nextPage());
  1036. delay(2000);
  1037. }
  1038. }
  1039. }
  1040. #endif
  1041. #ifdef _GxBitmaps648x480_H_
  1042. void drawBitmaps648x480()
  1043. {
  1044. #if !defined(__AVR)
  1045. const unsigned char* bitmaps[] =
  1046. {
  1047. Bitmap648x480_1, Bitmap648x480_2, Bitmap648x480_3
  1048. };
  1049. #else
  1050. const unsigned char* bitmaps[] = {}; // not enough code space
  1051. #endif
  1052. if ((display.epd2.WIDTH == 648) && (display.epd2.HEIGHT == 480) && !display.epd2.hasColor)
  1053. {
  1054. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1055. {
  1056. display.firstPage();
  1057. do
  1058. {
  1059. display.fillScreen(GxEPD_WHITE);
  1060. display.drawBitmap(0, 0, bitmaps[i], 648, 480, GxEPD_BLACK);
  1061. }
  1062. while (display.nextPage());
  1063. delay(2000);
  1064. }
  1065. }
  1066. }
  1067. #endif
  1068. #ifdef _GxBitmaps800x480_H_
  1069. void drawBitmaps800x480()
  1070. {
  1071. #if !defined(__AVR)
  1072. const unsigned char* bitmaps[] =
  1073. {
  1074. Bitmap800x480_1, Bitmap800x480_2, Bitmap800x480_3, Bitmap800x480_4
  1075. };
  1076. #else
  1077. const unsigned char* bitmaps[] = {}; // not enough code space
  1078. #endif
  1079. if ((display.epd2.WIDTH == 800) && (display.epd2.HEIGHT == 480))
  1080. {
  1081. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1082. {
  1083. display.firstPage();
  1084. do
  1085. {
  1086. display.fillScreen(GxEPD_WHITE);
  1087. display.drawBitmap(0, 0, bitmaps[i], 800, 480, GxEPD_BLACK);
  1088. }
  1089. while (display.nextPage());
  1090. delay(2000);
  1091. }
  1092. if (display.epd2.panel == GxEPD2::GDEW075T7)
  1093. {
  1094. // avoid ghosting caused by OTP waveform
  1095. display.clearScreen();
  1096. display.refresh(false); // full update
  1097. }
  1098. }
  1099. }
  1100. #endif
  1101. #ifdef _WS_Bitmaps800x600_H_
  1102. void drawBitmaps800x600()
  1103. {
  1104. #if defined(ESP8266) || defined(ESP32)
  1105. if ((display.epd2.panel == GxEPD2::ED060SCT) || (display.epd2.panel == GxEPD2::ED060KC1) || (display.epd2.panel == GxEPD2::ED078KC2))
  1106. {
  1107. // Serial.print("sizeof(WS_zoo_800x600) is "); Serial.println(sizeof(WS_zoo_800x600));
  1108. display.drawNative(WS_zoo_800x600, 0, 0, 0, 800, 600, false, false, true);
  1109. delay(2000);
  1110. // Serial.print("sizeof(WS_pic_1200x825) is "); Serial.println(sizeof(WS_pic_1200x825));
  1111. // display.drawNative((const uint8_t*)WS_pic_1200x825, 0, 0, 0, 1200, 825, false, false, true);
  1112. // delay(2000);
  1113. // Serial.print("sizeof(WS_acaa_1024x731) is "); Serial.println(sizeof(WS_acaa_1024x731));
  1114. // display.drawNative(WS_acaa_1024x731, 0, 0, 0, 1024, 731, false, false, true);
  1115. // delay(2000);
  1116. }
  1117. #endif
  1118. }
  1119. #endif
  1120. #if defined(ESP32) && defined(_GxBitmaps1304x984_H_)
  1121. void drawBitmaps1304x984()
  1122. {
  1123. if (display.epd2.panel == GxEPD2::GDEW1248T3)
  1124. {
  1125. display.drawImage(Bitmap1304x984, 0, 0, display.epd2.WIDTH, display.epd2.HEIGHT, false, false, true);
  1126. }
  1127. }
  1128. #endif
  1129. struct bitmap_pair
  1130. {
  1131. const unsigned char* black;
  1132. const unsigned char* red;
  1133. };
  1134. #ifdef _GxBitmaps3c200x200_H_
  1135. void drawBitmaps3c200x200()
  1136. {
  1137. bitmap_pair bitmap_pairs[] =
  1138. {
  1139. //{Bitmap3c200x200_black, Bitmap3c200x200_red},
  1140. {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
  1141. };
  1142. if (display.epd2.panel == GxEPD2::GDEW0154Z04)
  1143. {
  1144. display.firstPage();
  1145. do
  1146. {
  1147. display.fillScreen(GxEPD_WHITE);
  1148. // Bitmap3c200x200_black has 2 bits per pixel
  1149. // taken from Adafruit_GFX.cpp, modified
  1150. int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
  1151. uint8_t byte = 0;
  1152. for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
  1153. {
  1154. for (int16_t i = 0; i < display.epd2.WIDTH; i++)
  1155. {
  1156. if (i & 3) byte <<= 2;
  1157. else
  1158. {
  1159. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  1160. byte = pgm_read_byte(&Bitmap3c200x200_black[j * byteWidth * 2 + i / 4]);
  1161. #else
  1162. byte = Bitmap3c200x200_black[j * byteWidth * 2 + i / 4];
  1163. #endif
  1164. }
  1165. if (!(byte & 0x80))
  1166. {
  1167. display.drawPixel(i, j, GxEPD_BLACK);
  1168. }
  1169. }
  1170. }
  1171. display.drawInvertedBitmap(0, 0, Bitmap3c200x200_red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1172. }
  1173. while (display.nextPage());
  1174. delay(2000);
  1175. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1176. {
  1177. display.firstPage();
  1178. do
  1179. {
  1180. display.fillScreen(GxEPD_WHITE);
  1181. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1182. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1183. }
  1184. while (display.nextPage());
  1185. delay(2000);
  1186. }
  1187. }
  1188. if (display.epd2.hasColor)
  1189. {
  1190. display.clearScreen(); // use default for white
  1191. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  1192. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  1193. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1194. {
  1195. display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  1196. delay(2000);
  1197. }
  1198. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1199. {
  1200. int16_t x = -60;
  1201. int16_t y = -60;
  1202. for (uint16_t j = 0; j < 10; j++)
  1203. {
  1204. display.writeScreenBuffer(); // use default for white
  1205. display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  1206. display.refresh();
  1207. delay(1000);
  1208. x += display.epd2.WIDTH / 4;
  1209. y += display.epd2.HEIGHT / 4;
  1210. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  1211. }
  1212. }
  1213. display.writeScreenBuffer(); // use default for white
  1214. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
  1215. 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);
  1216. display.refresh();
  1217. delay(2000);
  1218. }
  1219. }
  1220. #endif
  1221. #ifdef _GxBitmaps3c104x212_H_
  1222. void drawBitmaps3c104x212()
  1223. {
  1224. #if !defined(__AVR)
  1225. bitmap_pair bitmap_pairs[] =
  1226. {
  1227. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  1228. {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  1229. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  1230. };
  1231. #else
  1232. bitmap_pair bitmap_pairs[] =
  1233. {
  1234. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  1235. //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  1236. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  1237. };
  1238. #endif
  1239. if (display.epd2.panel == GxEPD2::GDEW0213Z16)
  1240. {
  1241. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1242. {
  1243. display.firstPage();
  1244. do
  1245. {
  1246. display.fillScreen(GxEPD_WHITE);
  1247. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1248. if (bitmap_pairs[i].red == WS_Bitmap3c104x212_red)
  1249. {
  1250. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1251. }
  1252. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1253. }
  1254. while (display.nextPage());
  1255. delay(2000);
  1256. }
  1257. }
  1258. }
  1259. #endif
  1260. #ifdef _GxBitmaps3c128x296_H_
  1261. void drawBitmaps3c128x296()
  1262. {
  1263. #if !defined(__AVR)
  1264. bitmap_pair bitmap_pairs[] =
  1265. {
  1266. {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1267. {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1268. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1269. };
  1270. #else
  1271. bitmap_pair bitmap_pairs[] =
  1272. {
  1273. //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1274. //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1275. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1276. };
  1277. #endif
  1278. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 296) && display.epd2.hasColor)
  1279. {
  1280. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1281. {
  1282. display.firstPage();
  1283. do
  1284. {
  1285. display.fillScreen(GxEPD_WHITE);
  1286. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, 128, 296, GxEPD_BLACK);
  1287. if (bitmap_pairs[i].red == WS_Bitmap3c128x296_red)
  1288. {
  1289. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, 128, 296, GxEPD_RED);
  1290. }
  1291. else display.drawBitmap(0, 0, bitmap_pairs[i].red, 128, 296, GxEPD_RED);
  1292. }
  1293. while (display.nextPage());
  1294. delay(2000);
  1295. }
  1296. }
  1297. }
  1298. #endif
  1299. #ifdef _GxBitmaps3c176x264_H_
  1300. void drawBitmaps3c176x264()
  1301. {
  1302. bitmap_pair bitmap_pairs[] =
  1303. {
  1304. {Bitmap3c176x264_black, Bitmap3c176x264_red}
  1305. };
  1306. if (display.epd2.panel == GxEPD2::GDEW027C44)
  1307. {
  1308. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1309. {
  1310. display.firstPage();
  1311. do
  1312. {
  1313. display.fillScreen(GxEPD_WHITE);
  1314. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1315. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1316. }
  1317. while (display.nextPage());
  1318. delay(2000);
  1319. }
  1320. }
  1321. }
  1322. #endif
  1323. #ifdef _GxBitmaps3c400x300_H_
  1324. void drawBitmaps3c400x300()
  1325. {
  1326. #if !defined(__AVR)
  1327. bitmap_pair bitmap_pairs[] =
  1328. {
  1329. {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
  1330. {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
  1331. {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
  1332. };
  1333. #else
  1334. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1335. #endif
  1336. if (display.epd2.panel == GxEPD2::GDEW042Z15)
  1337. {
  1338. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1339. {
  1340. display.firstPage();
  1341. do
  1342. {
  1343. display.fillScreen(GxEPD_WHITE);
  1344. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1345. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1346. }
  1347. while (display.nextPage());
  1348. delay(2000);
  1349. }
  1350. }
  1351. }
  1352. #endif
  1353. #ifdef _GxBitmaps3c800x480_H_
  1354. void drawBitmaps3c800x480()
  1355. {
  1356. #if !defined(__AVR)
  1357. bitmap_pair bitmap_pairs[] =
  1358. {
  1359. {Bitmap3c800x480_1_black, Bitmap3c800x480_1_red}
  1360. };
  1361. #else
  1362. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1363. #endif
  1364. if (display.epd2.panel == GxEPD2::GDEW075Z08)
  1365. {
  1366. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1367. {
  1368. display.firstPage();
  1369. do
  1370. {
  1371. display.fillScreen(GxEPD_WHITE);
  1372. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1373. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1374. }
  1375. while (display.nextPage());
  1376. delay(2000);
  1377. }
  1378. }
  1379. }
  1380. #endif
  1381. #ifdef _GxBitmaps3c880x528_H_
  1382. void drawBitmaps3c880x528()
  1383. {
  1384. #if !defined(__AVR)
  1385. bitmap_pair bitmap_pairs[] =
  1386. {
  1387. {Bitmap3c880x528_black, Bitmap3c880x528_red}
  1388. };
  1389. #else
  1390. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1391. #endif
  1392. if (display.epd2.panel == GxEPD2::GDEH075Z90)
  1393. {
  1394. bool m = display.mirror(true);
  1395. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1396. {
  1397. display.firstPage();
  1398. do
  1399. {
  1400. display.fillScreen(GxEPD_WHITE);
  1401. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, 880, 528, GxEPD_BLACK);
  1402. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, 880, 528, GxEPD_RED);
  1403. }
  1404. while (display.nextPage());
  1405. delay(2000);
  1406. }
  1407. display.mirror(m);
  1408. }
  1409. }
  1410. #endif
  1411. #if defined(_WS_Bitmaps7c192x143_H_)
  1412. void drawBitmaps7c192x143()
  1413. {
  1414. if (display.epd2.panel == GxEPD2::ACeP565)
  1415. {
  1416. display.drawNative(WS_Bitmap7c192x143, 0, (display.epd2.WIDTH - 192) / 2, (display.epd2.HEIGHT - 143) / 2, 192, 143, false, false, true);
  1417. delay(5000);
  1418. }
  1419. }
  1420. #endif
  1421. void draw7colors()
  1422. {
  1423. display.setRotation(0);
  1424. uint16_t h = display.height() / 7;
  1425. display.firstPage();
  1426. do
  1427. {
  1428. display.fillRect(0, 0, display.width(), h, GxEPD_BLACK);
  1429. display.fillRect(0, h, display.width(), h, GxEPD_WHITE);
  1430. display.fillRect(0, 2 * h, display.width(), h, GxEPD_GREEN);
  1431. display.fillRect(0, 3 * h, display.width(), h, GxEPD_BLUE);
  1432. display.fillRect(0, 4 * h, display.width(), h, GxEPD_RED);
  1433. display.fillRect(0, 5 * h, display.width(), h, GxEPD_YELLOW);
  1434. display.fillRect(0, 6 * h, display.width(), h, GxEPD_ORANGE);
  1435. }
  1436. while (display.nextPage());
  1437. }
  1438. void draw7colorlines()
  1439. {
  1440. display.setRotation(0);
  1441. uint16_t h = 2;
  1442. display.firstPage();
  1443. do
  1444. {
  1445. uint16_t y = 0;
  1446. do
  1447. {
  1448. display.fillRect(0, y, display.width(), h, GxEPD_BLACK); y += h;
  1449. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1450. display.fillRect(0, y, display.width(), h, GxEPD_GREEN); y += h;
  1451. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1452. display.fillRect(0, y, display.width(), h, GxEPD_BLUE); y += h;
  1453. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1454. display.fillRect(0, y, display.width(), h, GxEPD_RED); y += h;
  1455. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1456. display.fillRect(0, y, display.width(), h, GxEPD_YELLOW); y += h;
  1457. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1458. display.fillRect(0, y, display.width(), h, GxEPD_ORANGE); y += h;
  1459. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1460. }
  1461. while ((y + 12 * h) < display.height());
  1462. //display.drawPixel(0, y, GxEPD_BLACK); display.drawPixel(10, y, GxEPD_GREEN);
  1463. //display.drawPixel(20, y, GxEPD_BLUE); display.drawPixel(30, y, GxEPD_RED);
  1464. //display.drawPixel(40, y, GxEPD_YELLOW); display.drawPixel(50, y, GxEPD_ORANGE);
  1465. display.fillRect(0, y, 2, 2, GxEPD_BLACK); display.fillRect(10, y, 2, 2, GxEPD_GREEN);
  1466. display.fillRect(20, y, 2, 2, GxEPD_BLUE); display.fillRect(30, y, 2, 2, GxEPD_RED);
  1467. display.fillRect(40, y, 2, 2, GxEPD_YELLOW); display.fillRect(50, y, 2, 2, GxEPD_ORANGE);
  1468. }
  1469. while (display.nextPage());
  1470. }