GxEPD2_Example.ino 48 KB

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