Skip to content

Commit 1cc1346

Browse files
Saving progress
1 parent c3bbcf9 commit 1cc1346

File tree

8 files changed

+1072
-4
lines changed

8 files changed

+1072
-4
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
**************************************************
3+
* @file Inkplate6COLOR_Factory_Programming.ino
4+
*
5+
* @brief File for factory programming Inkplate6 COLOR
6+
*
7+
* @note Tests will also be done, to pass all tests:
8+
* - Edit the WiFi information in test.cpp.
9+
* - Connect a slave device via EasyC on address 0x30 (you may change this in test.cpp also).
10+
* In the InkplateEasyCTester folder, you can find the code for uploading to Dasduino Core
11+
* or Dasduino ConnectPlus to convert Dasduino to an I2C slave device for testing an easyC connector
12+
* if you don't have a device with address 0x30.
13+
* - Insert a formatted microSD card (doesn't have to be empty)
14+
* - Press wake button to finish testing
15+
* Output of the tests will be done via Serial due to slow screen refresh rate.
16+
*
17+
*License v3.0: https://www.gnu.org/licenses/lgpl-3.0.en.html Please review the
18+
*LICENSE file included with this example. If you have any questions about
19+
*licensing, please visit https://soldered.com/contact/ Distributed as-is; no
20+
*warranty is given.
21+
*
22+
* @authors Soldered
23+
***************************************************/
24+
25+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
26+
#if !defined(ARDUINO_INKPLATECOLOR) && !defined(ARDUINO_INKPLATECOLORV2)
27+
#error "Wrong board selection for this example, please select Inkplate 6 Color in the boards menu."
28+
#endif
29+
30+
// Do not forget to add WiFi SSID and WiFi Password in test.cpp!
31+
32+
// Include needed libraries in the sketch
33+
#include "EEPROM.h"
34+
#include "Inkplate.h"
35+
#include "Wire.h"
36+
37+
// Include our functions and image
38+
#include "Peripheral.h"
39+
#include "test.h"
40+
#include "image.h"
41+
42+
Inkplate display;
43+
44+
// If you want to write new VCOM voltage and perform all tests change this number
45+
const int EEPROMaddress = 0;
46+
47+
// Peripheral mode variables and arrays
48+
#define BUFFER_SIZE 1000
49+
char commandBuffer[BUFFER_SIZE + 1];
50+
51+
void setup()
52+
{
53+
Serial.begin(115200);
54+
display.setTextSize(3);
55+
EEPROM.begin(512);
56+
Wire.begin();
57+
58+
// Wakeup button
59+
pinMode(GPIO_NUM_36, INPUT);
60+
61+
bool isFirstStartup = true;
62+
63+
if (isFirstStartup)
64+
{
65+
Wire.setTimeOut(3000);
66+
// Try to ping IO expander to test I2C
67+
Wire.beginTransmission(IO_INT_ADDR);
68+
if (Wire.endTransmission() != 0)
69+
{
70+
Serial.println("I2C Bus error!");
71+
failHandler();
72+
}
73+
}
74+
75+
display.begin();
76+
77+
if (isFirstStartup)
78+
{
79+
// Test all the peripherals
80+
testPeripheral();
81+
82+
EEPROM.write(EEPROMaddress, 170);
83+
EEPROM.commit();
84+
}
85+
86+
memset(commandBuffer, 0, BUFFER_SIZE);
87+
88+
showSplashScreen();
89+
}
90+
91+
void loop()
92+
{
93+
// Peripheral mode
94+
// More about peripheral mode: https://inkplate.readthedocs.io/en/latest/peripheral-mode.html
95+
96+
if (Serial.available())
97+
{
98+
while (Serial.available())
99+
{
100+
for (int i = 0; i < (BUFFER_SIZE - 1); i++)
101+
{
102+
commandBuffer[i] = commandBuffer[i + 1];
103+
}
104+
commandBuffer[BUFFER_SIZE - 1] = Serial.read();
105+
}
106+
}
107+
108+
// Function in Peripheral.h
109+
run(commandBuffer, BUFFER_SIZE, &display);
110+
}
111+
112+
// Print the initial image that remains on the screen
113+
void showSplashScreen()
114+
{
115+
display.clearDisplay();
116+
display.image.drawBitmap3Bit(0, 0, demo_image, demo_image_w, demo_image_h);
117+
display.display();
118+
}
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
/*
2+
More about peripheral mode: https://inkplate.readthedocs.io/en/latest/peripheral-mode.html
3+
*/
4+
5+
char strTemp[2001];
6+
7+
int hexToChar(char c)
8+
{
9+
if (c >= '0' && c <= '9')
10+
return c - '0';
11+
if (c >= 'A' && c <= 'F')
12+
return c - 'A' + 10;
13+
if (c >= 'a' && c <= 'f')
14+
return c - 'a' + 10;
15+
return -1;
16+
}
17+
18+
void run(char commandBuffer[], size_t n, Inkplate *display)
19+
{
20+
char *s = NULL;
21+
char *e = NULL;
22+
for (int i = 0; i < n; i++)
23+
{
24+
if (commandBuffer[i] == '#' && s == NULL)
25+
s = &commandBuffer[i];
26+
if (commandBuffer[i] == '*' && e == NULL)
27+
e = &commandBuffer[i];
28+
}
29+
if (s != NULL && e != NULL)
30+
{
31+
if ((e - s) > 0)
32+
{
33+
int x, x1, x2, y, y1, y2, x3, y3, l, c, w, h, r, n;
34+
char b;
35+
switch (*(s + 1))
36+
{
37+
case '?':
38+
Serial.print("OK");
39+
break;
40+
41+
case '0':
42+
sscanf(s + 3, "%d,%d,%d", &x, &y, &c);
43+
display->drawPixel(x, y, c);
44+
break;
45+
46+
case '1':
47+
sscanf(s + 3, "%d,%d,%d,%d,%d", &x1, &y1, &x2, &y2, &c);
48+
display->drawLine(x1, y1, x2, y2, c);
49+
break;
50+
51+
case '2':
52+
sscanf(s + 3, "%d,%d,%d,%d", &x, &y, &l, &c);
53+
display->drawFastVLine(x, y, l, c);
54+
break;
55+
56+
case '3':
57+
sscanf(s + 3, "%d,%d,%d,%d", &x, &y, &l, &c);
58+
display->drawFastHLine(x, y, l, c);
59+
break;
60+
61+
case '4':
62+
sscanf(s + 3, "%d,%d,%d,%d,%d", &x, &y, &w, &h, &c);
63+
display->drawRect(x, y, w, h, c);
64+
break;
65+
66+
case '5':
67+
sscanf(s + 3, "%d,%d,%d,%d", &x, &y, &r, &c);
68+
display->drawCircle(x, y, r, c);
69+
break;
70+
71+
case '6':
72+
sscanf(s + 3, "%d,%d,%d,%d,%d,%d,%d", &x1, &y1, &x2, &y2, &x3, &y3, &c);
73+
display->drawTriangle(x1, y1, x2, y2, x3, y3, c);
74+
break;
75+
76+
case '7':
77+
sscanf(s + 3, "%d,%d,%d,%d,%d,%d", &x, &y, &w, &h, &r, &c);
78+
display->drawRoundRect(x, y, w, h, r, c);
79+
break;
80+
81+
case '8':
82+
sscanf(s + 3, "%d,%d,%d,%d,%d", &x, &y, &w, &h, &c);
83+
display->fillRect(x, y, w, h, c);
84+
break;
85+
86+
case '9':
87+
sscanf(s + 3, "%d,%d,%d,%d", &x, &y, &r, &c);
88+
display->fillCircle(x, y, r, c);
89+
break;
90+
91+
case 'A':
92+
sscanf(s + 3, "%d,%d,%d,%d,%d,%d,%d", &x1, &y1, &x2, &y2, &x3, &y3, &c);
93+
display->fillTriangle(x1, y1, x2, y2, x3, y3, c);
94+
break;
95+
96+
case 'B':
97+
sscanf(s + 3, "%d,%d,%d,%d,%d,%d", &x, &y, &w, &h, &r, &c);
98+
display->fillRoundRect(x, y, w, h, r, c);
99+
break;
100+
101+
case 'C':
102+
sscanf(s + 3, "\"%2000[^\"]\"", strTemp);
103+
n = strlen(strTemp);
104+
for (int i = 0; i < n; i++)
105+
{
106+
strTemp[i] = toupper(strTemp[i]);
107+
}
108+
for (int i = 0; i < n; i += 2)
109+
{
110+
strTemp[i / 2] = (hexToChar(strTemp[i]) << 4) | (hexToChar(strTemp[i + 1]) & 0x0F);
111+
}
112+
strTemp[n / 2] = 0;
113+
display->print(strTemp);
114+
break;
115+
116+
case 'D':
117+
sscanf(s + 3, "%d", &c);
118+
display->setTextSize(c);
119+
break;
120+
121+
case 'E':
122+
sscanf(s + 3, "%d,%d", &x, &y);
123+
display->setCursor(x, y);
124+
break;
125+
126+
case 'F':
127+
sscanf(s + 3, "%c", &b);
128+
if (b == 'T')
129+
display->setTextWrap(true);
130+
if (b == 'F')
131+
display->setTextWrap(false);
132+
break;
133+
134+
case 'G':
135+
sscanf(s + 3, "%d", &c);
136+
c &= 3;
137+
display->setRotation(c);
138+
break;
139+
140+
case 'H':
141+
sscanf(s + 3, "%d,%d,\"%149[^\"]\"", &x, &y, strTemp);
142+
n = strlen(strTemp);
143+
for (int i = 0; i < n; i++)
144+
{
145+
strTemp[i] = toupper(strTemp[i]);
146+
}
147+
for (int i = 0; i < n; i += 2)
148+
{
149+
strTemp[i / 2] = (hexToChar(strTemp[i]) << 4) | (hexToChar(strTemp[i + 1]) & 0x0F);
150+
}
151+
strTemp[n / 2] = 0;
152+
r = display->sdCardInit();
153+
if (r)
154+
{
155+
r = display->image.drawBitmapFromSd(strTemp, x, y);
156+
Serial.print("#H(");
157+
Serial.print(r, DEC);
158+
Serial.println(")*");
159+
Serial.flush();
160+
}
161+
else
162+
{
163+
Serial.println("#H(-1)*");
164+
Serial.flush();
165+
}
166+
break;
167+
168+
case 'K':
169+
sscanf(s + 3, "%c", &b);
170+
if (b == '1')
171+
{
172+
display->clearDisplay();
173+
}
174+
break;
175+
176+
case 'L':
177+
sscanf(s + 3, "%c", &b);
178+
if (b == '1')
179+
{
180+
display->display();
181+
}
182+
break;
183+
184+
case 'O':
185+
sscanf(s + 3, "%d", &c);
186+
if (c >= 0 && c <= 2)
187+
{
188+
Serial.print("#O(");
189+
// Serial.print(display->readTouchpad(c), DEC);
190+
Serial.println(")*");
191+
Serial.flush();
192+
}
193+
break;
194+
195+
case 'P':
196+
sscanf(s + 3, "%c", &b);
197+
if (b == '?')
198+
{
199+
Serial.print("#P(");
200+
Serial.print(display->readBattery(), 2);
201+
Serial.println(")*");
202+
Serial.flush();
203+
}
204+
break;
205+
}
206+
*s = 0;
207+
*e = 0;
208+
}
209+
}
210+
}
323 KB
Loading

0 commit comments

Comments
 (0)