From 22f886a10a44c10d73df68cb0b1651be1ca6c148 Mon Sep 17 00:00:00 2001 From: Luke Marzen <98473324+lmarzen@users.noreply.github.com> Date: Fri, 16 Feb 2024 16:52:16 -0600 Subject: [PATCH] improved language translation support --- platformio/include/_locale.h | 39 +++++++++++++++- platformio/include/renderer.h | 2 +- platformio/src/client_utils.cpp | 14 +++--- platformio/src/display_utils.cpp | 16 +++---- platformio/src/locales/locale_de_DE.inc | 40 ++++++++++++++++- platformio/src/locales/locale_en_GB.inc | 38 +++++++++++++++- platformio/src/locales/locale_en_US.inc | 38 +++++++++++++++- platformio/src/locales/locale_fr_FR.inc | 38 +++++++++++++++- platformio/src/locales/locale_nl_BE.inc | 40 ++++++++++++++++- platformio/src/main.cpp | 60 +++++++++++++------------ platformio/src/renderer.cpp | 24 +++++++--- 11 files changed, 291 insertions(+), 58 deletions(-) diff --git a/platformio/include/_locale.h b/platformio/include/_locale.h index 4ebc99f25..cc1024d57 100644 --- a/platformio/include/_locale.h +++ b/platformio/include/_locale.h @@ -91,8 +91,34 @@ extern const char *TXT_UNITS_PRES_POUNDSPERSQUAREINCH; extern const char *TXT_UNITS_DIST_KILOMETERS; extern const char *TXT_UNITS_DIST_MILES; -// LAST REFRESH +// MISCELLANEOUS MESSAGES +// Title Case +extern const char *TXT_LOW_BATTERY; +extern const char *TXT_NETWORK_NOT_AVAILABLE; +extern const char *TXT_TIME_SYNCHRONIZATION_FAILED; +extern const char *TXT_WIFI_CONNECTION_FAILED; +// First Word Capitalized +extern const char *TXT_ATTEMPTING_HTTP_REQ; +extern const char *TXT_AWAKE_FOR; +extern const char *TXT_BATTERY_VOLTAGE; +extern const char *TXT_CONNECTING_TO; +extern const char *TXT_COULD_NOT_CONNECT_TO; +extern const char *TXT_ENTERING_DEEP_SLEEP_FOR; +extern const char *TXT_READING_FROM; +extern const char *TXT_FAILED; +extern const char *TXT_SUCCESS; extern const char *TXT_UNKNOWN; +// All Lowercase +extern const char *TXT_NOT_FOUND; +extern const char *TXT_READ_FAILED; +// Complete +extern const char *TXT_FAILED_TO_GET_TIME; +extern const char *TXT_HIBERNATING_INDEFINITELY_NOTICE; +extern const char *TXT_REFERENCING_OLDER_TIME_NOTICE; +extern const char *TXT_WAITING_FOR_SNTP; +extern const char *TXT_LOW_BATTERY_VOLTAGE; +extern const char *TXT_VERY_LOW_BATTERY_VOLTAGE; +extern const char *TXT_CRIT_LOW_BATTERY_VOLTAGE; // ALERTS extern const std::vector ALERT_URGENCY; @@ -229,4 +255,15 @@ extern const char *TXT_DESERIALIZATION_ERROR_INVALID_INPUT; extern const char *TXT_DESERIALIZATION_ERROR_NO_MEMORY; extern const char *TXT_DESERIALIZATION_ERROR_TOO_DEEP; +// WIFI STATUS +extern const char *TXT_WL_NO_SHIELD; +extern const char *TXT_WL_IDLE_STATUS; +extern const char *TXT_WL_NO_SSID_AVAIL; +extern const char *TXT_WL_SCAN_COMPLETED; +extern const char *TXT_WL_CONNECTED; +extern const char *TXT_WL_CONNECT_FAILED; +extern const char *TXT_WL_CONNECTION_LOST; +extern const char *TXT_WL_DISCONNECTED; + + #endif diff --git a/platformio/include/renderer.h b/platformio/include/renderer.h index 16743930f..3408ed819 100644 --- a/platformio/include/renderer.h +++ b/platformio/include/renderer.h @@ -82,6 +82,6 @@ void drawOutlookGraph(owm_hourly_t *const hourly, tm timeInfo); void drawStatusBar(const String &statusStr, const String &refreshTimeStr, int rssi, double batVoltage); void drawError(const uint8_t *bitmap_196x196, - const String &errMsgLn1, const String &errMsgLn2); + const String &errMsgLn1, const String &errMsgLn2=""); #endif diff --git a/platformio/src/client_utils.cpp b/platformio/src/client_utils.cpp index aab16f8a6..948aff2bb 100644 --- a/platformio/src/client_utils.cpp +++ b/platformio/src/client_utils.cpp @@ -58,7 +58,7 @@ wl_status_t startWiFi(int &wifiRSSI) { WiFi.mode(WIFI_STA); - Serial.printf("Connecting to '%s'", WIFI_SSID); + Serial.printf("%s '%s'", TXT_CONNECTING_TO, WIFI_SSID); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // timeout if WiFi does not connect in WIFI_TIMEOUT ms from now @@ -81,7 +81,7 @@ wl_status_t startWiFi(int &wifiRSSI) } else { - Serial.printf("Could not connect to '%s'\n", WIFI_SSID); + Serial.printf("%s '%s'\n", TXT_COULD_NOT_CONNECT_TO, WIFI_SSID); } return connection_status; } // startWiFi @@ -103,7 +103,7 @@ bool printLocalTime(tm *timeInfo) int attempts = 0; while (!getLocalTime(timeInfo) && attempts++ < 3) { - Serial.println("Failed to obtain time"); + Serial.println(TXT_FAILED_TO_GET_TIME); return false; } Serial.println(timeInfo, "%A, %B %d, %Y %H:%M:%S"); @@ -124,7 +124,7 @@ bool waitForSNTPSync(tm *timeInfo) if ((sntp_get_sync_status() == SNTP_SYNC_STATUS_RESET) && (millis() < timeout)) { - Serial.print("Waiting for SNTP synchronization."); + Serial.print(TXT_WAITING_FOR_SNTP); delay(100); // ms while ((sntp_get_sync_status() == SNTP_SYNC_STATUS_RESET) && (millis() < timeout)) @@ -166,7 +166,8 @@ bool waitForSNTPSync(tm *timeInfo) uri += "&appid=" + OWM_APIKEY; - Serial.println("Attempting HTTP Request: " + sanitizedUri); + Serial.print(TXT_ATTEMPTING_HTTP_REQ); + Serial.println(": " + sanitizedUri); int httpResponse = 0; while (!rxSuccess && attempts < 3) { @@ -230,7 +231,8 @@ bool waitForSNTPSync(tm *timeInfo) + "&start=" + startStr + "&end=" + endStr + "&appid={API key}"; - Serial.println("Attempting HTTP Request: " + sanitizedUri); + Serial.print(TXT_ATTEMPTING_HTTP_REQ); + Serial.println(": " + sanitizedUri); int httpResponse = 0; while (!rxSuccess && attempts < 3) { diff --git a/platformio/src/display_utils.cpp b/platformio/src/display_utils.cpp index 6a514aaf2..3cdcc0f41 100644 --- a/platformio/src/display_utils.cpp +++ b/platformio/src/display_utils.cpp @@ -1684,14 +1684,14 @@ const char *getWifiStatusPhrase(wl_status_t status) { switch (status) { - case WL_NO_SHIELD: return "No Shield"; - case WL_IDLE_STATUS: return "Idle"; - case WL_NO_SSID_AVAIL: return "No SSID Available"; - case WL_SCAN_COMPLETED: return "Scan Complete"; - case WL_CONNECTED: return "Connected"; - case WL_CONNECT_FAILED: return "Connection Failed"; - case WL_CONNECTION_LOST: return "Connection Lost"; - case WL_DISCONNECTED: return "Disconnected"; + case WL_NO_SHIELD: return TXT_WL_NO_SHIELD; + case WL_IDLE_STATUS: return TXT_WL_IDLE_STATUS; + case WL_NO_SSID_AVAIL: return TXT_WL_NO_SSID_AVAIL; + case WL_SCAN_COMPLETED: return TXT_WL_SCAN_COMPLETED; + case WL_CONNECTED: return TXT_WL_CONNECTED; + case WL_CONNECT_FAILED: return TXT_WL_CONNECT_FAILED; + case WL_CONNECTION_LOST: return TXT_WL_CONNECTION_LOST; + case WL_DISCONNECTED: return TXT_WL_DISCONNECTED; default: return ""; } diff --git a/platformio/src/locales/locale_de_DE.inc b/platformio/src/locales/locale_de_DE.inc index 83861d478..ca5a86a90 100644 --- a/platformio/src/locales/locale_de_DE.inc +++ b/platformio/src/locales/locale_de_DE.inc @@ -128,8 +128,34 @@ const char *TXT_UNITS_PRES_POUNDSPERSQUAREINCH = "lb/in\xB2"; const char *TXT_UNITS_DIST_KILOMETERS = "km"; const char *TXT_UNITS_DIST_MILES = "mi"; -// LAST REFRESH -const char *TXT_UNKNOWN = "Unbekannt"; +// MISCELLANEOUS MESSAGES +// Title Case +const char *TXT_LOW_BATTERY = "Low Battery"; +const char *TXT_NETWORK_NOT_AVAILABLE = "Network Not Available"; +const char *TXT_TIME_SYNCHRONIZATION_FAILED = "Time Synchronization Failed"; +const char *TXT_WIFI_CONNECTION_FAILED = "WiFi Connection Failed"; +// First Word Capitalized +const char *TXT_ATTEMPTING_HTTP_REQ = "Attempting HTTP request"; +const char *TXT_AWAKE_FOR = "Awake for"; +const char *TXT_BATTERY_VOLTAGE = "Battery voltage"; +const char *TXT_CONNECTING_TO = "Connecting to"; +const char *TXT_COULD_NOT_CONNECT_TO = "Could not connect to"; +const char *TXT_ENTERING_DEEP_SLEEP_FOR = "Entering deep sleep for"; +const char *TXT_READING_FROM = "Reading from"; +const char *TXT_FAILED = "Failed"; +const char *TXT_SUCCESS = "Success"; +const char *TXT_UNKNOWN = "Unknown"; +// All Lowercase +const char *TXT_NOT_FOUND = "not found"; +const char *TXT_READ_FAILED = "read failed"; +// Complete Sentences +const char *TXT_FAILED_TO_GET_TIME = "Failed to get the time!"; +const char *TXT_HIBERNATING_INDEFINITELY_NOTICE = "Hibernating without wake time!"; +const char *TXT_REFERENCING_OLDER_TIME_NOTICE = "Failed to syncronize time before deep-sleep, referencing older time."; +const char *TXT_WAITING_FOR_SNTP = "Waiting for SNTP synchronization."; +const char *TXT_LOW_BATTERY_VOLTAGE = "Low battery voltage!"; +const char *TXT_VERY_LOW_BATTERY_VOLTAGE = "Very low battery voltage!"; +const char *TXT_CRIT_LOW_BATTERY_VOLTAGE = "Critically low battery voltage!"; // ALERTS // The display can show up to 2 alerts, but alerts can be unpredictible in @@ -396,3 +422,13 @@ const char *TXT_DESERIALIZATION_ERROR_INCOMPLETE_INPUT = "Deserialization Incomp const char *TXT_DESERIALIZATION_ERROR_INVALID_INPUT = "Deserialization Invalid Input"; const char *TXT_DESERIALIZATION_ERROR_NO_MEMORY = "Deserialization No Memory"; const char *TXT_DESERIALIZATION_ERROR_TOO_DEEP = "Deserialization Too Deep"; + +// WIFI STATUS +const char *TXT_WL_NO_SHIELD = "No Shield"; +const char *TXT_WL_IDLE_STATUS = "Idle"; +const char *TXT_WL_NO_SSID_AVAIL = "No SSID Available"; +const char *TXT_WL_SCAN_COMPLETED = "Scan Complete"; +const char *TXT_WL_CONNECTED = "Connected"; +const char *TXT_WL_CONNECT_FAILED = "Connection Failed"; +const char *TXT_WL_CONNECTION_LOST = "Connection Lost"; +const char *TXT_WL_DISCONNECTED = "Disconnected"; diff --git a/platformio/src/locales/locale_en_GB.inc b/platformio/src/locales/locale_en_GB.inc index edd04fed8..02fa8d249 100644 --- a/platformio/src/locales/locale_en_GB.inc +++ b/platformio/src/locales/locale_en_GB.inc @@ -120,8 +120,34 @@ const char *TXT_UNITS_PRES_POUNDSPERSQUAREINCH = "lb/in\xB2"; const char *TXT_UNITS_DIST_KILOMETERS = "km"; const char *TXT_UNITS_DIST_MILES = "mi"; -// LAST REFRESH +// MISCELLANEOUS MESSAGES +// Title Case +const char *TXT_LOW_BATTERY = "Low Battery"; +const char *TXT_NETWORK_NOT_AVAILABLE = "Network Not Available"; +const char *TXT_TIME_SYNCHRONIZATION_FAILED = "Time Synchronization Failed"; +const char *TXT_WIFI_CONNECTION_FAILED = "WiFi Connection Failed"; +// First Word Capitalized +const char *TXT_ATTEMPTING_HTTP_REQ = "Attempting HTTP request"; +const char *TXT_AWAKE_FOR = "Awake for"; +const char *TXT_BATTERY_VOLTAGE = "Battery voltage"; +const char *TXT_CONNECTING_TO = "Connecting to"; +const char *TXT_COULD_NOT_CONNECT_TO = "Could not connect to"; +const char *TXT_ENTERING_DEEP_SLEEP_FOR = "Entering deep sleep for"; +const char *TXT_READING_FROM = "Reading from"; +const char *TXT_FAILED = "Failed"; +const char *TXT_SUCCESS = "Success"; const char *TXT_UNKNOWN = "Unknown"; +// All Lowercase +const char *TXT_NOT_FOUND = "not found"; +const char *TXT_READ_FAILED = "read failed"; +// Complete Sentences +const char *TXT_FAILED_TO_GET_TIME = "Failed to get the time!"; +const char *TXT_HIBERNATING_INDEFINITELY_NOTICE = "Hibernating without wake time!"; +const char *TXT_REFERENCING_OLDER_TIME_NOTICE = "Failed to syncronize time before deep-sleep, referencing older time."; +const char *TXT_WAITING_FOR_SNTP = "Waiting for SNTP synchronization."; +const char *TXT_LOW_BATTERY_VOLTAGE = "Low battery voltage!"; +const char *TXT_VERY_LOW_BATTERY_VOLTAGE = "Very low battery voltage!"; +const char *TXT_CRIT_LOW_BATTERY_VOLTAGE = "Critically low battery voltage!"; // ALERTS // The display can show up to 2 alerts, but alerts can be unpredictible in @@ -388,3 +414,13 @@ const char *TXT_DESERIALIZATION_ERROR_INCOMPLETE_INPUT = "Deserialization Incomp const char *TXT_DESERIALIZATION_ERROR_INVALID_INPUT = "Deserialization Invalid Input"; const char *TXT_DESERIALIZATION_ERROR_NO_MEMORY = "Deserialization No Memory"; const char *TXT_DESERIALIZATION_ERROR_TOO_DEEP = "Deserialization Too Deep"; + +// WIFI STATUS +const char *TXT_WL_NO_SHIELD = "No Shield"; +const char *TXT_WL_IDLE_STATUS = "Idle"; +const char *TXT_WL_NO_SSID_AVAIL = "No SSID Available"; +const char *TXT_WL_SCAN_COMPLETED = "Scan Complete"; +const char *TXT_WL_CONNECTED = "Connected"; +const char *TXT_WL_CONNECT_FAILED = "Connection Failed"; +const char *TXT_WL_CONNECTION_LOST = "Connection Lost"; +const char *TXT_WL_DISCONNECTED = "Disconnected"; diff --git a/platformio/src/locales/locale_en_US.inc b/platformio/src/locales/locale_en_US.inc index 27416701b..4c262bbad 100644 --- a/platformio/src/locales/locale_en_US.inc +++ b/platformio/src/locales/locale_en_US.inc @@ -120,8 +120,34 @@ const char *TXT_UNITS_PRES_POUNDSPERSQUAREINCH = "lb/in\xB2"; const char *TXT_UNITS_DIST_KILOMETERS = "km"; const char *TXT_UNITS_DIST_MILES = "mi"; -// LAST REFRESH +// MISCELLANEOUS MESSAGES +// Title Case +const char *TXT_LOW_BATTERY = "Low Battery"; +const char *TXT_NETWORK_NOT_AVAILABLE = "Network Not Available"; +const char *TXT_TIME_SYNCHRONIZATION_FAILED = "Time Synchronization Failed"; +const char *TXT_WIFI_CONNECTION_FAILED = "WiFi Connection Failed"; +// First Word Capitalized +const char *TXT_ATTEMPTING_HTTP_REQ = "Attempting HTTP request"; +const char *TXT_AWAKE_FOR = "Awake for"; +const char *TXT_BATTERY_VOLTAGE = "Battery voltage"; +const char *TXT_CONNECTING_TO = "Connecting to"; +const char *TXT_COULD_NOT_CONNECT_TO = "Could not connect to"; +const char *TXT_ENTERING_DEEP_SLEEP_FOR = "Entering deep sleep for"; +const char *TXT_READING_FROM = "Reading from"; +const char *TXT_FAILED = "Failed"; +const char *TXT_SUCCESS = "Success"; const char *TXT_UNKNOWN = "Unknown"; +// All Lowercase +const char *TXT_NOT_FOUND = "not found"; +const char *TXT_READ_FAILED = "read failed"; +// Complete Sentences +const char *TXT_FAILED_TO_GET_TIME = "Failed to get the time!"; +const char *TXT_HIBERNATING_INDEFINITELY_NOTICE = "Hibernating without wake time!"; +const char *TXT_REFERENCING_OLDER_TIME_NOTICE = "Failed to syncronize time before deep-sleep, referencing older time."; +const char *TXT_WAITING_FOR_SNTP = "Waiting for SNTP synchronization."; +const char *TXT_LOW_BATTERY_VOLTAGE = "Low battery voltage!"; +const char *TXT_VERY_LOW_BATTERY_VOLTAGE = "Very low battery voltage!"; +const char *TXT_CRIT_LOW_BATTERY_VOLTAGE = "Critically low battery voltage!"; // ALERTS // The display can show up to 2 alerts, but alerts can be unpredictible in @@ -388,3 +414,13 @@ const char *TXT_DESERIALIZATION_ERROR_INCOMPLETE_INPUT = "Deserialization Incomp const char *TXT_DESERIALIZATION_ERROR_INVALID_INPUT = "Deserialization Invalid Input"; const char *TXT_DESERIALIZATION_ERROR_NO_MEMORY = "Deserialization No Memory"; const char *TXT_DESERIALIZATION_ERROR_TOO_DEEP = "Deserialization Too Deep"; + +// WIFI STATUS +const char *TXT_WL_NO_SHIELD = "No Shield"; +const char *TXT_WL_IDLE_STATUS = "Idle"; +const char *TXT_WL_NO_SSID_AVAIL = "No SSID Available"; +const char *TXT_WL_SCAN_COMPLETED = "Scan Complete"; +const char *TXT_WL_CONNECTED = "Connected"; +const char *TXT_WL_CONNECT_FAILED = "Connection Failed"; +const char *TXT_WL_CONNECTION_LOST = "Connection Lost"; +const char *TXT_WL_DISCONNECTED = "Disconnected"; diff --git a/platformio/src/locales/locale_fr_FR.inc b/platformio/src/locales/locale_fr_FR.inc index 805cc8c28..e54527d5f 100644 --- a/platformio/src/locales/locale_fr_FR.inc +++ b/platformio/src/locales/locale_fr_FR.inc @@ -128,8 +128,34 @@ const char *TXT_UNITS_PRES_POUNDSPERSQUAREINCH = "lb/in\xB2"; const char *TXT_UNITS_DIST_KILOMETERS = "km"; const char *TXT_UNITS_DIST_MILES = "mi"; -// LAST REFRESH +// MISCELLANEOUS MESSAGES +// Title Case +const char *TXT_LOW_BATTERY = "Low Battery"; +const char *TXT_NETWORK_NOT_AVAILABLE = "Network Not Available"; +const char *TXT_TIME_SYNCHRONIZATION_FAILED = "Time Synchronization Failed"; +const char *TXT_WIFI_CONNECTION_FAILED = "WiFi Connection Failed"; +// First Word Capitalized +const char *TXT_ATTEMPTING_HTTP_REQ = "Attempting HTTP request"; +const char *TXT_AWAKE_FOR = "Awake for"; +const char *TXT_BATTERY_VOLTAGE = "Battery voltage"; +const char *TXT_CONNECTING_TO = "Connecting to"; +const char *TXT_COULD_NOT_CONNECT_TO = "Could not connect to"; +const char *TXT_ENTERING_DEEP_SLEEP_FOR = "Entering deep sleep for"; +const char *TXT_READING_FROM = "Reading from"; +const char *TXT_FAILED = "Failed"; +const char *TXT_SUCCESS = "Success"; const char *TXT_UNKNOWN = "Unknown"; +// All Lowercase +const char *TXT_NOT_FOUND = "not found"; +const char *TXT_READ_FAILED = "read failed"; +// Complete Sentences +const char *TXT_FAILED_TO_GET_TIME = "Failed to get the time!"; +const char *TXT_HIBERNATING_INDEFINITELY_NOTICE = "Hibernating without wake time!"; +const char *TXT_REFERENCING_OLDER_TIME_NOTICE = "Failed to syncronize time before deep-sleep, referencing older time."; +const char *TXT_WAITING_FOR_SNTP = "Waiting for SNTP synchronization."; +const char *TXT_LOW_BATTERY_VOLTAGE = "Low battery voltage!"; +const char *TXT_VERY_LOW_BATTERY_VOLTAGE = "Very low battery voltage!"; +const char *TXT_CRIT_LOW_BATTERY_VOLTAGE = "Critically low battery voltage!"; // ALERTS // The display can show up to 2 alerts, but alerts can be unpredictible in @@ -396,3 +422,13 @@ const char *TXT_DESERIALIZATION_ERROR_INCOMPLETE_INPUT = "Deserialization Incomp const char *TXT_DESERIALIZATION_ERROR_INVALID_INPUT = "Deserialization Invalid Input"; const char *TXT_DESERIALIZATION_ERROR_NO_MEMORY = "Deserialization No Memory"; const char *TXT_DESERIALIZATION_ERROR_TOO_DEEP = "Deserialization Too Deep"; + +// WIFI STATUS +const char *TXT_WL_NO_SHIELD = "No Shield"; +const char *TXT_WL_IDLE_STATUS = "Idle"; +const char *TXT_WL_NO_SSID_AVAIL = "No SSID Available"; +const char *TXT_WL_SCAN_COMPLETED = "Scan Complete"; +const char *TXT_WL_CONNECTED = "Connected"; +const char *TXT_WL_CONNECT_FAILED = "Connection Failed"; +const char *TXT_WL_CONNECTION_LOST = "Connection Lost"; +const char *TXT_WL_DISCONNECTED = "Disconnected"; diff --git a/platformio/src/locales/locale_nl_BE.inc b/platformio/src/locales/locale_nl_BE.inc index 18b79d9c6..59bf70954 100644 --- a/platformio/src/locales/locale_nl_BE.inc +++ b/platformio/src/locales/locale_nl_BE.inc @@ -127,8 +127,34 @@ const char *TXT_UNITS_PRES_POUNDSPERSQUAREINCH = "lb/in\xB2"; const char *TXT_UNITS_DIST_KILOMETERS = "km"; const char *TXT_UNITS_DIST_MILES = "mi"; -// LAST REFRESH -const char *TXT_UNKNOWN = "Onbekend"; +// MISCELLANEOUS MESSAGES +// Title Case +const char *TXT_LOW_BATTERY = "Low Battery"; +const char *TXT_NETWORK_NOT_AVAILABLE = "Network Not Available"; +const char *TXT_TIME_SYNCHRONIZATION_FAILED = "Time Synchronization Failed"; +const char *TXT_WIFI_CONNECTION_FAILED = "WiFi Connection Failed"; +// First Word Capitalized +const char *TXT_ATTEMPTING_HTTP_REQ = "Attempting HTTP request"; +const char *TXT_AWAKE_FOR = "Awake for"; +const char *TXT_BATTERY_VOLTAGE = "Battery voltage"; +const char *TXT_CONNECTING_TO = "Connecting to"; +const char *TXT_COULD_NOT_CONNECT_TO = "Could not connect to"; +const char *TXT_ENTERING_DEEP_SLEEP_FOR = "Entering deep sleep for"; +const char *TXT_READING_FROM = "Reading from"; +const char *TXT_FAILED = "Failed"; +const char *TXT_SUCCESS = "Success"; +const char *TXT_UNKNOWN = "Unknown"; +// All Lowercase +const char *TXT_NOT_FOUND = "not found"; +const char *TXT_READ_FAILED = "read failed"; +// Complete Sentences +const char *TXT_FAILED_TO_GET_TIME = "Failed to get the time!"; +const char *TXT_HIBERNATING_INDEFINITELY_NOTICE = "Hibernating without wake time!"; +const char *TXT_REFERENCING_OLDER_TIME_NOTICE = "Failed to syncronize time before deep-sleep, referencing older time."; +const char *TXT_WAITING_FOR_SNTP = "Waiting for SNTP synchronization."; +const char *TXT_LOW_BATTERY_VOLTAGE = "Low battery voltage!"; +const char *TXT_VERY_LOW_BATTERY_VOLTAGE = "Very low battery voltage!"; +const char *TXT_CRIT_LOW_BATTERY_VOLTAGE = "Critically low battery voltage!"; // ALERTS // The display can show up to 2 alerts, but alerts can be unpredictible in @@ -395,3 +421,13 @@ const char *TXT_DESERIALIZATION_ERROR_INCOMPLETE_INPUT = "Deserialization Incomp const char *TXT_DESERIALIZATION_ERROR_INVALID_INPUT = "Deserialization Invalid Input"; const char *TXT_DESERIALIZATION_ERROR_NO_MEMORY = "Deserialization No Memory"; const char *TXT_DESERIALIZATION_ERROR_TOO_DEEP = "Deserialization Too Deep"; + +// WIFI STATUS +const char *TXT_WL_NO_SHIELD = "No Shield"; +const char *TXT_WL_IDLE_STATUS = "Idle"; +const char *TXT_WL_NO_SSID_AVAIL = "No SSID Available"; +const char *TXT_WL_SCAN_COMPLETED = "Scan Complete"; +const char *TXT_WL_CONNECTED = "Connected"; +const char *TXT_WL_CONNECT_FAILED = "Connection Failed"; +const char *TXT_WL_CONNECTION_LOST = "Connection Lost"; +const char *TXT_WL_DISCONNECTED = "Disconnected"; diff --git a/platformio/src/main.cpp b/platformio/src/main.cpp index 1ab3cd869..ea3342495 100644 --- a/platformio/src/main.cpp +++ b/platformio/src/main.cpp @@ -24,6 +24,7 @@ #include #include +#include "_locale.h" #include "api_response.h" #include "client_utils.h" #include "config.h" @@ -43,15 +44,14 @@ static owm_resp_air_pollution_t owm_air_pollution; Preferences prefs; -/* Put esp32 into ultra low-power deep-sleep (<11μA). +/* Put esp32 into ultra low-power deep sleep (<11μA). * Aligns wake time to the minute. Sleep times defined in config.cpp. */ void beginDeepSleep(unsigned long &startTime, tm *timeInfo) { if (!getLocalTime(timeInfo)) { - Serial.println("Failed to obtain time before deep-sleep, referencing " \ - "older time."); + Serial.println(TXT_REFERENCING_OLDER_TIME_NOTICE); } uint64_t sleepDuration = 0; @@ -111,9 +111,10 @@ void beginDeepSleep(unsigned long &startTime, tm *timeInfo) #endif esp_sleep_enable_timer_wakeup(sleepDuration * 1000000ULL); - Serial.println("Awake for " - + String((millis() - startTime) / 1000.0, 3) + "s"); - Serial.println("Deep-sleep for " + String(sleepDuration) + "s"); + Serial.print(TXT_AWAKE_FOR); + Serial.println(" " + String((millis() - startTime) / 1000.0, 3) + "s"); + Serial.print(TXT_ENTERING_DEEP_SLEEP_FOR); + Serial.println(" " + String(sleepDuration) + "s"); esp_deep_sleep_start(); } // end beginDeepSleep @@ -143,7 +144,8 @@ void setup() double batteryVoltage = static_cast(batADC) / 1000.0 * (3.5 / 2.0); // use / 1000.0 * (3.3 / 2.0) multiplier above for firebeetle esp32 // use / 1000.0 * (3.5 / 2.0) for firebeetle esp32-E - Serial.println("Battery voltage: " + String(batteryVoltage, 2)); + Serial.print(TXT_BATTERY_VOLTAGE); + Serial.println(": " + String(batteryVoltage, 2)); // When the battery is low, the display should be updated to reflect that, but // only the first time we detect low voltage. The next time the display will @@ -151,7 +153,7 @@ void setup() // make use of non-volatile storage. bool lowBat = prefs.getBool("lowBat", false); - // low battery, deep-sleep now + // low battery, deep sleep now if (batteryVoltage <= LOW_BATTERY_VOLTAGE) { if (lowBat == false) @@ -161,7 +163,7 @@ void setup() initDisplay(); do { - drawError(battery_alert_0deg_196x196, "Low Battery", ""); + drawError(battery_alert_0deg_196x196, TXT_LOW_BATTERY); } while (display.nextPage()); powerOffDisplay(); } @@ -170,24 +172,24 @@ void setup() { // critically low battery // don't set esp_sleep_enable_timer_wakeup(); // We won't wake up again until someone manually presses the RST button. - Serial.println("Critically low battery voltage!"); - Serial.println("Hibernating without wake time!"); + Serial.println(TXT_CRIT_LOW_BATTERY_VOLTAGE); + Serial.println(TXT_HIBERNATING_INDEFINITELY_NOTICE); } else if (batteryVoltage <= VERY_LOW_BATTERY_VOLTAGE) { // very low battery esp_sleep_enable_timer_wakeup(VERY_LOW_BATTERY_SLEEP_INTERVAL * 60ULL * 1000000ULL); - Serial.println("Very low battery voltage!"); - Serial.println("Deep-sleep for " - + String(VERY_LOW_BATTERY_SLEEP_INTERVAL) + "min"); + Serial.println(TXT_VERY_LOW_BATTERY_VOLTAGE); + Serial.print(TXT_ENTERING_DEEP_SLEEP_FOR); + Serial.println(" " + String(VERY_LOW_BATTERY_SLEEP_INTERVAL) + "min"); } else { // low battery esp_sleep_enable_timer_wakeup(LOW_BATTERY_SLEEP_INTERVAL * 60ULL * 1000000ULL); - Serial.println("Low battery voltage!"); - Serial.println("Deep-sleep for " - + String(LOW_BATTERY_SLEEP_INTERVAL) + "min"); + Serial.println(TXT_LOW_BATTERY_VOLTAGE); + Serial.print(TXT_ENTERING_DEEP_SLEEP_FOR); + Serial.println(" " + String(LOW_BATTERY_SLEEP_INTERVAL) + "min"); } esp_deep_sleep_start(); } @@ -216,18 +218,18 @@ void setup() initDisplay(); if (wifiStatus == WL_NO_SSID_AVAIL) { - Serial.println("Network Not Available"); + Serial.println(TXT_NETWORK_NOT_AVAILABLE); do { - drawError(wifi_x_196x196, "Network Not", "Available"); + drawError(wifi_x_196x196, TXT_NETWORK_NOT_AVAILABLE); } while (display.nextPage()); } else { - Serial.println("WiFi Connection Failed"); + Serial.println(TXT_WIFI_CONNECTION_FAILED); do { - drawError(wifi_x_196x196, "WiFi Connection", "Failed"); + drawError(wifi_x_196x196, TXT_WIFI_CONNECTION_FAILED); } while (display.nextPage()); } powerOffDisplay(); @@ -238,13 +240,13 @@ void setup() configTzTime(TIMEZONE, NTP_SERVER_1, NTP_SERVER_2); bool timeConfigured = waitForSNTPSync(&timeInfo); if (!timeConfigured) - { // Failed To Fetch The Time - Serial.println("Time Synchronization Failed"); + { + Serial.println(TXT_TIME_SYNCHRONIZATION_FAILED); killWiFi(); initDisplay(); do { - drawError(wi_time_4_196x196, "Time Synchronization", "Failed"); + drawError(wi_time_4_196x196, TXT_TIME_SYNCHRONIZATION_FAILED); } while (display.nextPage()); powerOffDisplay(); beginDeepSleep(startTime, &timeInfo); @@ -295,7 +297,7 @@ void setup() digitalWrite(PIN_BME_PWR, HIGH); float inTemp = NAN; float inHumidity = NAN; - Serial.print("Reading from BME280... "); + Serial.print(String(TXT_READING_FROM) + " BME280... "); TwoWire I2C_bme = TwoWire(0); Adafruit_BME280 bme; @@ -311,17 +313,17 @@ void setup() // displayed. if (std::isnan(inTemp) || std::isnan(inHumidity)) { - statusStr = "BME read failed"; + statusStr = "BME " + String(TXT_READ_FAILED); Serial.println(statusStr); } else { - Serial.println("Success"); + Serial.println(TXT_SUCCESS); } } else { - statusStr = "BME not found"; // check wiring + statusStr = "BME " + String(TXT_NOT_FOUND); // check wiring Serial.println(statusStr); } digitalWrite(PIN_BME_PWR, LOW); @@ -347,7 +349,7 @@ void setup() } while (display.nextPage()); powerOffDisplay(); - // DEEP-SLEEP + // DEEP SLEEP beginDeepSleep(startTime, &timeInfo); } // end setup diff --git a/platformio/src/renderer.cpp b/platformio/src/renderer.cpp index aaff97f11..82d14f08d 100644 --- a/platformio/src/renderer.cpp +++ b/platformio/src/renderer.cpp @@ -1177,17 +1177,29 @@ void drawStatusBar(const String &statusStr, const String &refreshTimeStr, /* This function is responsible for drawing prominent error messages to the * screen. + * + * If error message line 2 (errMsgLn2) is empty, line 1 will be automatically + * wrapped. */ void drawError(const uint8_t *bitmap_196x196, const String &errMsgLn1, const String &errMsgLn2) { display.setFont(&FONT_26pt8b); - drawString(DISP_WIDTH / 2, - DISP_HEIGHT / 2 + 196 / 2 + 21, - errMsgLn1, CENTER); - drawString(DISP_WIDTH / 2, - DISP_HEIGHT / 2 + 196 / 2 + 76, - errMsgLn2, CENTER); + if (!errMsgLn2.isEmpty()) + { + drawString(DISP_WIDTH / 2, + DISP_HEIGHT / 2 + 196 / 2 + 21, + errMsgLn1, CENTER); + drawString(DISP_WIDTH / 2, + DISP_HEIGHT / 2 + 196 / 2 + 21 + 55, + errMsgLn2, CENTER); + } + else + { + drawMultiLnString(DISP_WIDTH / 2, + DISP_HEIGHT / 2 + 196 / 2 + 21, + errMsgLn1, CENTER, DISP_WIDTH - 200, 2, 55); + } display.drawInvertedBitmap(DISP_WIDTH / 2 - 196 / 2, DISP_HEIGHT / 2 - 196 / 2 - 21, bitmap_196x196, 196, 196, ACCENT_COLOR);