From 29d873d268e3fb8e888f4c5ff32ee061ecdeedff Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Tue, 26 Jan 2021 07:16:24 +0100 Subject: [PATCH] Show message during SPIFFS format Also moved startup order around so module error message can be localized with user language. --- operame.ino | 38 +++++++++++++++++++++++--------------- operame_strings.h | 15 +++++++++++++++ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/operame.ino b/operame.ino index a8f2fcc..d9c564a 100644 --- a/operame.ino +++ b/operame.ino @@ -267,25 +267,41 @@ int get_co2() { void setup() { Serial.begin(115200); Serial.println("Operame start"); - SPIFFS.begin(true); + + digitalWrite(pin_backlight, HIGH); + display.init(); + display.fillScreen(TFT_BLACK); + display.setRotation(1); + sprite.createSprite(display.width(), display.height()); + + OperameLanguage::select(T, LANGUAGE); + + if (!SPIFFS.begin(false)) { + display_lines(T.first_run, TFT_MAGENTA); + if (!SPIFFS.format()) { + display_big(T.error_format, TFT_RED); + delay(20*1000); + } + } pinMode(pin_portalbutton, INPUT_PULLUP); pinMode(pin_demobutton, INPUT_PULLUP); pinMode(pin_pcb_ok, INPUT_PULLUP); pinMode(pin_backlight, OUTPUT); - digitalWrite(pin_backlight, HIGH); - - display.init(); - display.fillScreen(TFT_BLACK); - display.setRotation(1); - sprite.createSprite(display.width(), display.height()); + WiFiSettings.hostname = "operame-"; + WiFiSettings.language = LANGUAGE; + WiFiSettings.begin(); + OperameLanguage::select(T, WiFiSettings.language); while (digitalRead(pin_pcb_ok)) { display_big(T.error_module, TFT_RED); delay(1000); } + display_logo(); + delay(2000); + hwserial1.begin(9600, SERIAL_8N1, pin_sensor_rx, pin_sensor_tx); if (aqc_get_co2() >= 0) { @@ -298,14 +314,7 @@ void setup() { Serial.println("Using MHZ driver."); } - display_logo(); - delay(2000); - WiFiSettings.hostname = "operame-"; - WiFiSettings.language = LANGUAGE; - WiFiSettings.begin(); - - OperameLanguage::select(T, WiFiSettings.language); for (auto& str : T.portal_instructions[0]) { str.replace("{ssid}", WiFiSettings.hostname); } @@ -328,7 +337,6 @@ void setup() { mqtt_template = WiFiSettings.string("operame_mqtt_template", "{} PPM", T.config_mqtt_template); WiFiSettings.info(T.config_template_info); - WiFiSettings.onConnect = [] { display_big(T.connecting, TFT_BLUE); check_portalbutton(); diff --git a/operame_strings.h b/operame_strings.h index eb4350c..cdae1d9 100644 --- a/operame_strings.h +++ b/operame_strings.h @@ -12,6 +12,7 @@ struct Texts { *error_timeout, *error_sensor, *error_wifi, + *error_format, *config_wifi, *config_ota, *config_co2_warning, @@ -29,6 +30,7 @@ struct Texts { *wait ; std::vector> portal_instructions; + std::list first_run; }; std::map languages { @@ -54,6 +56,7 @@ bool select(Texts& T, String language) { T.error_timeout = "Time's up"; T.error_sensor = "sensor error"; T.error_wifi = "WiFi failed!"; + T.error_format = "Formatting failed"; T.wait = "wait..."; T.config_wifi = "Use WiFi connection"; T.config_ota = "Enable wireless reprogramming. (Uses portal password!)"; @@ -93,6 +96,11 @@ bool select(Texts& T, String language) { "when you're done." } }; + T.first_run = { + "DO NOT TURN OFF", + "Initializing", + "flash memory.", + }; return true; } @@ -103,6 +111,7 @@ bool select(Texts& T, String language) { T.error_timeout = "Tijd verstreken"; T.error_sensor = "sensorfout"; T.error_wifi = "WiFi mislukt!"; + T.error_format = "Formatteren mislukt"; T.wait = "wacht..."; T.config_wifi = "WiFi-verbinding gebruiken"; T.config_ota = "Draadloos herprogrammeren inschakelen. (Gebruikt portaalwachtwoord!)"; @@ -142,6 +151,12 @@ bool select(Texts& T, String language) { "als u klaar bent." } }; + T.first_run = { + "NIET", + "UITSCHAKELEN", + "Flashgeheugen", + "wordt voorbereid." + }; return true; }