Skip to content

Commit f6ef4ce

Browse files
committed
Fixed a buffer overflow in Inkplate 10 example
#256 This still needs to be updated for all other Inkplate boards
1 parent 82e747a commit f6ef4ce

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

examples/Inkplate10/Projects/Inkplate10_Google_Calendar/Inkplate10_Google_Calendar.ino

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,29 @@ void setup()
107107
display.setTextColor(0, 7);
108108

109109
// Connect Inkplate to the WiFi network
110-
network.begin(ssid, pass);
110+
// Try connecting to a WiFi network.
111+
// Parameters are network SSID, password, timeout in seconds and whether to print to serial.
112+
// If the Inkplate isn't able to connect to a network stop further code execution and print an error message.
113+
if (!display.connectWiFi(ssid, pass, WIFI_TIMEOUT, true))
114+
{
115+
//Can't connect to netowrk
116+
// Clear display for the error message
117+
display.clearDisplay();
118+
// Set the font size;
119+
display.setTextSize(3);
120+
// Set the cursor positions and print the text.
121+
display.setCursor((display.width() / 2) - 200, display.height() / 2);
122+
display.print(F("Unable to connect to "));
123+
display.println(F(ssid));
124+
display.setCursor((display.width() / 2) - 200, (display.height() / 2) + 30);
125+
display.println(F("Please check SSID and PASS!"));
126+
// Display the error message on the Inkplate and go to deep sleep
127+
display.display();
128+
esp_sleep_enable_timer_wakeup(1000L * DELAY_MS);
129+
(void)esp_deep_sleep_start();
130+
}
131+
132+
setTime();
111133

112134
// Get the data from Google Calendar
113135
// Repeat attempts until data is fully downloaded
@@ -142,6 +164,26 @@ void loop()
142164
// Never here
143165
}
144166

167+
void setTime()
168+
{
169+
// Structure used to hold time information
170+
struct tm timeInfo;
171+
// Fetch current time from an NTP server and store it
172+
time_t nowSec;
173+
// Fetch current time in epoch format and store it
174+
display.getNTPEpoch(&nowSec);
175+
// This loop ensures that the NTP time fetched is valid and beyond a certain threshold
176+
while(nowSec < 8 * 3600 * 2)
177+
{
178+
delay(500);
179+
yield();
180+
display.getNTPEpoch(&nowSec);
181+
}
182+
gmtime_r(&nowSec, &timeInfo);
183+
Serial.print(F("Current time: "));
184+
Serial.print(asctime(&timeInfo));
185+
}
186+
145187
// Function for drawing calendar info
146188
void drawInfo()
147189
{
@@ -457,9 +499,14 @@ void drawData()
457499
getToFrom(entries[entriesNum].time, timeStart, timeEnd, &entries[entriesNum].day,
458500
&entries[entriesNum].timeStamp);
459501
}
502+
// Increment the counter
460503
++entriesNum;
504+
// If we're over the limit, exit the loading loop
505+
if(entriesNum == 128)
506+
{
507+
break;
508+
}
461509
}
462-
463510
// Sort entries by time
464511
qsort(entries, entriesNum, sizeof(entry), cmp);
465512

@@ -468,9 +515,11 @@ void drawData()
468515
bool clogged[3] = {0};
469516
int cloggedCount[3] = {0};
470517

518+
// If required, uncomment this line of debug if required, could be useful:
519+
//Serial.println("Displaying events one by one. There is " + String(entriesNum) + " events to display.");
471520
// Displaying events one by one
472521
for (int i = 0; i < entriesNum; ++i)
473-
{
522+
{
474523
// If column overflowed just add event to not shown
475524
if (entries[i].day != -1 && clogged[entries[i].day])
476525
++cloggedCount[entries[i].day];
@@ -480,7 +529,6 @@ void drawData()
480529
// We store how much height did one event take up
481530
int shift = 0;
482531
bool s = drawEvent(&entries[i], entries[i].day, columns[entries[i].day] + 64, 1200 - 4, &shift);
483-
484532
columns[entries[i].day] += shift;
485533

486534
// If it overflowed, set column to clogged and add one event as not shown
@@ -489,6 +537,7 @@ void drawData()
489537
++cloggedCount[entries[i].day];
490538
clogged[entries[i].day] = 1;
491539
}
540+
delay(100);
492541
}
493542

494543
// Display not shown events info

0 commit comments

Comments
 (0)