Skip to content

Commit ad280be

Browse files
committed
IP 6COLOR peripheral mode update
1 parent 22d6d45 commit ad280be

File tree

5 files changed

+1758
-273
lines changed

5 files changed

+1758
-273
lines changed
Lines changed: 44 additions & 273 deletions
Original file line numberDiff line numberDiff line change
@@ -1,298 +1,69 @@
11
/*
2-
Inkplate6COLOR_Peripheral_Mode example for Soldered Inkplate 6COLOR
2+
Inkplate6COLOR_Peripheral_Mode sketch for Soldered Inkplate 6COLOR.
3+
For this example you will need only a USB-C cable and Inkplate 6COLOR.
34
Select "Soldered Inkplate 6COLOR" from Tools -> Board menu.
4-
Don't have "Soldered Inkplate 6COLOR" option? Follow our tutorial and add it:
5-
https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/
5+
Dont have "Soldered Inkplate 6COLOR" option? Follow our tutorial and add it:
6+
https://soldered.com/learn/add-inkplate-6color-board-definition-to-arduino-ide/
67
7-
Using this sketch, you don't have to program and control e-paper using Arduino code.
8-
Instead, you can send UART command. This give you flexibility that you can use this Inkplate 6COLOR on any platform!
8+
Using this sketch, you dont have to program and control the e-paper display using Arduino code.
9+
Instead, you can send UART commands. This gives you the flexibility to use Inkplate 6COLOR on any platform!
910
10-
Because it uses UART, it's little bit slower and it's not recommended to send bunch of
11-
drawPixel command to draw some image. Instead, load bitmaps and pictures on SD card and load image from SD.
12-
If we missed some function, you can modify this and make yor own.
13-
Also, every Inkplate comes with this peripheral mode right from the factory.
11+
Because it uses UART, it’s a bit slower and not recommended to send a large number of
12+
drawPixel commands to render images. Instead, store bitmaps or pictures on an SD card
13+
and load them directly from there.
14+
If any functionality is missing, you can modify this code and make your own version.
15+
Every Inkplate 6COLOR comes with this Peripheral Mode preloaded from the factory.
1416
1517
Learn more about Peripheral Mode:
1618
https://inkplate.readthedocs.io/en/latest/peripheral-mode.html
1719
18-
UART settings are: 115200 baud, standard parity, ending with "\n\r" (both)
19-
You can send commands via USB port or by directly connecting to ESP32 TX and RX pins.
20-
Don't forget you need to send #L(1)* after each command to show it on the display
21-
(equal to display.display()).
20+
UART settings are: 115200 baud, standard parity, ending with "\n\r" (Both NL & CR)
21+
You can send commands via the USB port or by directly connecting to the ESP32 TX and RX pins.
2222
23-
Want to learn more about Inkplate? Visit www.inkplate.io
24-
Looking to get support? Write on our forums: https://forum.soldered.com/
25-
15 July 2020 by Soldered
23+
Want to learn more about Inkplate? Visit:
24+
https://soldered.com/documentation/inkplate/
25+
26+
23 October 2025 by Soldered
2627
*/
2728

28-
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
29-
#ifndef ARDUINO_INKPLATECOLOR
30-
#error "Wrong board selection for this example, please select Soldered Inkplate 6COLOR in the boards menu."
31-
#endif
29+
// Include Inkplate library
30+
#include "Inkplate.h"
3231

33-
#include <Inkplate.h>
34-
Inkplate display;
32+
// Include Peripheral Mode library
33+
#include "InkplatePeripheralMode.h"
34+
35+
// Include the header file with sketch settings (buffer size, serial timeout, argument termination char, etc.)
36+
#include "settings.h"
3537

36-
#define BUFFER_SIZE 1000
37-
char commandBuffer[BUFFER_SIZE + 1];
38-
char strTemp[2001];
38+
// Pointer to the singleton Peripheral Mode instance
39+
PeripheralMode *peripheral;
40+
41+
// Create Inkplate 6COLOR display object
42+
Inkplate display;
3943

4044
void setup()
4145
{
46+
// Initialize Inkplate library
4247
display.begin();
43-
Serial.begin(115200);
44-
memset(commandBuffer, 0, BUFFER_SIZE);
45-
}
46-
47-
void loop()
48-
{
49-
// put your main code here, to run repeatedly:
50-
if (Serial.available())
51-
{
52-
while (Serial.available())
53-
{
54-
for (int i = 0; i < (BUFFER_SIZE - 1); i++)
55-
{
56-
commandBuffer[i] = commandBuffer[i + 1];
57-
}
58-
commandBuffer[BUFFER_SIZE - 1] = Serial.read();
59-
}
60-
}
61-
char *s = NULL;
62-
char *e = NULL;
63-
for (int i = 0; i < BUFFER_SIZE; i++)
64-
{
65-
if (commandBuffer[i] == '#' && s == NULL)
66-
s = &commandBuffer[i];
67-
if (commandBuffer[i] == '*' && e == NULL)
68-
e = &commandBuffer[i];
69-
}
70-
if (s != NULL && e != NULL)
71-
{
72-
if ((e - s) > 0)
73-
{
74-
int x, x1, x2, y, y1, y2, x3, y3, l, c, w, h, r, n, rx, ry, xc, yc;
75-
char b;
76-
char temp[150];
77-
switch (*(s + 1))
78-
{
79-
case '?':
80-
Serial.print("OK");
81-
break;
82-
83-
case '0':
84-
sscanf(s + 3, "%d,%d,%d", &x, &y, &c);
85-
display.drawPixel(x, y, c);
86-
break;
87-
88-
case '1':
89-
sscanf(s + 3, "%d,%d,%d,%d,%d", &x1, &y1, &x2, &y2, &c);
90-
display.drawLine(x1, y1, x2, y2, c);
91-
break;
92-
93-
case '2':
94-
sscanf(s + 3, "%d,%d,%d,%d", &x, &y, &l, &c);
95-
display.drawFastVLine(x, y, l, c);
96-
break;
97-
98-
case '3':
99-
sscanf(s + 3, "%d,%d,%d,%d", &x, &y, &l, &c);
100-
display.drawFastHLine(x, y, l, c);
101-
break;
102-
103-
case '4':
104-
sscanf(s + 3, "%d,%d,%d,%d,%d", &x, &y, &w, &h, &c);
105-
display.drawRect(x, y, w, h, c);
106-
break;
10748

108-
case '5':
109-
sscanf(s + 3, "%d,%d,%d,%d", &x, &y, &r, &c);
110-
display.drawCircle(x, y, r, c);
111-
break;
49+
// Create instance of Peripheral Mode object
50+
peripheral = PeripheralMode::getInstance();
11251

113-
case '6':
114-
sscanf(s + 3, "%d,%d,%d,%d,%d,%d,%d", &x1, &y1, &x2, &y2, &x3, &y3, &c);
115-
display.drawTriangle(x1, y1, x2, y2, x3, y3, c);
116-
break;
117-
118-
case '7':
119-
sscanf(s + 3, "%d,%d,%d,%d,%d,%d", &x, &y, &w, &h, &r, &c);
120-
display.drawRoundRect(x, y, w, h, r, c);
121-
break;
122-
123-
case '8':
124-
sscanf(s + 3, "%d,%d,%d,%d,%d", &x, &y, &w, &h, &c);
125-
display.fillRect(x, y, w, h, c);
126-
break;
127-
128-
case '9':
129-
sscanf(s + 3, "%d,%d,%d,%d", &x, &y, &r, &c);
130-
display.fillCircle(x, y, r, c);
131-
break;
132-
133-
case 'A':
134-
sscanf(s + 3, "%d,%d,%d,%d,%d,%d,%d", &x1, &y1, &x2, &y2, &x3, &y3, &c);
135-
display.fillTriangle(x1, y1, x2, y2, x3, y3, c);
136-
break;
137-
138-
case 'B':
139-
sscanf(s + 3, "%d,%d,%d,%d,%d,%d", &x, &y, &w, &h, &r, &c);
140-
display.fillRoundRect(x, y, w, h, r, c);
141-
break;
142-
143-
case 'C':
144-
sscanf(s + 3, "\"%2000[^\"]\"", strTemp);
145-
n = strlen(strTemp);
146-
for (int i = 0; i < n; i++)
147-
{
148-
strTemp[i] = toupper(strTemp[i]);
149-
}
150-
for (int i = 0; i < n; i += 2)
151-
{
152-
strTemp[i / 2] = (hexToChar(strTemp[i]) << 4) | (hexToChar(strTemp[i + 1]) & 0x0F);
153-
}
154-
strTemp[n / 2] = 0;
155-
display.print(strTemp);
156-
break;
157-
158-
case 'D':
159-
sscanf(s + 3, "%d", &c);
160-
display.setTextSize(c);
161-
break;
162-
163-
case 'E':
164-
sscanf(s + 3, "%d,%d", &x, &y);
165-
display.setCursor(x, y);
166-
break;
167-
168-
case 'F':
169-
sscanf(s + 3, "%c", &b);
170-
if (b == 'T')
171-
display.setTextWrap(true);
172-
if (b == 'F')
173-
display.setTextWrap(false);
174-
break;
175-
176-
case 'G':
177-
sscanf(s + 3, "%d", &c);
178-
c &= 3;
179-
display.setRotation(c);
180-
break;
181-
182-
case 'H':
183-
sscanf(s + 3, "%d,%d,\"%149[^\"]\"", &x, &y, strTemp);
184-
n = strlen(strTemp);
185-
for (int i = 0; i < n; i++)
186-
{
187-
strTemp[i] = toupper(strTemp[i]);
188-
}
189-
for (int i = 0; i < n; i += 2)
190-
{
191-
strTemp[i / 2] = (hexToChar(strTemp[i]) << 4) | (hexToChar(strTemp[i + 1]) & 0x0F);
192-
}
193-
strTemp[n / 2] = 0;
194-
r = display.sdCardInit();
195-
if (r)
196-
{
197-
r = display.drawBitmapFromSd(strTemp, x, y);
198-
Serial.print("#H(");
199-
Serial.print(r, DEC);
200-
Serial.println(")*");
201-
Serial.flush();
202-
}
203-
else
204-
{
205-
Serial.println("#H(-1)*");
206-
Serial.flush();
207-
}
208-
break;
209-
210-
case 'K':
211-
sscanf(s + 3, "%c", &b);
212-
if (b == '1')
213-
{
214-
display.clearDisplay();
215-
}
216-
break;
217-
218-
case 'L':
219-
sscanf(s + 3, "%c", &b);
220-
if (b == '1')
221-
{
222-
display.display();
223-
}
224-
break;
225-
226-
case 'M':
227-
sscanf(s + 3, "%d,%d,%d", &y1, &x2, &y2);
228-
display.display();
229-
break;
230-
231-
case 'P':
232-
sscanf(s + 3, "%c", &b);
233-
if (b == '?')
234-
{
235-
Serial.print("#P(");
236-
Serial.print(display.readBattery(), 2);
237-
Serial.println(")*");
238-
Serial.flush();
239-
}
240-
break;
52+
// Initialize Peripheral Mode (UART, display, buffer, etc.)
53+
if (!peripheral->begin(&Serial, &display, 115200ULL, SERIAL_UART_RX_PIN, SERIAL_UART_TX_PIN, SERIAL_BUFFER_SIZE))
54+
{
55+
// Send an error message to serial
56+
Serial.println("Peripheral Mode init failed!\nProgram halted!");
24157

242-
case 'S':
243-
sscanf(s + 3, "%d,%d,\"%149[^\"]\"", &x, &y, strTemp);
244-
n = strlen(strTemp);
245-
for (int i = 0; i < n; i++)
246-
{
247-
strTemp[i] = toupper(strTemp[i]);
248-
}
249-
for (int i = 0; i < n; i += 2)
250-
{
251-
strTemp[i / 2] = (hexToChar(strTemp[i]) << 4) | (hexToChar(strTemp[i + 1]) & 0x0F);
252-
}
253-
strTemp[n / 2] = 0;
254-
r = display.sdCardInit();
255-
if (r)
256-
{
257-
r = display.drawImage(strTemp, x, y);
258-
Serial.print("#H(");
259-
Serial.print(r, DEC);
260-
Serial.println(")*");
261-
Serial.flush();
262-
}
263-
else
264-
{
265-
Serial.println("#H(-1)*");
266-
Serial.flush();
267-
}
268-
break;
269-
case 'T':
270-
int t;
271-
sscanf(s + 3, "%d,%d,%d,%d,%d,%d", &x1, &y1, &x2, &y2, &c, &t);
272-
display.drawThickLine(x1, y1, x2, y2, c, t);
273-
break;
274-
case 'U':
275-
sscanf(s + 3, "%d,%d,%d,%d,%d", &rx, &ry, &xc, &yc, &c);
276-
display.drawElipse(rx, ry, xc, yc, c);
277-
break;
278-
case 'V':
279-
sscanf(s + 3, "%d,%d,%d,%d,%d", &rx, &ry, &xc, &yc, &c);
280-
display.fillElipse(rx, ry, xc, yc, c);
281-
break;
282-
}
283-
*s = 0;
284-
*e = 0;
285-
}
58+
// Stop program execution
59+
while (1);
28660
}
61+
62+
Serial.println("READY");
28763
}
28864

289-
int hexToChar(char c)
65+
void loop()
29066
{
291-
if (c >= '0' && c <= '9')
292-
return c - '0';
293-
if (c >= 'A' && c <= 'F')
294-
return c - 'A' + 10;
295-
if (c >= 'a' && c <= 'f')
296-
return c - 'a' + 10;
297-
return -1;
67+
// Check if there is incoming data on serial and process commands
68+
peripheral->getDataFromSerial(SERIAL_TIMEOUT_MS);
29869
}

0 commit comments

Comments
 (0)