GxEPD2_Example.ino 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  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. //logo200x200, first200x200, second200x200, fourth200x200, third200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200 // ED037TC1 test
  795. };
  796. #endif
  797. if ((display.epd2.WIDTH == 200) && (display.epd2.HEIGHT == 200) && !display.epd2.hasColor)
  798. {
  799. bool m = display.mirror(true);
  800. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  801. {
  802. display.firstPage();
  803. do
  804. {
  805. display.fillScreen(GxEPD_WHITE);
  806. display.drawInvertedBitmap(0, 0, bitmaps[i], 200, 200, GxEPD_BLACK);
  807. }
  808. while (display.nextPage());
  809. delay(2000);
  810. }
  811. display.mirror(m);
  812. }
  813. //else
  814. {
  815. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  816. display.clearScreen(); // use default for white
  817. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  818. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  819. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  820. {
  821. display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  822. delay(2000);
  823. }
  824. }
  825. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  826. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  827. {
  828. int16_t x = -60;
  829. int16_t y = -60;
  830. for (uint16_t j = 0; j < 10; j++)
  831. {
  832. display.writeScreenBuffer(); // use default for white
  833. display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  834. display.refresh(true);
  835. if (display.epd2.hasFastPartialUpdate)
  836. {
  837. // for differential update: set previous buffer equal to current buffer in controller
  838. display.epd2.writeScreenBufferAgain(); // use default for white
  839. display.epd2.writeImageAgain(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  840. }
  841. delay(2000);
  842. x += display.epd2.WIDTH / 4;
  843. y += display.epd2.HEIGHT / 4;
  844. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  845. }
  846. if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
  847. break; // comment out for full show
  848. }
  849. display.writeScreenBuffer(); // use default for white
  850. display.writeImage(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  851. display.writeImage(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  852. display.refresh(true);
  853. // for differential update: set previous buffer equal to current buffer in controller
  854. display.epd2.writeScreenBufferAgain(); // use default for white
  855. display.epd2.writeImageAgain(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  856. 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);
  857. delay(2000);
  858. }
  859. #endif
  860. #ifdef _GxBitmaps104x212_H_
  861. void drawBitmaps104x212()
  862. {
  863. #if !defined(__AVR)
  864. const unsigned char* bitmaps[] =
  865. {
  866. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  867. };
  868. #else
  869. const unsigned char* bitmaps[] =
  870. {
  871. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  872. };
  873. #endif
  874. if ((display.epd2.WIDTH == 104) && (display.epd2.HEIGHT == 212) && !display.epd2.hasColor)
  875. {
  876. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  877. {
  878. display.firstPage();
  879. do
  880. {
  881. display.fillScreen(GxEPD_WHITE);
  882. display.drawBitmap(0, 0, bitmaps[i], 104, 212, GxEPD_BLACK);
  883. }
  884. while (display.nextPage());
  885. delay(2000);
  886. }
  887. }
  888. }
  889. #endif
  890. #ifdef _GxBitmaps128x250_H_
  891. void drawBitmaps128x250()
  892. {
  893. #if !defined(__AVR)
  894. const unsigned char* bitmaps[] =
  895. {
  896. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  897. };
  898. #else
  899. const unsigned char* bitmaps[] =
  900. {
  901. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  902. };
  903. #endif
  904. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 250) && !display.epd2.hasColor)
  905. {
  906. bool m = display.mirror(true);
  907. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  908. {
  909. display.firstPage();
  910. do
  911. {
  912. display.fillScreen(GxEPD_WHITE);
  913. display.drawInvertedBitmap(0, 0, bitmaps[i], 128, 250, GxEPD_BLACK);
  914. }
  915. while (display.nextPage());
  916. delay(2000);
  917. }
  918. display.mirror(m);
  919. }
  920. }
  921. #endif
  922. #ifdef _GxBitmaps128x296_H_
  923. void drawBitmaps128x296()
  924. {
  925. #if !defined(__AVR)
  926. const unsigned char* bitmaps[] =
  927. {
  928. Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
  929. };
  930. #else
  931. const unsigned char* bitmaps[] =
  932. {
  933. Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
  934. };
  935. #endif
  936. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 296) && !display.epd2.hasColor)
  937. {
  938. bool m = display.mirror(true);
  939. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  940. {
  941. display.firstPage();
  942. do
  943. {
  944. display.fillScreen(GxEPD_WHITE);
  945. display.drawInvertedBitmap(0, 0, bitmaps[i], 128, 296, GxEPD_BLACK);
  946. }
  947. while (display.nextPage());
  948. delay(2000);
  949. }
  950. display.mirror(m);
  951. }
  952. }
  953. #endif
  954. #ifdef _GxBitmaps152x296_H_
  955. void drawBitmaps152x296()
  956. {
  957. #if !defined(__AVR)
  958. const unsigned char* bitmaps[] =
  959. {
  960. Bitmap152x296_1, Bitmap152x296_2, Bitmap152x296_3
  961. };
  962. #else
  963. const unsigned char* bitmaps[] =
  964. {
  965. Bitmap152x296_1, Bitmap152x296_2, Bitmap152x296_3
  966. };
  967. #endif
  968. if ((display.epd2.WIDTH == 152) && (display.epd2.HEIGHT == 296) && !display.epd2.hasColor)
  969. {
  970. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  971. {
  972. display.firstPage();
  973. do
  974. {
  975. display.fillScreen(GxEPD_WHITE);
  976. display.drawInvertedBitmap(0, 0, bitmaps[i], 152, 296, GxEPD_BLACK);
  977. }
  978. while (display.nextPage());
  979. delay(2000);
  980. }
  981. }
  982. }
  983. #endif
  984. #ifdef _GxBitmaps176x264_H_
  985. void drawBitmaps176x264()
  986. {
  987. #if !defined(__AVR)
  988. const unsigned char* bitmaps[] =
  989. {
  990. Bitmap176x264_1, Bitmap176x264_2, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  991. };
  992. #else
  993. const unsigned char* bitmaps[] =
  994. {
  995. Bitmap176x264_1, Bitmap176x264_2 //, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  996. };
  997. #endif
  998. if ((display.epd2.WIDTH == 176) && (display.epd2.HEIGHT == 264) && !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], 176, 264, GxEPD_BLACK);
  1007. }
  1008. while (display.nextPage());
  1009. delay(2000);
  1010. }
  1011. }
  1012. }
  1013. #endif
  1014. #ifdef _GxBitmaps240x416_H_
  1015. void drawBitmaps240x416()
  1016. {
  1017. #if !defined(__AVR)
  1018. const unsigned char* bitmaps[] =
  1019. {
  1020. Bitmap240x416_1, Bitmap240x416_2, Bitmap240x416_3
  1021. };
  1022. #else
  1023. const unsigned char* bitmaps[] =
  1024. {
  1025. Bitmap240x460_1, Bitmap240x460_2, Bitmap240x460_3
  1026. };
  1027. #endif
  1028. if ((display.epd2.WIDTH == 240) && (display.epd2.HEIGHT == 416) && !display.epd2.hasColor)
  1029. {
  1030. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1031. {
  1032. display.firstPage();
  1033. do
  1034. {
  1035. display.fillScreen(GxEPD_WHITE);
  1036. display.drawInvertedBitmap(0, 0, bitmaps[i], 240, 416, GxEPD_BLACK);
  1037. }
  1038. while (display.nextPage());
  1039. delay(2000);
  1040. }
  1041. }
  1042. }
  1043. #endif
  1044. #ifdef _GxBitmaps400x300_H_
  1045. void drawBitmaps400x300()
  1046. {
  1047. #if !defined(__AVR)
  1048. const unsigned char* bitmaps[] =
  1049. {
  1050. Bitmap400x300_1, Bitmap400x300_2
  1051. };
  1052. #else
  1053. const unsigned char* bitmaps[] = {}; // not enough code space
  1054. #endif
  1055. if ((display.epd2.WIDTH == 400) && (display.epd2.HEIGHT == 300) && !display.epd2.hasColor)
  1056. {
  1057. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1058. {
  1059. display.firstPage();
  1060. do
  1061. {
  1062. display.fillScreen(GxEPD_WHITE);
  1063. display.drawInvertedBitmap(0, 0, bitmaps[i], 400, 300, GxEPD_BLACK);
  1064. }
  1065. while (display.nextPage());
  1066. delay(2000);
  1067. }
  1068. }
  1069. }
  1070. #endif
  1071. #ifdef _GxBitmaps640x384_H_
  1072. void drawBitmaps640x384()
  1073. {
  1074. #if !defined(__AVR)
  1075. const unsigned char* bitmaps[] =
  1076. {
  1077. Bitmap640x384_1, Bitmap640x384_2
  1078. };
  1079. #else
  1080. const unsigned char* bitmaps[] = {}; // not enough code space
  1081. #endif
  1082. if ((display.epd2.WIDTH == 640) && (display.epd2.HEIGHT == 384))
  1083. {
  1084. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1085. {
  1086. display.firstPage();
  1087. do
  1088. {
  1089. display.fillScreen(GxEPD_WHITE);
  1090. display.drawInvertedBitmap(0, 0, bitmaps[i], 640, 384, GxEPD_BLACK);
  1091. }
  1092. while (display.nextPage());
  1093. delay(2000);
  1094. }
  1095. }
  1096. }
  1097. #endif
  1098. #ifdef _GxBitmaps648x480_H_
  1099. void drawBitmaps648x480()
  1100. {
  1101. #if !defined(__AVR)
  1102. const unsigned char* bitmaps[] =
  1103. {
  1104. Bitmap648x480_1, Bitmap648x480_2, Bitmap648x480_3
  1105. };
  1106. #else
  1107. const unsigned char* bitmaps[] = {}; // not enough code space
  1108. #endif
  1109. if ((display.epd2.WIDTH == 648) && (display.epd2.HEIGHT == 480) && !display.epd2.hasColor)
  1110. {
  1111. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1112. {
  1113. display.firstPage();
  1114. do
  1115. {
  1116. display.fillScreen(GxEPD_WHITE);
  1117. display.drawBitmap(0, 0, bitmaps[i], 648, 480, GxEPD_BLACK);
  1118. }
  1119. while (display.nextPage());
  1120. delay(2000);
  1121. }
  1122. }
  1123. }
  1124. #endif
  1125. #ifdef _GxBitmaps800x480_H_
  1126. void drawBitmaps800x480()
  1127. {
  1128. #if !defined(__AVR)
  1129. const unsigned char* bitmaps[] =
  1130. {
  1131. Bitmap800x480_1, Bitmap800x480_2, Bitmap800x480_3, Bitmap800x480_4
  1132. };
  1133. #else
  1134. const unsigned char* bitmaps[] = {}; // not enough code space
  1135. #endif
  1136. if ((display.epd2.WIDTH == 800) && (display.epd2.HEIGHT == 480))
  1137. {
  1138. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1139. {
  1140. display.firstPage();
  1141. do
  1142. {
  1143. display.fillScreen(GxEPD_WHITE);
  1144. display.drawBitmap(0, 0, bitmaps[i], 800, 480, GxEPD_BLACK);
  1145. }
  1146. while (display.nextPage());
  1147. delay(2000);
  1148. }
  1149. if (display.epd2.panel == GxEPD2::GDEW075T7)
  1150. {
  1151. // avoid ghosting caused by OTP waveform
  1152. display.clearScreen();
  1153. display.refresh(false); // full update
  1154. }
  1155. }
  1156. }
  1157. #endif
  1158. #ifdef _WS_Bitmaps800x600_H_
  1159. void drawBitmaps800x600()
  1160. {
  1161. #if defined(ESP8266) || defined(ESP32)
  1162. if ((display.epd2.panel == GxEPD2::ED060SCT) || (display.epd2.panel == GxEPD2::ED060KC1) || (display.epd2.panel == GxEPD2::ED078KC2))
  1163. {
  1164. // Serial.print("sizeof(WS_zoo_800x600) is "); Serial.println(sizeof(WS_zoo_800x600));
  1165. display.drawNative(WS_zoo_800x600, 0, 0, 0, 800, 600, false, false, true);
  1166. delay(2000);
  1167. // Serial.print("sizeof(WS_pic_1200x825) is "); Serial.println(sizeof(WS_pic_1200x825));
  1168. // display.drawNative((const uint8_t*)WS_pic_1200x825, 0, 0, 0, 1200, 825, false, false, true);
  1169. // delay(2000);
  1170. // Serial.print("sizeof(WS_acaa_1024x731) is "); Serial.println(sizeof(WS_acaa_1024x731));
  1171. // display.drawNative(WS_acaa_1024x731, 0, 0, 0, 1024, 731, false, false, true);
  1172. // delay(2000);
  1173. }
  1174. #endif
  1175. }
  1176. #endif
  1177. #if defined(ESP32) && defined(_GxBitmaps1304x984_H_)
  1178. void drawBitmaps1304x984()
  1179. {
  1180. if (display.epd2.panel == GxEPD2::GDEW1248T3)
  1181. {
  1182. display.drawImage(Bitmap1304x984, 0, 0, display.epd2.WIDTH, display.epd2.HEIGHT, false, false, true);
  1183. }
  1184. }
  1185. #endif
  1186. struct bitmap_pair
  1187. {
  1188. const unsigned char* black;
  1189. const unsigned char* red;
  1190. };
  1191. #ifdef _GxBitmaps3c200x200_H_
  1192. void drawBitmaps3c200x200()
  1193. {
  1194. bitmap_pair bitmap_pairs[] =
  1195. {
  1196. //{Bitmap3c200x200_black, Bitmap3c200x200_red},
  1197. {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
  1198. };
  1199. if (display.epd2.panel == GxEPD2::GDEW0154Z04)
  1200. {
  1201. display.firstPage();
  1202. do
  1203. {
  1204. display.fillScreen(GxEPD_WHITE);
  1205. // Bitmap3c200x200_black has 2 bits per pixel
  1206. // taken from Adafruit_GFX.cpp, modified
  1207. int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
  1208. uint8_t byte = 0;
  1209. for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
  1210. {
  1211. for (int16_t i = 0; i < display.epd2.WIDTH; i++)
  1212. {
  1213. if (i & 3) byte <<= 2;
  1214. else
  1215. {
  1216. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  1217. byte = pgm_read_byte(&Bitmap3c200x200_black[j * byteWidth * 2 + i / 4]);
  1218. #else
  1219. byte = Bitmap3c200x200_black[j * byteWidth * 2 + i / 4];
  1220. #endif
  1221. }
  1222. if (!(byte & 0x80))
  1223. {
  1224. display.drawPixel(i, j, GxEPD_BLACK);
  1225. }
  1226. }
  1227. }
  1228. display.drawInvertedBitmap(0, 0, Bitmap3c200x200_red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1229. }
  1230. while (display.nextPage());
  1231. delay(2000);
  1232. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1233. {
  1234. display.firstPage();
  1235. do
  1236. {
  1237. display.fillScreen(GxEPD_WHITE);
  1238. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1239. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1240. }
  1241. while (display.nextPage());
  1242. delay(2000);
  1243. }
  1244. }
  1245. if (display.epd2.hasColor)
  1246. {
  1247. display.clearScreen(); // use default for white
  1248. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  1249. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  1250. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1251. {
  1252. display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  1253. delay(2000);
  1254. }
  1255. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1256. {
  1257. int16_t x = -60;
  1258. int16_t y = -60;
  1259. for (uint16_t j = 0; j < 10; j++)
  1260. {
  1261. display.writeScreenBuffer(); // use default for white
  1262. display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  1263. display.refresh();
  1264. delay(1000);
  1265. x += display.epd2.WIDTH / 4;
  1266. y += display.epd2.HEIGHT / 4;
  1267. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  1268. }
  1269. }
  1270. display.writeScreenBuffer(); // use default for white
  1271. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
  1272. 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);
  1273. display.refresh();
  1274. delay(2000);
  1275. }
  1276. }
  1277. #endif
  1278. #ifdef _GxBitmaps3c104x212_H_
  1279. void drawBitmaps3c104x212()
  1280. {
  1281. #if !defined(__AVR)
  1282. bitmap_pair bitmap_pairs[] =
  1283. {
  1284. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  1285. {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  1286. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  1287. };
  1288. #else
  1289. bitmap_pair bitmap_pairs[] =
  1290. {
  1291. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  1292. //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  1293. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  1294. };
  1295. #endif
  1296. if (display.epd2.panel == GxEPD2::GDEW0213Z16)
  1297. {
  1298. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1299. {
  1300. display.firstPage();
  1301. do
  1302. {
  1303. display.fillScreen(GxEPD_WHITE);
  1304. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1305. if (bitmap_pairs[i].red == WS_Bitmap3c104x212_red)
  1306. {
  1307. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1308. }
  1309. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1310. }
  1311. while (display.nextPage());
  1312. delay(2000);
  1313. }
  1314. }
  1315. }
  1316. #endif
  1317. #ifdef _GxBitmaps3c128x296_H_
  1318. void drawBitmaps3c128x296()
  1319. {
  1320. #if !defined(__AVR)
  1321. bitmap_pair bitmap_pairs[] =
  1322. {
  1323. {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1324. {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1325. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1326. };
  1327. #else
  1328. bitmap_pair bitmap_pairs[] =
  1329. {
  1330. //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1331. //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1332. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1333. };
  1334. #endif
  1335. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 296) && display.epd2.hasColor)
  1336. {
  1337. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1338. {
  1339. display.firstPage();
  1340. do
  1341. {
  1342. display.fillScreen(GxEPD_WHITE);
  1343. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, 128, 296, GxEPD_BLACK);
  1344. if (bitmap_pairs[i].red == WS_Bitmap3c128x296_red)
  1345. {
  1346. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, 128, 296, GxEPD_RED);
  1347. }
  1348. else display.drawBitmap(0, 0, bitmap_pairs[i].red, 128, 296, GxEPD_RED);
  1349. }
  1350. while (display.nextPage());
  1351. delay(2000);
  1352. }
  1353. }
  1354. }
  1355. #endif
  1356. #ifdef _GxBitmaps3c176x264_H_
  1357. void drawBitmaps3c176x264()
  1358. {
  1359. bitmap_pair bitmap_pairs[] =
  1360. {
  1361. {Bitmap3c176x264_black, Bitmap3c176x264_red}
  1362. };
  1363. if (display.epd2.panel == GxEPD2::GDEW027C44)
  1364. {
  1365. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1366. {
  1367. display.firstPage();
  1368. do
  1369. {
  1370. display.fillScreen(GxEPD_WHITE);
  1371. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1372. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1373. }
  1374. while (display.nextPage());
  1375. delay(2000);
  1376. }
  1377. }
  1378. }
  1379. #endif
  1380. #ifdef _GxBitmaps3c400x300_H_
  1381. void drawBitmaps3c400x300()
  1382. {
  1383. #if !defined(__AVR)
  1384. bitmap_pair bitmap_pairs[] =
  1385. {
  1386. {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
  1387. {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
  1388. {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
  1389. };
  1390. #else
  1391. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1392. #endif
  1393. if (display.epd2.panel == GxEPD2::GDEW042Z15)
  1394. {
  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, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1402. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1403. }
  1404. while (display.nextPage());
  1405. delay(2000);
  1406. }
  1407. }
  1408. }
  1409. #endif
  1410. #ifdef _GxBitmaps3c800x480_H_
  1411. void drawBitmaps3c800x480()
  1412. {
  1413. #if !defined(__AVR)
  1414. bitmap_pair bitmap_pairs[] =
  1415. {
  1416. {Bitmap3c800x480_1_black, Bitmap3c800x480_1_red}
  1417. };
  1418. #else
  1419. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1420. #endif
  1421. if (display.epd2.panel == GxEPD2::GDEW075Z08)
  1422. {
  1423. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1424. {
  1425. display.firstPage();
  1426. do
  1427. {
  1428. display.fillScreen(GxEPD_WHITE);
  1429. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1430. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1431. }
  1432. while (display.nextPage());
  1433. delay(2000);
  1434. }
  1435. }
  1436. }
  1437. #endif
  1438. #ifdef _GxBitmaps3c880x528_H_
  1439. void drawBitmaps3c880x528()
  1440. {
  1441. #if !defined(__AVR)
  1442. bitmap_pair bitmap_pairs[] =
  1443. {
  1444. {Bitmap3c880x528_black, Bitmap3c880x528_red}
  1445. };
  1446. #else
  1447. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1448. #endif
  1449. if (display.epd2.panel == GxEPD2::GDEH075Z90)
  1450. {
  1451. bool m = display.mirror(true);
  1452. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1453. {
  1454. display.firstPage();
  1455. do
  1456. {
  1457. display.fillScreen(GxEPD_WHITE);
  1458. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, 880, 528, GxEPD_BLACK);
  1459. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, 880, 528, GxEPD_RED);
  1460. }
  1461. while (display.nextPage());
  1462. delay(2000);
  1463. }
  1464. display.mirror(m);
  1465. }
  1466. }
  1467. #endif
  1468. #if defined(_WS_Bitmaps7c192x143_H_)
  1469. void drawBitmaps7c192x143()
  1470. {
  1471. if (display.epd2.panel == GxEPD2::ACeP565)
  1472. {
  1473. display.drawNative(WS_Bitmap7c192x143, 0, (display.epd2.WIDTH - 192) / 2, (display.epd2.HEIGHT - 143) / 2, 192, 143, false, false, true);
  1474. delay(5000);
  1475. }
  1476. }
  1477. #endif
  1478. void draw7colors()
  1479. {
  1480. display.setRotation(0);
  1481. uint16_t h = display.height() / 7;
  1482. display.firstPage();
  1483. do
  1484. {
  1485. display.fillRect(0, 0, display.width(), h, GxEPD_BLACK);
  1486. display.fillRect(0, h, display.width(), h, GxEPD_WHITE);
  1487. display.fillRect(0, 2 * h, display.width(), h, GxEPD_GREEN);
  1488. display.fillRect(0, 3 * h, display.width(), h, GxEPD_BLUE);
  1489. display.fillRect(0, 4 * h, display.width(), h, GxEPD_RED);
  1490. display.fillRect(0, 5 * h, display.width(), h, GxEPD_YELLOW);
  1491. display.fillRect(0, 6 * h, display.width(), h, GxEPD_ORANGE);
  1492. }
  1493. while (display.nextPage());
  1494. }
  1495. void draw7colorlines()
  1496. {
  1497. display.setRotation(0);
  1498. uint16_t h = 2;
  1499. display.firstPage();
  1500. do
  1501. {
  1502. uint16_t y = 0;
  1503. do
  1504. {
  1505. display.fillRect(0, y, display.width(), h, GxEPD_BLACK); y += h;
  1506. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1507. display.fillRect(0, y, display.width(), h, GxEPD_GREEN); y += h;
  1508. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1509. display.fillRect(0, y, display.width(), h, GxEPD_BLUE); y += h;
  1510. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1511. display.fillRect(0, y, display.width(), h, GxEPD_RED); y += h;
  1512. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1513. display.fillRect(0, y, display.width(), h, GxEPD_YELLOW); y += h;
  1514. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1515. display.fillRect(0, y, display.width(), h, GxEPD_ORANGE); y += h;
  1516. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1517. }
  1518. while ((y + 12 * h) < display.height());
  1519. //display.drawPixel(0, y, GxEPD_BLACK); display.drawPixel(10, y, GxEPD_GREEN);
  1520. //display.drawPixel(20, y, GxEPD_BLUE); display.drawPixel(30, y, GxEPD_RED);
  1521. //display.drawPixel(40, y, GxEPD_YELLOW); display.drawPixel(50, y, GxEPD_ORANGE);
  1522. display.fillRect(0, y, 2, 2, GxEPD_BLACK); display.fillRect(10, y, 2, 2, GxEPD_GREEN);
  1523. display.fillRect(20, y, 2, 2, GxEPD_BLUE); display.fillRect(30, y, 2, 2, GxEPD_RED);
  1524. display.fillRect(40, y, 2, 2, GxEPD_YELLOW); display.fillRect(50, y, 2, 2, GxEPD_ORANGE);
  1525. }
  1526. while (display.nextPage());
  1527. }