diff --git a/src/Wippersnapper.cpp b/src/Wippersnapper.cpp index 4a39741c9..822d238aa 100644 --- a/src/Wippersnapper.cpp +++ b/src/Wippersnapper.cpp @@ -2306,9 +2306,14 @@ void Wippersnapper::errorWriteHang(String error) { WS_DEBUG_PRINTLN(error); #ifdef USE_TINYUSB _fileSystem->writeToBootOut(error.c_str()); + delay(500); + TinyUSBDevice.attach(); + delay(500); #endif // Signal and hang forever while (1) { + WS_DEBUG_PRINTLN("ERROR: Halted execution"); + WS_DEBUG_PRINTLN(error.c_str()); WS.feedWDT(); statusLEDBlink(WS_LED_STATUS_ERROR_RUNTIME); delay(1000); diff --git a/src/provisioning/littlefs/WipperSnapper_LittleFS.cpp b/src/provisioning/littlefs/WipperSnapper_LittleFS.cpp index 337f1070d..c86d84949 100644 --- a/src/provisioning/littlefs/WipperSnapper_LittleFS.cpp +++ b/src/provisioning/littlefs/WipperSnapper_LittleFS.cpp @@ -28,8 +28,8 @@ WipperSnapper_LittleFS::WipperSnapper_LittleFS() { // Attempt to initialize filesystem if (!LittleFS.begin()) { - WS_DEBUG_PRINTLN("ERROR: Failure initializing LittleFS!"); setStatusLEDColor(RED); + fsHalt("ERROR: Failure initializing LittleFS!"); while (1) ; } @@ -51,25 +51,21 @@ WipperSnapper_LittleFS::~WipperSnapper_LittleFS() { LittleFS.end(); } void WipperSnapper_LittleFS::parseSecrets() { // Check if `secrets.json` file exists on FS if (!LittleFS.exists("/secrets.json")) { - WS_DEBUG_PRINTLN("ERROR: No secrets.json found on filesystem - did you " - "upload credentials?"); - fsHalt(); + fsHalt("ERROR: No secrets.json found on filesystem - did you upload " + "credentials?"); } // Attempt to open secrets.json file for reading File secretsFile = LittleFS.open("/secrets.json", "r"); if (!secretsFile) { - WS_DEBUG_PRINTLN("ERROR: Could not open secrets.json file for reading!"); - fsHalt(); + fsHalt("ERROR: Could not open secrets.json file for reading!"); } // Attempt to deserialize the file's JSON document JsonDocument doc; DeserializationError error = deserializeJson(doc, secretsFile); if (error) { - WS_DEBUG_PRINT("ERROR: deserializeJson() failed with code "); - WS_DEBUG_PRINTLN(error.c_str()); - fsHalt(); + fsHalt(String("ERROR: deserializeJson() failed with code ") + error); } // Extract a config struct from the JSON document @@ -78,18 +74,16 @@ void WipperSnapper_LittleFS::parseSecrets() { // Validate the config struct is not filled with default values if (strcmp(WS._config.aio_user, "YOUR_IO_USERNAME_HERE") == 0 || strcmp(WS._config.aio_key, "YOUR_IO_KEY_HERE") == 0) { - WS_DEBUG_PRINTLN( + fsHalt( "ERROR: Invalid IO credentials in secrets.json! TO FIX: Please change " "io_username and io_key to match your Adafruit IO credentials!\n"); - fsHalt(); } if (strcmp(WS._config.network.ssid, "YOUR_WIFI_SSID_HERE") == 0 || strcmp(WS._config.network.pass, "YOUR_WIFI_PASS_HERE") == 0) { - WS_DEBUG_PRINTLN("ERROR: Invalid network credentials in secrets.json! TO " - "FIX: Please change network_ssid and network_password to " - "match your Adafruit IO credentials!\n"); - fsHalt(); + fsHalt("ERROR: Invalid network credentials in secrets.json! TO FIX: Please " + "change network_ssid and network_password to match your Adafruit IO " + "credentials!\n"); } // Close the file @@ -99,11 +93,14 @@ void WipperSnapper_LittleFS::parseSecrets() { LittleFS.end(); } -void WipperSnapper_LittleFS::fsHalt() { +void WipperSnapper_LittleFS::fsHalt(String msg) { while (1) { + WS_DEBUG_PRINTLN("ERROR: Halted execution!"); + WS_DEBUG_PRINTLN(msg.c_str()); statusLEDSolid(WS_LED_STATUS_FS_WRITE); delay(1000); yield(); } } + #endif \ No newline at end of file diff --git a/src/provisioning/littlefs/WipperSnapper_LittleFS.h b/src/provisioning/littlefs/WipperSnapper_LittleFS.h index d96b53768..33ee61e22 100644 --- a/src/provisioning/littlefs/WipperSnapper_LittleFS.h +++ b/src/provisioning/littlefs/WipperSnapper_LittleFS.h @@ -33,7 +33,7 @@ class WipperSnapper_LittleFS { WipperSnapper_LittleFS(); ~WipperSnapper_LittleFS(); void parseSecrets(); - void fsHalt(); + void fsHalt(String msg=""); }; extern Wippersnapper WS; diff --git a/src/provisioning/tinyusb/Wippersnapper_FS.cpp b/src/provisioning/tinyusb/Wippersnapper_FS.cpp index 36cde7784..f98dd37fa 100644 --- a/src/provisioning/tinyusb/Wippersnapper_FS.cpp +++ b/src/provisioning/tinyusb/Wippersnapper_FS.cpp @@ -95,9 +95,9 @@ Wippersnapper_FS::Wippersnapper_FS() { // If a filesystem does not already exist - attempt to initialize a new // filesystem - if (!initFilesystem() || !initFilesystem(true)) { - WS_DEBUG_PRINTLN("ERROR Initializing Filesystem"); + if (!initFilesystem() && !initFilesystem(true)) { setStatusLEDColor(RED); + fsHalt("ERROR Initializing Filesystem"); while (1) ; } @@ -107,7 +107,7 @@ Wippersnapper_FS::Wippersnapper_FS() { // If we created a new filesystem, halt until user RESETs device. if (_freshFS) - fsHalt(); + fsHalt("New filesystem created! Please RESET your board."); } /************************************************************/ @@ -325,7 +325,7 @@ void Wippersnapper_FS::createSecretsFile() { "Please edit it to reflect your Adafruit IO and network credentials. " "When you're done, press RESET on the board."); #endif - fsHalt(); + fsHalt("ERROR: Please edit the secrets.json file. Then, reset your board."); } /**************************************************************************/ @@ -337,17 +337,14 @@ void Wippersnapper_FS::parseSecrets() { // Attempt to open the secrets.json file for reading File32 secretsFile = wipperFatFs.open("/secrets.json"); if (!secretsFile) { - WS_DEBUG_PRINTLN("ERROR: Could not open secrets.json file for reading!"); - fsHalt(); + fsHalt("ERROR: Could not open secrets.json file for reading!"); } // Attempt to deserialize the file's JSON document JsonDocument doc; DeserializationError error = deserializeJson(doc, secretsFile); if (error) { - WS_DEBUG_PRINT("ERROR: deserializeJson() failed with code "); - WS_DEBUG_PRINTLN(error.c_str()); - fsHalt(); + fsHalt(String("ERROR: Unable to parse secrets.json file - deserializeJson() failed with code") + error.c_str()); } // Extract a config struct from the JSON document @@ -362,7 +359,7 @@ void Wippersnapper_FS::parseSecrets() { "The \"io_username/io_key\" fields within secrets.json are invalid, please " "change it to match your Adafruit IO credentials. Then, press RESET."); #endif - fsHalt(); + fsHalt("ERROR: Invalid IO credentials in secrets.json! TO FIX: Please change io_username and io_key to match your Adafruit IO credentials!"); } if (strcmp(WS._config.network.ssid, "YOUR_WIFI_SSID_HERE") == 0 || strcmp(WS._config.network.pass, "YOUR_WIFI_PASS_HERE") == 0) { @@ -373,7 +370,7 @@ void Wippersnapper_FS::parseSecrets() { "The \"network_ssid and network_password\" fields within secrets.json are invalid, please " "change it to match your WiFi credentials. Then, press RESET."); #endif - fsHalt(); + fsHalt("ERROR: Invalid network credentials in secrets.json! TO FIX: Please change network_ssid and network_password to match your Adafruit IO credentials!"); } // Close secrets.json file @@ -396,16 +393,24 @@ void Wippersnapper_FS::writeToBootOut(PGM_P str) { bootFile.close(); } else { WS_DEBUG_PRINTLN("ERROR: Unable to open wipper_boot_out.txt for logging!"); + // feels like we should check why, if good use-case ok, otherwise fsHalt + // as indicates fs corruption or disc access issue (maybe latter is okay) } } /**************************************************************************/ /*! @brief Halts execution and blinks the status LEDs yellow. + @param msg + Error message to print to serial console. */ /**************************************************************************/ -void Wippersnapper_FS::fsHalt() { +void Wippersnapper_FS::fsHalt(String msg) { + TinyUSBDevice.attach(); + delay(1500); while (1) { + WS_DEBUG_PRINTLN("ERROR: Halted execution!"); + WS_DEBUG_PRINTLN(msg.c_str()); // statusLEDSolid(WS_LED_STATUS_FS_WRITE); delay(1000); yield(); @@ -432,8 +437,7 @@ void Wippersnapper_FS::createDisplayConfig() { // Create and fill JSON document from displayConfig JsonDocument doc; if (!doc.set(displayConfig)) { - WS_DEBUG_PRINTLN("ERROR: Unable to set displayConfig, no space in arduinoJSON document!"); - fsHalt(); + fsHalt("ERROR: Unable to set displayConfig, no space in arduinoJSON document!"); } // Write the file out to the filesystem serializeJsonPretty(doc, displayFile); @@ -454,18 +458,14 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) { // Attempt to open file for JSON parsing File32 file = wipperFatFs.open("/display_config.json", FILE_READ); if (!file) { - WS_DEBUG_PRINTLN( - "FATAL ERROR: Unable to open display_config.json for parsing"); - fsHalt(); + fsHalt("FATAL ERROR: Unable to open display_config.json for parsing"); } // Attempt to deserialize the file's json document JsonDocument doc; DeserializationError error = deserializeJson(doc, file); if (error) { - WS_DEBUG_PRINTLN("deserializeJson() of display file failed, rc:") - Serial.println(error.c_str()); - fsHalt(); + fsHalt(String("FATAL ERROR: Unable to parse display_config.json - deserializeJson() failed with code") + error); } // Close the file, we're done with it file.close(); diff --git a/src/provisioning/tinyusb/Wippersnapper_FS.h b/src/provisioning/tinyusb/Wippersnapper_FS.h index 6d8d65b80..beeba017b 100644 --- a/src/provisioning/tinyusb/Wippersnapper_FS.h +++ b/src/provisioning/tinyusb/Wippersnapper_FS.h @@ -54,7 +54,7 @@ class Wippersnapper_FS { void createSecretsFile(); bool createBootFile(); void writeToBootOut(PGM_P str); - void fsHalt(); + void fsHalt(String msg = ""); void parseSecrets();