SSD1607LutEdit.ino 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /*
  2. SSD1607LutEdit.ino
  3. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  4. Copyright (c) 2016, olikraus@gmail.com
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice, this list
  9. of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice, this
  11. list of conditions and the following disclaimer in the documentation and/or other
  12. materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  14. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <Arduino.h>
  28. #include <U8g2lib.h>
  29. #ifdef U8X8_HAVE_HW_SPI
  30. #include <SPI.h>
  31. #endif
  32. #ifdef U8X8_HAVE_HW_I2C
  33. #include <Wire.h>
  34. #endif
  35. // display for the LUT editor
  36. U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2_editor(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
  37. // target e-paper device
  38. #define BUSY_PIN 0
  39. U8G2_SSD1607_200X200_1_4W_SW_SPI u8g2_epaper(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display
  40. //U8G2_SSD1607_V2_200X200_1_4W_SW_SPI u8g2_epaper(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display
  41. //#define BUSY_PIN 2
  42. //U8G2_IL3820_296X128_1_4W_SW_SPI u8g2_epaper(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // WaveShare 2.9 inch eInk/ePaper Display, enable 16 bit mode for this display!
  43. //U8G2_IL3820_V2_296X128_1_4W_SW_SPI u8g2_epaper(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // WaveShare 2.9 inch eInk/ePaper Display, enable 16 bit mode for this display!
  44. /*================================================*/
  45. /* lut editor */
  46. uint16_t lut_measured_duration = 0;
  47. #define LUT_ARRAY_LEN 20
  48. #define LUT_WAVE_CNT 4
  49. /*
  50. level
  51. 0: neutral, middle
  52. 1: upper line
  53. 2: lower line
  54. 00 black to black (upper line required)
  55. 01 black to white (lower line required)
  56. 10 white to black
  57. 11 white to white
  58. */
  59. uint8_t lut_level[LUT_WAVE_CNT][LUT_ARRAY_LEN];
  60. uint8_t lut_time[LUT_ARRAY_LEN];
  61. #define LUT_DY 3
  62. u8g2_uint_t cursor_x1, cursor_x2;
  63. uint8_t lut_time_to_width[16] =
  64. {
  65. 2, // 0
  66. 2, // 1
  67. 2, // 2
  68. 2, // 3
  69. 3, // 4
  70. 3, // 5
  71. 3, // 6
  72. 3, // 7
  73. 4, // 8
  74. 4, // 9
  75. 4, // 10
  76. 4, // 11
  77. 5, // 12
  78. 5, // 13
  79. 5, // 14
  80. 5, // 15
  81. };
  82. u8g2_uint_t get_dx(uint8_t i)
  83. {
  84. //return 5;
  85. return lut_time_to_width[lut_time[i]];
  86. }
  87. void read_lut(const uint8_t *lut)
  88. {
  89. uint8_t i;
  90. for ( i = 0; i < LUT_ARRAY_LEN; i++ )
  91. {
  92. lut_level[0][i] = lut[i] & 3;
  93. lut_level[1][i] = (lut[i]>>2) & 3;
  94. lut_level[2][i] = (lut[i]>>4) & 3;
  95. lut_level[3][i] = (lut[i]>>6) & 3;
  96. }
  97. for ( i = 0; i < LUT_ARRAY_LEN/2; i++ )
  98. {
  99. lut_time[i*2 + 0] = lut[LUT_ARRAY_LEN+i] & 15;
  100. lut_time[i*2 + 1] = (lut[LUT_ARRAY_LEN+i]>>4) & 15;
  101. }
  102. }
  103. void draw_lut_wave(u8g2_t *u8g2, uint8_t w, uint8_t cx, uint8_t is_cursor, u8g2_uint_t y)
  104. {
  105. uint8_t i;
  106. u8g2_uint_t x1, y1;
  107. u8g2_uint_t x2, y2;
  108. x1 = 18;
  109. y1 = y;
  110. u8g2_DrawGlyph(u8g2, 2,y+2, (w&2)?'1':'0');
  111. u8g2_DrawGlyph(u8g2, 8,y+2, (w&1)?'1':'0');
  112. for( i = 0; i < LUT_ARRAY_LEN; i++ )
  113. {
  114. x2 = x1 + get_dx(i);
  115. y2 = y;
  116. if ( lut_level[w][i] == 1)
  117. y2 -= LUT_DY-1;
  118. else if ( lut_level[w][i] == 2 )
  119. y2 += LUT_DY-1;
  120. if ( y1 != y2 )
  121. u8g2_DrawLine(u8g2, x1, y1, x1, y2);
  122. u8g2_DrawHLine(u8g2, x1, y2, x2-x1+1);
  123. if ( i == cx )
  124. {
  125. cursor_x1 = x1;
  126. cursor_x2 = x2;
  127. if ( is_cursor )
  128. {
  129. u8g2_DrawHLine(u8g2, x1, y-LUT_DY-1, x2-x1+1);
  130. u8g2_DrawHLine(u8g2, x1, y+LUT_DY+1, x2-x1+1);
  131. }
  132. }
  133. x1 = x2;
  134. y1 = y2;
  135. }
  136. }
  137. void draw_all_lut(u8g2_t *u8g2, uint8_t cx, uint8_t cy)
  138. {
  139. uint8_t i;
  140. uint16_t total;
  141. int16_t area;
  142. u8g2_uint_t x, y;
  143. u8g2_uint_t xs = 1;
  144. y = LUT_DY +1;
  145. for( i = 0; i < LUT_WAVE_CNT; i++ )
  146. {
  147. if ( i == cy )
  148. draw_lut_wave(u8g2, i, cx, 1, y);
  149. else
  150. draw_lut_wave(u8g2, i, cx, 0, y); // 255: no cursor
  151. y += (LUT_DY+2)*2;
  152. }
  153. total = 0;
  154. area = 0;
  155. if ( cy == LUT_WAVE_CNT )
  156. for( i = 0; i < LUT_ARRAY_LEN; i++ )
  157. total += lut_time[i];
  158. if ( cy < LUT_WAVE_CNT )
  159. {
  160. for( i = 0; i < LUT_ARRAY_LEN; i++ )
  161. {
  162. if ( lut_level[cy][i] == 1 )
  163. area += lut_time[i];
  164. else if ( lut_level[cy][i] == 2 )
  165. area -= lut_time[i];
  166. }
  167. }
  168. y+=1;
  169. if ( cy == LUT_WAVE_CNT )
  170. {
  171. u8g2_SetDrawColor(u8g2, 2);
  172. u8g2_DrawBox(u8g2, cursor_x1, 0, cursor_x2-cursor_x1+1, (LUT_DY+2)*2*4-1 );
  173. u8g2_SetDrawColor(u8g2, 0);
  174. }
  175. else
  176. {
  177. u8g2_SetDrawColor(u8g2, 1);
  178. }
  179. x = u8g2_DrawStr(u8g2, xs, y, " TP[");
  180. x += u8g2_DrawStr(u8g2, x, y, u8x8_u8toa( cx, 2));
  181. x += u8g2_DrawStr(u8g2, x, y, "]=");
  182. x += u8g2_DrawStr(u8g2, x, y, u8x8_u8toa( lut_time[cx], 2));
  183. x += u8g2_DrawStr(u8g2, x, y, " ");
  184. u8g2_SetDrawColor(u8g2, 1);
  185. x = 70;
  186. if ( cy == LUT_WAVE_CNT+1 )
  187. {
  188. if ( lut_measured_duration > 0 )
  189. {
  190. x = 60;
  191. x += u8g2_DrawStr(u8g2, x, y, "measure=");
  192. x += u8g2_DrawStr(u8g2, x, y, u8x8_u16toa( lut_measured_duration, 4));
  193. }
  194. }
  195. if ( cy == LUT_WAVE_CNT )
  196. {
  197. x += u8g2_DrawStr(u8g2, x, y, " total=");
  198. x += u8g2_DrawStr(u8g2, x, y, u8x8_u16toa( total, 3));
  199. x += u8g2_DrawStr(u8g2, x, y, " ");
  200. }
  201. else if ( cy < LUT_WAVE_CNT )
  202. {
  203. x += u8g2_DrawStr(u8g2, x, y, " area=");
  204. if ( area >= 0 )
  205. x += u8g2_DrawStr(u8g2, x, y, u8x8_u16toa( area, 3));
  206. else
  207. {
  208. x += u8g2_DrawStr(u8g2, x, y, "-");
  209. x += u8g2_DrawStr(u8g2, x, y, u8x8_u16toa( -area, 3));
  210. }
  211. x += u8g2_DrawStr(u8g2, x, y, " ");
  212. }
  213. y+=8;
  214. x = u8g2_DrawStr(u8g2, xs, y, "Test: ");
  215. if ( cy == LUT_WAVE_CNT+1 && (cx & 1) == 0 )
  216. {
  217. u8g2_SetDrawColor(u8g2, 0);
  218. }
  219. else
  220. {
  221. u8g2_SetDrawColor(u8g2, 1);
  222. }
  223. x += u8g2_DrawStr(u8g2, x, y, " New ");
  224. if ( cy == LUT_WAVE_CNT+1 && (cx & 1) != 0 )
  225. {
  226. u8g2_SetDrawColor(u8g2, 0);
  227. }
  228. else
  229. {
  230. u8g2_SetDrawColor(u8g2, 1);
  231. }
  232. x += u8g2_DrawStr(u8g2, x, y, " Old ");
  233. u8g2_SetDrawColor(u8g2, 1);
  234. //if ( lut_measured_duration > 0 )
  235. //{
  236. // x = 60;
  237. // x += u8g2_DrawStr(u8g2, x, y, "measure=");
  238. // x += u8g2_DrawStr(u8g2, x, y, u8x8_u16toa( lut_measured_duration, 4));
  239. //}
  240. y+=8;
  241. if ( cy == LUT_WAVE_CNT+2 )
  242. {
  243. u8g2_SetDrawColor(u8g2, 0);
  244. }
  245. else
  246. {
  247. u8g2_SetDrawColor(u8g2, 1);
  248. }
  249. x = u8g2_DrawStr(u8g2, xs, y, " Show Binary LUT ");
  250. u8g2_SetDrawColor(u8g2, 1);
  251. //extern uint16_t refresh_cnt;
  252. //u8g2_DrawStr(u8g2, 115, y, u8x8_u16toa( refresh_cnt, 2));
  253. }
  254. void init_lut(void)
  255. {
  256. uint8_t i, j;
  257. for( i = 0; i < LUT_ARRAY_LEN; i++ )
  258. {
  259. for( j = 0; j < LUT_WAVE_CNT; j++ )
  260. lut_level[j][i] = 0;
  261. lut_time[i] = 0;
  262. }
  263. }
  264. uint8_t edit_lut(u8g2_t *u8g2)
  265. {
  266. uint8_t event;
  267. uint8_t cx, cy;
  268. u8g2_SetFont(u8g2, u8g2_font_5x7_mr);
  269. u8g2_SetFontMode(u8g2, 0);
  270. u8g2_SetFontDirection(u8g2, 0);
  271. cx = 0;
  272. cy = 0;
  273. for(;;)
  274. {
  275. u8g2_FirstPage(u8g2);
  276. do
  277. {
  278. draw_all_lut(u8g2, cx, cy);
  279. } while( u8g2_NextPage(u8g2) );
  280. for(;;)
  281. {
  282. event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
  283. if ( event == U8X8_MSG_GPIO_MENU_SELECT )
  284. {
  285. if ( cx < LUT_ARRAY_LEN && cy < LUT_WAVE_CNT )
  286. {
  287. lut_level[cy][cx]++;
  288. if ( lut_level[cy][cx] >= 3 )
  289. lut_level[cy][cx] = 0;
  290. }
  291. else if ( cy == LUT_WAVE_CNT )
  292. {
  293. lut_time[cx]++;
  294. if ( lut_time[cx] >= 16 )
  295. lut_time[cx] = 0;
  296. }
  297. else if ( cy == LUT_WAVE_CNT+1 )
  298. {
  299. if ( (cx & 1) == 0 )
  300. return 1; /* new waveform */
  301. return 2; /* old/buildin refresh waveform */
  302. }
  303. else if ( cy == LUT_WAVE_CNT+2 )
  304. {
  305. return 10; /* show lut */
  306. }
  307. break;
  308. }
  309. else if ( event == U8X8_MSG_GPIO_MENU_HOME )
  310. {
  311. if ( cy == LUT_WAVE_CNT )
  312. {
  313. if ( lut_time[cx] == 0 )
  314. lut_time[cx] = 16;
  315. lut_time[cx]--;
  316. }
  317. break;
  318. }
  319. else if ( event == U8X8_MSG_GPIO_MENU_NEXT )
  320. {
  321. cx++;
  322. if ( cx >= LUT_ARRAY_LEN )
  323. cx = 0;
  324. break;
  325. }
  326. else if ( event == U8X8_MSG_GPIO_MENU_DOWN )
  327. {
  328. cy++;
  329. if ( cy >= LUT_WAVE_CNT+3 )
  330. cy = 0;
  331. break;
  332. }
  333. else if ( event == U8X8_MSG_GPIO_MENU_PREV )
  334. {
  335. if ( cx == 0 )
  336. cx = LUT_ARRAY_LEN;
  337. cx--;
  338. break;
  339. }
  340. else if ( event == U8X8_MSG_GPIO_MENU_UP )
  341. {
  342. if ( cy == 0 )
  343. cy = LUT_WAVE_CNT+3;
  344. cy--;
  345. break;
  346. }
  347. }
  348. }
  349. return 0;
  350. }
  351. /* send lut to the target eink device (given by u8x8_t *) */
  352. void write_to_lut_register(u8x8_t *epaper)
  353. {
  354. uint8_t i;
  355. uint8_t b;
  356. u8x8_cad_StartTransfer(epaper);
  357. u8x8_cad_SendCmd(epaper, 0x032);
  358. for ( i = 0; i < LUT_ARRAY_LEN; i++ )
  359. {
  360. b = lut_level[0][i];
  361. b |= lut_level[1][i]<<2;
  362. b |= lut_level[2][i]<<4;
  363. b |= lut_level[3][i]<<6;
  364. u8x8_cad_SendArg(epaper, b);
  365. }
  366. for ( i = 0; i < LUT_ARRAY_LEN/2; i++ )
  367. {
  368. b = lut_time[i*2 + 0];
  369. b |= lut_time[i*2 + 1] << 4;
  370. u8x8_cad_SendArg(epaper, b);
  371. }
  372. u8x8_cad_EndTransfer(epaper);
  373. }
  374. /*================================================*/
  375. /*================================================*/
  376. /* epaper test */
  377. uint8_t is_enable_hook;
  378. uint8_t (*u8x8_d_original)(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
  379. /* the purpose of this hook function is to replace the REFRESH code by our own function */
  380. uint8_t u8x8_d_test_hook(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  381. {
  382. volatile uint32_t start, curr, end;
  383. volatile uint16_t v;
  384. if ( is_enable_hook )
  385. {
  386. if ( msg == U8X8_MSG_DISPLAY_REFRESH )
  387. {
  388. u8x8_cad_StartTransfer(u8x8);
  389. u8x8_cad_SendCmd(u8x8, 0x022); // program update sequence
  390. u8x8_cad_SendArg(u8x8, 0x004); // define sequence
  391. // 0x0c4: clk -> CP -> LUT -> pattern display
  392. u8x8_cad_SendCmd(u8x8, 0x020); // execute
  393. start =millis();
  394. end = start + 4000;
  395. //pinMode(A2, INPUT);
  396. delay(10);
  397. for(;;)
  398. {
  399. v = analogRead(BUSY_PIN);
  400. curr = millis();
  401. if ( v < 300 )
  402. break;
  403. if ( curr > end )
  404. break;
  405. }
  406. lut_measured_duration = curr-start;
  407. u8x8_cad_EndTransfer(u8x8);
  408. return 1;
  409. }
  410. }
  411. return u8x8_d_original(u8x8, msg, arg_int, arg_ptr);
  412. }
  413. void test_lut(u8g2_t *u8g2)
  414. {
  415. u8g2_epaper.setPowerSave(0);
  416. u8g2_FirstPage(u8g2);
  417. do
  418. {
  419. u8g2_DrawStr(u8g2, 0, 20, "Test LUT, Page 1");
  420. } while( u8g2_NextPage(u8g2) );
  421. u8g2_epaper.firstPage();
  422. do {
  423. u8g2_epaper.setFont(u8g2_font_ncenB14_tr);
  424. u8g2_epaper.drawStr(0,20,"11111111111111111111111111");
  425. u8g2_epaper.drawStr(0,40,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  426. u8g2_epaper.drawBox(10, 60, 60, 30);
  427. u8g2_epaper.drawFrame(50, 70, 60, 40);
  428. u8g2_epaper.drawBox(110+10, 60, 60, 30);
  429. } while ( u8g2_epaper.nextPage() );
  430. delay(3000);
  431. u8g2_FirstPage(u8g2);
  432. do
  433. {
  434. u8g2_DrawStr(u8g2, 0, 20, "Test LUT, Page 2");
  435. u8g2_DrawStr(u8g2, 0, 40, u8x8_u16toa( lut_measured_duration, 4));
  436. } while( u8g2_NextPage(u8g2) );
  437. u8g2_epaper.firstPage();
  438. do {
  439. u8g2_epaper.setFont(u8g2_font_ncenB14_tr);
  440. u8g2_epaper.drawStr(0,20,"22222222222222222222222222");
  441. u8g2_epaper.drawStr(0,40,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  442. u8g2_epaper.drawFrame(10, 60, 60, 30);
  443. u8g2_epaper.drawBox(50, 70, 60, 40);
  444. u8g2_epaper.drawBox(150+10, 70, 60, 40);
  445. } while ( u8g2_epaper.nextPage() );
  446. delay(3000);
  447. u8g2_FirstPage(u8g2);
  448. do
  449. {
  450. u8g2_DrawStr(u8g2, 0, 20, "Test LUT, Page 3");
  451. u8g2_DrawStr(u8g2, 0, 40, u8x8_u16toa( lut_measured_duration, 4));
  452. } while( u8g2_NextPage(u8g2) );
  453. u8g2_epaper.firstPage();
  454. do {
  455. u8g2_epaper.setFont(u8g2_font_ncenB14_tr);
  456. u8g2_epaper.drawStr(0,20,"33333333333333333333333333");
  457. u8g2_epaper.drawStr(0,40,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  458. u8g2_epaper.drawBox(10, 60, 60, 30);
  459. u8g2_epaper.drawFrame(50, 70, 60, 40);
  460. u8g2_epaper.drawBox(110+10, 60, 60, 30);
  461. } while ( u8g2_epaper.nextPage() );
  462. u8g2_epaper.setPowerSave(1);
  463. delay(3000);
  464. }
  465. /*================================================*/
  466. /* send lut to the target eink device (given by u8x8_t *) */
  467. void show_lut_on_editor(void)
  468. {
  469. uint8_t i;
  470. uint8_t b;
  471. u8g2_uint_t x, y;
  472. x = 0;
  473. y = 0;
  474. for ( i = 0; i < LUT_ARRAY_LEN; i++ )
  475. {
  476. b = lut_level[0][i];
  477. b |= lut_level[1][i]<<2;
  478. b |= lut_level[2][i]<<4;
  479. b |= lut_level[3][i]<<6;
  480. u8g2_editor.setCursor(x*20, y*8+8);
  481. u8g2_editor.print(b, HEX);
  482. x++;
  483. if ( x >= 5 )
  484. {
  485. x = 0;
  486. y++;
  487. }
  488. }
  489. x = 0;
  490. y++;
  491. for ( i = 0; i < LUT_ARRAY_LEN/2; i++ )
  492. {
  493. b = lut_time[i*2 + 0];
  494. b |= lut_time[i*2 + 1] << 4;
  495. u8g2_editor.setCursor(x*20, y*8+8);
  496. u8g2_editor.print(b, HEX);
  497. x++;
  498. if ( x >= 5 )
  499. {
  500. x = 0;
  501. y++;
  502. }
  503. }
  504. }
  505. /*================================================*/
  506. /* arduino setup & loop */
  507. const uint8_t LUTDefault_full[31] =
  508. {
  509. 0x50, 0xAA, 0x55, 0xAA, 0x11,
  510. 0x11, 0x00, 0x00, 0x00, 0x00,
  511. 0x00, 0x00, 0x00, 0x00, 0x00,
  512. 0x00, 0x00, 0x00, 0x00, 0x00,
  513. 0xFF, 0xFF, 0x3F, 0x00, 0x00,
  514. 0x00, 0x00, 0x00, 0x00, 0x00
  515. };
  516. // same as LUTDefault_full, but dubled size
  517. const uint8_t w01[30] =
  518. {
  519. 0x00, 0x00, 0x44, 0xaa, 0xaa,
  520. 0x55, 0x55, 0xaa, 0xaa, 0x11,
  521. 0x11, 0x00, 0x00, 0x00, 0x00,
  522. 0x00, 0x00, 0x00, 0x00, 0x00,
  523. 0x01, 0xff, 0xff, 0xff, 0xff,
  524. 0x0f, 0x00, 0x00, 0x00, 0x00
  525. };
  526. // same as w01, but timing adjisted, should be identical to LUTDefault_full
  527. const uint8_t w02[30] =
  528. {
  529. 0x00, 0x00, 0x44, 0xaa, 0xaa,
  530. 0x55, 0x55, 0xaa, 0xaa, 0x11,
  531. 0x11, 0x00, 0x00, 0x00, 0x00,
  532. 0x00, 0x00, 0x00, 0x00, 0x00,
  533. 0x11, 0x5a, 0x5a, 0x5a, 0x5a,
  534. 0x0a, 0x00, 0x00, 0x00, 0x00
  535. };
  536. // speed optimized, lesser flickering version
  537. // ticks=71
  538. // measued=1441ms
  539. const uint8_t w03[30] =
  540. {
  541. 0x00, 0x40, 0x04, 0xa6, 0xa8,
  542. 0x65, 0x19, 0xaa, 0x98, 0x11,
  543. 0x11, 0x00, 0x00, 0x00, 0x00,
  544. 0x00, 0x00, 0x00, 0x00, 0x00,
  545. 0x20, 0x26, 0x26, 0x26, 0xff,
  546. 0x0f, 0x00, 0x00, 0x00, 0x00
  547. };
  548. // speed optimized, lesser flickering version
  549. // ticks=71
  550. // measued=1441ms
  551. const uint8_t w04[30] =
  552. {
  553. 0x00, 0x88, 0x88, 0x88, 0x98,
  554. 0x99, 0x99, 0x99, 0x11, 0x11,
  555. 0x11, 0x00, 0x00, 0x00, 0x00,
  556. 0x00, 0x00, 0x00, 0x00, 0x00,
  557. 0x77, 0x77, 0x77, 0x77, 0x77,
  558. 0x00, 0x00, 0x00, 0x00, 0x00
  559. };
  560. // speed optimized, no (?) flickering version
  561. const uint8_t w05[30] =
  562. {
  563. 0xaa, 0x55, 0x55, 0x55, 0x99,
  564. 0x99, 0x99, 0x99, 0x99, 0x00,
  565. 0x00, 0x00, 0x00, 0x00, 0x00,
  566. 0x00, 0x00, 0x00, 0x00, 0x00,
  567. 0x77, 0x77, 0x77, 0x77, 0x07,
  568. 0x00, 0x00, 0x00, 0x00, 0x00
  569. };
  570. /*
  571. Duration: 1240 ms
  572. Initial white pulse:
  573. - Required for white-white so that white stays white (pulse can be as low as 2 ticks)
  574. - On black-black to ensure long term stbility (pulse should be 4 or higher for
  575. long term stability)
  576. - Pulse should be short, to avoid flicker
  577. - Long enough for the black-black transition
  578. White pixel (black-white transition)
  579. - Starts at the beginning. Looks like a black pulse is not required.
  580. - White low level must stop before the black pixel are finished
  581. Black pixel (black-black and white-black)
  582. - Black (high level) is extended. If the black level is applied longer, the contrast
  583. gets better.
  584. - There must be no white pixel write otherwise contrast will be bad: Writing
  585. black is put at the end and starts in the middle
  586. */
  587. /*
  588. U8X8_A(0x02),
  589. U8X8_A(0x02),
  590. U8X8_A(0x01),
  591. U8X8_A(0x11),
  592. U8X8_A(0x12),
  593. U8X8_A(0x12),
  594. U8X8_A(0x22),
  595. U8X8_A(0x22),
  596. U8X8_A(0x66),
  597. U8X8_A(0x69),
  598. U8X8_A(0x69),
  599. U8X8_A(0x59),
  600. U8X8_A(0x58),
  601. U8X8_A(0x99),
  602. U8X8_A(0x99),
  603. U8X8_A(0x88),
  604. U8X8_A(0x00),
  605. U8X8_A(0x00),
  606. U8X8_A(0x00),
  607. U8X8_A(0x00),
  608. U8X8_A(0xF8),
  609. U8X8_A(0xB4),
  610. U8X8_A(0x13),
  611. U8X8_A(0x51),
  612. U8X8_A(0x35),
  613. U8X8_A(0x51),
  614. U8X8_A(0x51),
  615. U8X8_A(0x19),
  616. U8X8_A(0x01),
  617. U8X8_A(0x00),
  618. */
  619. const uint8_t w06[30] =
  620. {
  621. 0x02, 0x02, 0x01, 0x11, 0x12,
  622. 0x12, 0x12, 0x22, 0x22, 0x66,
  623. 0x69, 0x59, 0x58, 0x99, 0x99,
  624. 0x88, 0x00, 0x00, 0x00, 0x00,
  625. 0xf8, 0xb4, 0x13, 0x51, 0x35,
  626. 0x51, 0x51, 0xe9, 0x04, 0x00
  627. };
  628. void setup(void)
  629. {
  630. u8g2_editor.begin(/* menu_select_pin= */ 2, /* menu_next_pin= */ 4, /* menu_prev_pin= */ 7, /* menu_up_pin= */ 6, /* menu_down_pin= */ 5, /* menu_home_pin= */ 3);
  631. u8g2_editor.setFont(u8g2_font_5x7_mr);
  632. u8g2_editor.setFontMode(0);
  633. u8g2_editor.setFontDirection(0);
  634. u8g2_epaper.begin();
  635. u8g2_epaper.setPowerSave(0);
  636. u8x8_d_original = u8g2_epaper.getU8x8()->display_cb; // get the original display function and..
  637. u8g2_epaper.getU8x8()->display_cb = u8x8_d_test_hook; // ...replace it with our hook function
  638. init_lut();
  639. //read_lut(LUTDefault_full);
  640. read_lut(w06);
  641. }
  642. void loop(void)
  643. {
  644. uint8_t cmd;
  645. cmd = edit_lut(u8g2_editor.getU8g2());
  646. switch( cmd )
  647. {
  648. case 1: /* test new lut */
  649. is_enable_hook = 1;
  650. u8g2_epaper.setPowerSave(0);
  651. write_to_lut_register(u8g2_epaper.getU8x8());
  652. test_lut(u8g2_editor.getU8g2());
  653. break;
  654. case 2: /* test old, existing lut */
  655. is_enable_hook = 0;
  656. u8g2_epaper.initDisplay();
  657. u8g2_epaper.setPowerSave(0);
  658. test_lut(u8g2_editor.getU8g2());
  659. break;
  660. case 10:
  661. u8g2_editor.firstPage();
  662. do {
  663. show_lut_on_editor();
  664. } while ( u8g2_editor.nextPage() );
  665. while( u8g2_editor.getMenuEvent() == 0 )
  666. ;
  667. }
  668. }