Skip to content

Commit

Permalink
error: partial update for error & multiple tries
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgreg committed Apr 13, 2021
1 parent f39e53f commit f557db5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
20 changes: 10 additions & 10 deletions display.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,20 @@ void displayWeather(Weather* weather) {
} while (display.nextPage());
}

void displayCenteredText(char* text) {
void displayError(char* text) {
int x = 0;
int y = display.height() - 20;
int w = display.width() / 2;
int h = 20;
display.setFont(&FONT_SMALL);
display.setTextColor(GxEPD_BLACK);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh);
uint16_t x = ((display.width() - tbw) / 2) - tbx;
uint16_t y = ((display.height() - tbh) / 2) - tby;
display.setFullWindow();
display.setTextColor(GxEPD_RED);

display.setPartialWindow(x, y, w, h);
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
display.setCursor(x, y);
display.setCursor(x + 5, y + 12);
display.print(text);
}
while (display.nextPage());
} while (display.nextPage());
}
13 changes: 9 additions & 4 deletions esp32-weather-station.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ void loop() {
uint64_t sleepTime = HOUR;

if (!connectToWifi()) {
displayCenteredText("Can't connect to wifi");
} else {
boolean jsonParsed = getJSON(URL);
displayError("Error : WIFI");
} else {
unsigned int retries = 5;
boolean jsonParsed = false;
while(!jsonParsed && (retries-- > 0)) {
delay(1000);
jsonParsed = getJSON(URL);
}
if (!jsonParsed) {
displayCenteredText("Error getting JSON");
displayError("Error : JSON");
} else {
Weather weather;
fillWeatherFromJson(&weather);
Expand Down

0 comments on commit f557db5

Please sign in to comment.