6
6
Inkplate display (INKPLATE_1BIT);
7
7
8
8
double 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;
10
13
11
14
// Peripheral mode variables and arrays
12
15
#define BUFFER_SIZE 1000
@@ -19,36 +22,89 @@ const char *testString = {"This is some test string..."};
19
22
// Internal registers of MCP
20
23
uint8_t mcpRegsInt[22 ];
21
24
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
+
22
45
void setup ()
23
46
{
24
- display.begin ();
25
47
Serial.begin (115200 );
26
- EEPROM.begin (64 );
48
+ display.begin ();
49
+ EEPROM.begin (512 );
27
50
28
- vcomVoltage = -1.19 ;
51
+ vcomVoltage = -1.3 ;
29
52
53
+ // Check if VCOM and waveform programming is not already done
30
54
if (EEPROM.read (EEPROMaddress) != 170 )
31
55
{
32
56
microSDCardTest ();
33
57
display.pinModeInternal (MCP23017_INT_ADDR, mcpRegsInt, 6 , INPUT_PULLUP);
34
58
writeVCOMToEEPROM (vcomVoltage);
35
59
EEPROM.write (EEPROMaddress, 170 );
36
60
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);
38
93
}
39
94
else
40
95
{
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 ;
43
100
}
44
101
memset (commandBuffer, 0 , BUFFER_SIZE);
45
102
46
- showSplashScreen ();
103
+ showSplashScreen (waveformEEPROM );
47
104
}
48
105
49
106
void loop ()
50
107
{
51
-
52
108
if (Serial.available ())
53
109
{
54
110
while (Serial.available ())
@@ -396,9 +452,9 @@ uint8_t readReg(uint8_t _reg)
396
452
return Wire.read ();
397
453
}
398
454
399
- void showSplashScreen ()
455
+ void showSplashScreen (struct waveformData _w )
400
456
{
401
- display.clean ( 0 , 1 );
457
+ display.clearDisplay ( );
402
458
display.display ();
403
459
display.selectDisplayMode (INKPLATE_3BIT);
404
460
display.drawBitmap3Bit (0 , 0 , demo_image, demo_image_w, demo_image_h);
@@ -407,6 +463,9 @@ void showSplashScreen()
407
463
display.setCursor (10 , 10 );
408
464
display.print (vcomVoltage, 2 );
409
465
display.print (" V" );
466
+ display.setCursor (10 , 20 );
467
+ display.print (" Waveform" );
468
+ display.print (_w.waveformId - 20 + 1 , DEC);
410
469
display.display ();
411
470
}
412
471
@@ -559,7 +618,35 @@ void microSDCardTest()
559
618
{
560
619
display.print (" FAIL!" );
561
620
display.display ();
562
- while (1 );
621
+ while (1 )
622
+ ;
563
623
}
564
624
display.clearDisplay ();
565
625
}
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