66Inkplate display (INKPLATE_1BIT);
77
88double vcomVoltage;
9- int EEPROMaddress = 0 ;
9+
10+ // EEPROMOffset must be between 0 and 20
11+ const int EEPROMOffset = 0 ;
12+ int EEPROMaddress = sizeof (waveformData) + EEPROMOffset;
1013
1114// Peripheral mode variables and arrays
1215#define BUFFER_SIZE 1000
@@ -19,36 +22,89 @@ const char *testString = {"This is some test string..."};
1922// Internal registers of MCP
2023uint8_t mcpRegsInt[22 ];
2124
25+ // All waveforms for Inkplate 10 boards
26+ uint8_t waveform1[8 ][9 ] = {{0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 }, {0 , 0 , 0 , 2 , 2 , 2 , 1 , 1 , 0 }, {0 , 0 , 2 , 1 , 1 , 2 , 2 , 1 , 0 },
27+ {0 , 1 , 2 , 2 , 1 , 2 , 2 , 1 , 0 }, {0 , 0 , 2 , 1 , 2 , 2 , 2 , 1 , 0 }, {0 , 2 , 2 , 2 , 2 , 2 , 2 , 1 , 0 },
28+ {0 , 0 , 0 , 0 , 0 , 2 , 1 , 2 , 0 }, {0 , 0 , 0 , 2 , 2 , 2 , 2 , 2 , 0 }};
29+ uint8_t waveform2[8 ][9 ] = {{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, {0 , 0 , 0 , 2 , 1 , 2 , 1 , 1 , 0 }, {0 , 0 , 0 , 2 , 2 , 1 , 2 , 1 , 0 },
30+ {0 , 0 , 2 , 2 , 1 , 2 , 2 , 1 , 0 }, {0 , 0 , 0 , 2 , 1 , 1 , 1 , 2 , 0 }, {0 , 0 , 2 , 2 , 2 , 1 , 1 , 2 , 0 },
31+ {0 , 0 , 0 , 0 , 0 , 1 , 2 , 2 , 0 }, {0 , 0 , 0 , 0 , 2 , 2 , 2 , 2 , 0 }};
32+ uint8_t waveform3[8 ][9 ] = {{0 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 0 }, {0 , 1 , 2 , 1 , 1 , 2 , 2 , 1 , 0 }, {0 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 0 },
33+ {0 , 0 , 2 , 2 , 2 , 2 , 2 , 1 , 0 }, {0 , 3 , 3 , 2 , 1 , 1 , 1 , 2 , 0 }, {0 , 3 , 3 , 2 , 2 , 1 , 1 , 2 , 0 },
34+ {0 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 0 }, {0 , 3 , 3 , 3 , 2 , 2 , 2 , 2 , 0 }};
35+ uint8_t *waveformList[] = {&waveform1[0 ][0 ], &waveform2[0 ][0 ], &waveform3[0 ][0 ]};
36+
37+ // Calculate number of possible waveforms
38+ uint8_t waveformListSize = (sizeof (waveformList) / sizeof (uint8_t *));
39+
40+ // Struct for reading waveform from EEPROM memory of ESP32
41+ struct waveformData waveformEEPROM;
42+
43+ int currentWaveform = 0 ;
44+
2245void setup ()
2346{
24- display.begin ();
2547 Serial.begin (115200 );
26- EEPROM.begin (64 );
48+ display.begin ();
49+ EEPROM.begin (512 );
2750
28- vcomVoltage = -1.19 ;
51+ vcomVoltage = -1.3 ;
2952
53+ // Check if VCOM and waveform programming is not already done
3054 if (EEPROM.read (EEPROMaddress) != 170 )
3155 {
3256 microSDCardTest ();
3357 display.pinModeInternal (MCP23017_INT_ADDR, mcpRegsInt, 6 , INPUT_PULLUP);
3458 writeVCOMToEEPROM (vcomVoltage);
3559 EEPROM.write (EEPROMaddress, 170 );
3660 EEPROM.commit ();
37- display.selectDisplayMode (INKPLATE_1BIT);
61+ display.selectDisplayMode (INKPLATE_3BIT);
62+
63+ // Display all shades of gray on epaper with first waveform
64+ showGradient (currentWaveform);
65+
66+ // Until "Load" key is not pressed, user can select one of the waveforms
67+ while (!display.readTouchpad (PAD2))
68+ {
69+ // Select and show next waveform
70+ if (display.readTouchpad (PAD3))
71+ {
72+ currentWaveform++;
73+ if (currentWaveform > waveformListSize - 1 )
74+ currentWaveform = 0 ;
75+ showGradient (currentWaveform);
76+ }
77+
78+ // Select and show prev. waveform
79+ if (display.readTouchpad (PAD1))
80+ {
81+ currentWaveform--;
82+ if (currentWaveform < 0 )
83+ currentWaveform = waveformListSize - 1 ;
84+ showGradient (currentWaveform);
85+ }
86+ }
87+
88+ // Load waveform in EEPROM memory of ESP32
89+ waveformEEPROM.waveformId = INKPLATE10_WAVEFORM1 + currentWaveform;
90+ memcpy (&waveformEEPROM.waveform , waveformList[currentWaveform], sizeof (waveformEEPROM.waveform ));
91+ waveformEEPROM.checksum = display.calculateChecksum (waveformEEPROM);
92+ display.burnWaveformToEEPROM (waveformEEPROM);
3893 }
3994 else
4095 {
41- Serial.println (" Vcom already set!" );
42- // vcomVoltage = (double)EEPROM.read(EEPROMaddress) / 100;
96+ Serial.println (" Vcom and waveform already set!" );
97+ display.einkOn ();
98+ vcomVoltage = (double )(readReg (0x03 ) | ((uint16_t )(readReg (0x04 & 1 ) << 8 ))) / -100 ;
99+ display.getWaveformFromEEPROM (&waveformEEPROM) ? waveformEEPROM.waveformId : -1 ;
43100 }
44101 memset (commandBuffer, 0 , BUFFER_SIZE);
45102
46- showSplashScreen ();
103+ showSplashScreen (waveformEEPROM );
47104}
48105
49106void loop ()
50107{
51-
52108 if (Serial.available ())
53109 {
54110 while (Serial.available ())
@@ -396,9 +452,9 @@ uint8_t readReg(uint8_t _reg)
396452 return Wire.read ();
397453}
398454
399- void showSplashScreen ()
455+ void showSplashScreen (struct waveformData _w )
400456{
401- display.clean ( 0 , 1 );
457+ display.clearDisplay ( );
402458 display.display ();
403459 display.selectDisplayMode (INKPLATE_3BIT);
404460 display.drawBitmap3Bit (0 , 0 , demo_image, demo_image_w, demo_image_h);
@@ -407,6 +463,9 @@ void showSplashScreen()
407463 display.setCursor (10 , 10 );
408464 display.print (vcomVoltage, 2 );
409465 display.print (" V" );
466+ display.setCursor (10 , 20 );
467+ display.print (" Waveform" );
468+ display.print (_w.waveformId - 20 + 1 , DEC);
410469 display.display ();
411470}
412471
@@ -559,7 +618,35 @@ void microSDCardTest()
559618 {
560619 display.print (" FAIL!" );
561620 display.display ();
562- while (1 );
621+ while (1 )
622+ ;
563623 }
564624 display.clearDisplay ();
565625}
626+
627+ void showGradient (int _selected)
628+ {
629+ int w = display.width () / 8 ;
630+ int h = display.height () - 100 ;
631+
632+ display.changeWaveform (waveformList[currentWaveform]);
633+
634+ display.fillRect (0 , 725 , 1200 , 100 , 7 );
635+
636+ display.setTextSize (4 );
637+ display.setTextColor (0 );
638+ display.setCursor (420 , 743 );
639+ display.print (" Waveform select" );
640+ display.setCursor (432 , 792 );
641+ display.print (" Prev Load Next" );
642+
643+ display.setCursor (800 , 743 );
644+ display.print (" 1 2 3" );
645+ display.drawRect ((_selected * 6 * 4 * 2 ) + 800 - 3 , 740 , (6 * 4 ) + 2 , (8 * 4 ) + 2 , 0 );
646+
647+ for (int i = 0 ; i < 8 ; i++)
648+ {
649+ display.fillRect (i * w, 0 , w, h, i);
650+ }
651+ display.display ();
652+ }
0 commit comments