Skip to content

Commit

Permalink
Fixed a buffer overflow in Inkplate 10 example
Browse files Browse the repository at this point in the history
#256

This still needs to be updated for all other Inkplate boards
  • Loading branch information
rsoric committed Sep 3, 2024
1 parent 82e747a commit f6ef4ce
Showing 1 changed file with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,29 @@ void setup()
display.setTextColor(0, 7);

// Connect Inkplate to the WiFi network
network.begin(ssid, pass);
// Try connecting to a WiFi network.
// Parameters are network SSID, password, timeout in seconds and whether to print to serial.
// If the Inkplate isn't able to connect to a network stop further code execution and print an error message.
if (!display.connectWiFi(ssid, pass, WIFI_TIMEOUT, true))
{
//Can't connect to netowrk
// Clear display for the error message
display.clearDisplay();
// Set the font size;
display.setTextSize(3);
// Set the cursor positions and print the text.
display.setCursor((display.width() / 2) - 200, display.height() / 2);
display.print(F("Unable to connect to "));
display.println(F(ssid));
display.setCursor((display.width() / 2) - 200, (display.height() / 2) + 30);
display.println(F("Please check SSID and PASS!"));
// Display the error message on the Inkplate and go to deep sleep
display.display();
esp_sleep_enable_timer_wakeup(1000L * DELAY_MS);
(void)esp_deep_sleep_start();
}

setTime();

// Get the data from Google Calendar
// Repeat attempts until data is fully downloaded
Expand Down Expand Up @@ -142,6 +164,26 @@ void loop()
// Never here
}

void setTime()
{
// Structure used to hold time information
struct tm timeInfo;
// Fetch current time from an NTP server and store it
time_t nowSec;
// Fetch current time in epoch format and store it
display.getNTPEpoch(&nowSec);
// This loop ensures that the NTP time fetched is valid and beyond a certain threshold
while(nowSec < 8 * 3600 * 2)
{
delay(500);
yield();
display.getNTPEpoch(&nowSec);
}
gmtime_r(&nowSec, &timeInfo);
Serial.print(F("Current time: "));
Serial.print(asctime(&timeInfo));
}

// Function for drawing calendar info
void drawInfo()
{
Expand Down Expand Up @@ -457,9 +499,14 @@ void drawData()
getToFrom(entries[entriesNum].time, timeStart, timeEnd, &entries[entriesNum].day,
&entries[entriesNum].timeStamp);
}
// Increment the counter
++entriesNum;
// If we're over the limit, exit the loading loop
if(entriesNum == 128)
{
break;
}
}

// Sort entries by time
qsort(entries, entriesNum, sizeof(entry), cmp);

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

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

columns[entries[i].day] += shift;

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

// Display not shown events info
Expand Down

0 comments on commit f6ef4ce

Please sign in to comment.