Skip to content

Commit e534d92

Browse files
committed
Added IP4 Factory and Peripheral mode
1 parent 05c8af8 commit e534d92

File tree

9 files changed

+1745
-5
lines changed

9 files changed

+1745
-5
lines changed

examples/Inkplate4/Diagnostics/Inkplate4_Factory_Programming/Inkplate4_Factory_Programming.ino

Lines changed: 594 additions & 0 deletions
Large diffs are not rendered by default.
260 KB
Loading

examples/Inkplate4/Diagnostics/Inkplate4_Factory_Programming/image.h

Lines changed: 304 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
#include "test.h"
2+
3+
const char sdCardTestStringLength = 100;
4+
const char *testString = {"This is some test string..."};
5+
6+
const char *WSSID = {"Soldered"};
7+
const char *WPASS = {"dasduino"};
8+
9+
//const char *WSSID = {"Soldered-testingPurposes"};
10+
//const char *WPASS = {"Testing443"};
11+
12+
// Change this to your used slave device
13+
const uint8_t easyCDeviceAddress = 0x30;
14+
15+
void testPeripheral()
16+
{
17+
// Set display for test report
18+
// Send test reports to the UART (this epaper is slow and does not support partial update)
19+
Serial.println("INKPLATE CHECKLIST");
20+
21+
// Check I/O expander
22+
Serial.print("- I/O Expander: ");
23+
// Try to communicate with I/O expander
24+
Wire.beginTransmission(IO_INT_ADDR);
25+
if (Wire.endTransmission() == 0) // Check if there was an error in communication and print out the results on display.
26+
{
27+
Serial.println("OK");
28+
}
29+
else
30+
{
31+
Serial.println("FAIL");
32+
failHandler();
33+
}
34+
35+
// Check the micro SD card slot
36+
Serial.print("- microSD card slot: ");
37+
if (checkMicroSDCard())
38+
{
39+
Serial.println("OK");
40+
}
41+
else
42+
{
43+
Serial.println("FAIL");
44+
failHandler();
45+
}
46+
47+
// Check the WiFi
48+
Serial.print("- WiFi: ");
49+
if (checkWiFi(WSSID, WPASS, WTIMEOUT))
50+
{
51+
Serial.println("OK");
52+
}
53+
else
54+
{
55+
Serial.println("FAIL");
56+
failHandler();
57+
}
58+
59+
// First version of the Inkplate doesn't have RTC.
60+
61+
// Check the RTC
62+
Serial.print("- PCF85063 RTC: ");
63+
if (rtcCheck())
64+
{
65+
Serial.println("OK");
66+
}
67+
else
68+
{
69+
Serial.println("FAIL");
70+
failHandler();
71+
}
72+
73+
74+
// Check I2C (easyc)
75+
// A slave must be connected via easyC address set in the beginning of this file
76+
Serial.print("- I2C (easyC): ");
77+
if (checkI2C(easyCDeviceAddress))
78+
{
79+
Serial.println("OK");
80+
}
81+
else
82+
{
83+
Serial.println("FAIL");
84+
failHandler();
85+
}
86+
87+
// Check battery
88+
float batteryVoltage = 0.0;
89+
Serial.print("- Battery: ");
90+
if (checkBattery(&batteryVoltage))
91+
{
92+
Serial.print(batteryVoltage);
93+
Serial.print("V ");
94+
Serial.println("OK");
95+
}
96+
else
97+
{
98+
Serial.println("FAIL");
99+
failHandler();
100+
}
101+
102+
// Text wake up button
103+
long beginWakeUpTest = millis();
104+
int wakeButtonState = digitalRead(GPIO_NUM_36);
105+
106+
Serial.println("Press WAKEUP button within 30 seconds to finish testing...");
107+
while (true)
108+
{
109+
long now = millis();
110+
if (now - beginWakeUpTest > 30000)
111+
{
112+
Serial.println("WAKEUP not pressed for 30 seconds!");
113+
failHandler();
114+
}
115+
116+
if (digitalRead(GPIO_NUM_36) != wakeButtonState)
117+
{
118+
break;
119+
}
120+
delay(1);
121+
}
122+
Serial.println("WAKEUP button pressed!");
123+
}
124+
125+
int checkWiFi(const char *_ssid, const char *_pass, uint8_t _wifiTimeout)
126+
{
127+
unsigned long _timeout = millis();
128+
129+
// Try to connect to WiFi network
130+
WiFi.begin(WSSID, WPASS);
131+
132+
// Wait until WiFi connection is established or timeout has occured.
133+
while ((WiFi.status() != WL_CONNECTED) && ((unsigned long)(millis() - _timeout) < (_wifiTimeout * 1000UL)))
134+
;
135+
136+
// Check if board is connected to WiFi
137+
if (WiFi.status() == WL_CONNECTED)
138+
{
139+
return 1;
140+
}
141+
else
142+
{
143+
return 0;
144+
}
145+
146+
// Something is wrong if you got there.
147+
return 0;
148+
}
149+
150+
int checkMicroSDCard()
151+
{
152+
int sdInitOk = 0;
153+
sdInitOk = display.sdCardInit();
154+
155+
if (sdInitOk)
156+
{
157+
File file;
158+
159+
if (file.open("/testFile.txt", O_CREAT | O_RDWR))
160+
{
161+
file.print(testString);
162+
file.close();
163+
}
164+
else
165+
{
166+
return 0;
167+
}
168+
169+
delay(250);
170+
171+
if (file.open("/testFile.txt", O_RDWR))
172+
{
173+
char sdCardString[sdCardTestStringLength];
174+
file.read(sdCardString, sizeof(sdCardString));
175+
sdCardString[file.fileSize()] = 0;
176+
int stringCompare = strcmp(testString, sdCardString);
177+
file.remove();
178+
file.close();
179+
if (stringCompare != 0)
180+
return 0;
181+
}
182+
else
183+
{
184+
return 0;
185+
}
186+
}
187+
else
188+
{
189+
return 0;
190+
}
191+
return 1;
192+
}
193+
194+
int checkI2C(int address)
195+
{
196+
Wire.beginTransmission(address);
197+
if (Wire.endTransmission() == 0)
198+
{
199+
return 1;
200+
}
201+
else
202+
{
203+
return 0;
204+
}
205+
}
206+
207+
int checkBattery(float *batVoltage)
208+
{
209+
float voltage;
210+
voltage = display.readBattery();
211+
*batVoltage = voltage;
212+
213+
// Check the battery voltage.
214+
// If the measured voltage is below 2.8V and above 4.6V, charger is dead.
215+
if (voltage <= 2.8 || voltage >= 4.6)
216+
{
217+
return 0;
218+
}
219+
220+
return 1;
221+
}
222+
223+
int rtcCheck()
224+
{
225+
// First "ping" RTC on the I2C protocol and reset the RTC
226+
Wire.beginTransmission(0x51);
227+
int _res = Wire.endTransmission();
228+
229+
// If result is from I2C is anything else than success (_res = 0), return 0 (error).
230+
if (_res != 0)
231+
return 0;
232+
233+
// Reset and re-init RTC.
234+
display.rtcReset();
235+
236+
// Set some time in epoch in RTC.
237+
uint32_t _epoch = 1640995200ULL;
238+
display.rtcSetEpoch(_epoch);
239+
240+
// Wait at least one and a half second
241+
delay(1500);
242+
243+
// Read the epoch (if everything is ok, epoch from RTC should not be the same)
244+
if (display.rtcGetEpoch() != _epoch)
245+
{
246+
return 1;
247+
}
248+
else
249+
{
250+
return 0;
251+
}
252+
253+
return 0;
254+
}
255+
256+
// Show a message and stop the code from executing.
257+
void failHandler()
258+
{
259+
260+
Serial.println(" -> Test stopped!");
261+
262+
// Inf. loop... halt the program!
263+
while (true)
264+
delay(1000);
265+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef __TEST_H__
2+
#define __TEST_H__
3+
4+
#include <Arduino.h>
5+
#include "Inkplate.h"
6+
7+
// WiFi timeout in seconds.
8+
#define WTIMEOUT 10
9+
10+
// Timeoit for detecting touchpads in seconds (only on old Inkplates)
11+
#define TOUCHPADS_TIMEOUT 10
12+
13+
// Get Inkplate object from the main file.
14+
extern Inkplate display;
15+
16+
// By default, test both I/O expanders.
17+
void testPeripheral();
18+
double getVCOMFromSerial(double *_vcom);
19+
int checkWiFi(const char *_ssid, const char *_pass, uint8_t _wifiTimeout);
20+
int checkMicroSDCard();
21+
int rtcCheck();
22+
int checkI2C(int address);
23+
int checkBattery(float * batVoltage);
24+
void failHandler();
25+
26+
#endif

0 commit comments

Comments
 (0)