Skip to content

Commit a21e971

Browse files
committed
fshalt - clang
1 parent 6fe49af commit a21e971

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

src/Wippersnapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,9 +2306,14 @@ void Wippersnapper::errorWriteHang(String error) {
23062306
WS_DEBUG_PRINTLN(error);
23072307
#ifdef USE_TINYUSB
23082308
_fileSystem->writeToBootOut(error.c_str());
2309+
delay(500);
2310+
TinyUSBDevice.attach();
2311+
delay(500);
23092312
#endif
23102313
// Signal and hang forever
23112314
while (1) {
2315+
WS_DEBUG_PRINTLN("ERROR: Halted execution");
2316+
WS_DEBUG_PRINTLN(error.c_str());
23122317
WS.feedWDT();
23132318
statusLEDBlink(WS_LED_STATUS_ERROR_RUNTIME);
23142319
delay(1000);

src/provisioning/littlefs/WipperSnapper_LittleFS.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
WipperSnapper_LittleFS::WipperSnapper_LittleFS() {
2929
// Attempt to initialize filesystem
3030
if (!LittleFS.begin()) {
31-
WS_DEBUG_PRINTLN("ERROR: Failure initializing LittleFS!");
3231
setStatusLEDColor(RED);
32+
fsHalt("ERROR: Failure initializing LittleFS!");
3333
while (1)
3434
;
3535
}
@@ -51,25 +51,22 @@ WipperSnapper_LittleFS::~WipperSnapper_LittleFS() { LittleFS.end(); }
5151
void WipperSnapper_LittleFS::parseSecrets() {
5252
// Check if `secrets.json` file exists on FS
5353
if (!LittleFS.exists("/secrets.json")) {
54-
WS_DEBUG_PRINTLN("ERROR: No secrets.json found on filesystem - did you "
55-
"upload credentials?");
56-
fsHalt();
54+
fsHalt("ERROR: No secrets.json found on filesystem - did you upload "
55+
"credentials?");
5756
}
5857

5958
// Attempt to open secrets.json file for reading
6059
File secretsFile = LittleFS.open("/secrets.json", "r");
6160
if (!secretsFile) {
62-
WS_DEBUG_PRINTLN("ERROR: Could not open secrets.json file for reading!");
63-
fsHalt();
61+
fsHalt("ERROR: Could not open secrets.json file for reading!");
6462
}
6563

6664
// Attempt to deserialize the file's JSON document
6765
JsonDocument doc;
6866
DeserializationError error = deserializeJson(doc, secretsFile);
6967
if (error) {
70-
WS_DEBUG_PRINT("ERROR: deserializeJson() failed with code ");
71-
WS_DEBUG_PRINTLN(error.c_str());
72-
fsHalt();
68+
fsHalt(String("ERROR: deserializeJson() failed with code ") +
69+
error.c_str());
7370
}
7471

7572
// Extract a config struct from the JSON document
@@ -78,18 +75,16 @@ void WipperSnapper_LittleFS::parseSecrets() {
7875
// Validate the config struct is not filled with default values
7976
if (strcmp(WS._config.aio_user, "YOUR_IO_USERNAME_HERE") == 0 ||
8077
strcmp(WS._config.aio_key, "YOUR_IO_KEY_HERE") == 0) {
81-
WS_DEBUG_PRINTLN(
78+
fsHalt(
8279
"ERROR: Invalid IO credentials in secrets.json! TO FIX: Please change "
8380
"io_username and io_key to match your Adafruit IO credentials!\n");
84-
fsHalt();
8581
}
8682

8783
if (strcmp(WS._config.network.ssid, "YOUR_WIFI_SSID_HERE") == 0 ||
8884
strcmp(WS._config.network.pass, "YOUR_WIFI_PASS_HERE") == 0) {
89-
WS_DEBUG_PRINTLN("ERROR: Invalid network credentials in secrets.json! TO "
90-
"FIX: Please change network_ssid and network_password to "
91-
"match your Adafruit IO credentials!\n");
92-
fsHalt();
85+
fsHalt("ERROR: Invalid network credentials in secrets.json! TO FIX: Please "
86+
"change network_ssid and network_password to match your Adafruit IO "
87+
"credentials!\n");
9388
}
9489

9590
// Close the file
@@ -99,11 +94,14 @@ void WipperSnapper_LittleFS::parseSecrets() {
9994
LittleFS.end();
10095
}
10196

102-
void WipperSnapper_LittleFS::fsHalt() {
97+
void WipperSnapper_LittleFS::fsHalt(String msg) {
10398
while (1) {
99+
WS_DEBUG_PRINTLN("ERROR: Halted execution!");
100+
WS_DEBUG_PRINTLN(msg.c_str());
104101
statusLEDSolid(WS_LED_STATUS_FS_WRITE);
105102
delay(1000);
106103
yield();
107104
}
108105
}
106+
109107
#endif

src/provisioning/littlefs/WipperSnapper_LittleFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WipperSnapper_LittleFS {
3333
WipperSnapper_LittleFS();
3434
~WipperSnapper_LittleFS();
3535
void parseSecrets();
36-
void fsHalt();
36+
void fsHalt(String msg = "");
3737
};
3838

3939
extern Wippersnapper WS;

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ Wippersnapper_FS::Wippersnapper_FS() {
9595

9696
// If a filesystem does not already exist - attempt to initialize a new
9797
// filesystem
98-
if (!initFilesystem() || !initFilesystem(true)) {
99-
WS_DEBUG_PRINTLN("ERROR Initializing Filesystem");
98+
if (!initFilesystem() && !initFilesystem(true)) {
10099
setStatusLEDColor(RED);
100+
fsHalt("ERROR Initializing Filesystem");
101101
while (1)
102102
;
103103
}
@@ -107,7 +107,7 @@ Wippersnapper_FS::Wippersnapper_FS() {
107107

108108
// If we created a new filesystem, halt until user RESETs device.
109109
if (_freshFS)
110-
fsHalt();
110+
fsHalt("New filesystem created! Please RESET your board.");
111111
}
112112

113113
/************************************************************/
@@ -325,7 +325,7 @@ void Wippersnapper_FS::createSecretsFile() {
325325
"Please edit it to reflect your Adafruit IO and network credentials. "
326326
"When you're done, press RESET on the board.");
327327
#endif
328-
fsHalt();
328+
fsHalt("ERROR: Please edit the secrets.json file. Then, reset your board.");
329329
}
330330

331331
/**************************************************************************/
@@ -337,17 +337,14 @@ void Wippersnapper_FS::parseSecrets() {
337337
// Attempt to open the secrets.json file for reading
338338
File32 secretsFile = wipperFatFs.open("/secrets.json");
339339
if (!secretsFile) {
340-
WS_DEBUG_PRINTLN("ERROR: Could not open secrets.json file for reading!");
341-
fsHalt();
340+
fsHalt("ERROR: Could not open secrets.json file for reading!");
342341
}
343342

344343
// Attempt to deserialize the file's JSON document
345344
JsonDocument doc;
346345
DeserializationError error = deserializeJson(doc, secretsFile);
347346
if (error) {
348-
WS_DEBUG_PRINT("ERROR: deserializeJson() failed with code ");
349-
WS_DEBUG_PRINTLN(error.c_str());
350-
fsHalt();
347+
fsHalt(String("ERROR: Unable to parse secrets.json file - deserializeJson() failed with code") + error.c_str());
351348
}
352349

353350
// Extract a config struct from the JSON document
@@ -362,7 +359,7 @@ void Wippersnapper_FS::parseSecrets() {
362359
"The \"io_username/io_key\" fields within secrets.json are invalid, please "
363360
"change it to match your Adafruit IO credentials. Then, press RESET.");
364361
#endif
365-
fsHalt();
362+
fsHalt("ERROR: Invalid IO credentials in secrets.json! TO FIX: Please change io_username and io_key to match your Adafruit IO credentials!");
366363
}
367364

368365
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() {
373370
"The \"network_ssid and network_password\" fields within secrets.json are invalid, please "
374371
"change it to match your WiFi credentials. Then, press RESET.");
375372
#endif
376-
fsHalt();
373+
fsHalt("ERROR: Invalid network credentials in secrets.json! TO FIX: Please change network_ssid and network_password to match your Adafruit IO credentials!");
377374
}
378375

379376
// Close secrets.json file
@@ -396,16 +393,24 @@ void Wippersnapper_FS::writeToBootOut(PGM_P str) {
396393
bootFile.close();
397394
} else {
398395
WS_DEBUG_PRINTLN("ERROR: Unable to open wipper_boot_out.txt for logging!");
396+
// feels like we should check why, if good use-case ok, otherwise fsHalt
397+
// as indicates fs corruption or disc access issue (maybe latter is okay)
399398
}
400399
}
401400

402401
/**************************************************************************/
403402
/*!
404403
@brief Halts execution and blinks the status LEDs yellow.
404+
@param msg
405+
Error message to print to serial console.
405406
*/
406407
/**************************************************************************/
407-
void Wippersnapper_FS::fsHalt() {
408+
void Wippersnapper_FS::fsHalt(String msg) {
409+
TinyUSBDevice.attach();
410+
delay(1500);
408411
while (1) {
412+
WS_DEBUG_PRINTLN("ERROR: Halted execution!");
413+
WS_DEBUG_PRINTLN(msg.c_str());
409414
// statusLEDSolid(WS_LED_STATUS_FS_WRITE);
410415
delay(1000);
411416
yield();
@@ -432,8 +437,7 @@ void Wippersnapper_FS::createDisplayConfig() {
432437
// Create and fill JSON document from displayConfig
433438
JsonDocument doc;
434439
if (!doc.set(displayConfig)) {
435-
WS_DEBUG_PRINTLN("ERROR: Unable to set displayConfig, no space in arduinoJSON document!");
436-
fsHalt();
440+
fsHalt("ERROR: Unable to set displayConfig, no space in arduinoJSON document!");
437441
}
438442
// Write the file out to the filesystem
439443
serializeJsonPretty(doc, displayFile);
@@ -454,18 +458,14 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
454458
// Attempt to open file for JSON parsing
455459
File32 file = wipperFatFs.open("/display_config.json", FILE_READ);
456460
if (!file) {
457-
WS_DEBUG_PRINTLN(
458-
"FATAL ERROR: Unable to open display_config.json for parsing");
459-
fsHalt();
461+
fsHalt("FATAL ERROR: Unable to open display_config.json for parsing");
460462
}
461463

462464
// Attempt to deserialize the file's json document
463465
JsonDocument doc;
464466
DeserializationError error = deserializeJson(doc, file);
465467
if (error) {
466-
WS_DEBUG_PRINTLN("deserializeJson() of display file failed, rc:")
467-
Serial.println(error.c_str());
468-
fsHalt();
468+
fsHalt(String("FATAL ERROR: Unable to parse display_config.json - deserializeJson() failed with code") + error.c_str());
469469
}
470470
// Close the file, we're done with it
471471
file.close();

src/provisioning/tinyusb/Wippersnapper_FS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Wippersnapper_FS {
5454
void createSecretsFile();
5555
bool createBootFile();
5656
void writeToBootOut(PGM_P str);
57-
void fsHalt();
57+
void fsHalt(String msg = "");
5858

5959
void parseSecrets();
6060

0 commit comments

Comments
 (0)