@@ -95,9 +95,9 @@ Wippersnapper_FS::Wippersnapper_FS() {
95
95
96
96
// If a filesystem does not already exist - attempt to initialize a new
97
97
// filesystem
98
- if (!initFilesystem () || !initFilesystem (true )) {
99
- WS_DEBUG_PRINTLN (" ERROR Initializing Filesystem" );
98
+ if (!initFilesystem () && !initFilesystem (true )) {
100
99
setStatusLEDColor (RED);
100
+ fsHalt (" ERROR Initializing Filesystem" );
101
101
while (1 )
102
102
;
103
103
}
@@ -107,7 +107,7 @@ Wippersnapper_FS::Wippersnapper_FS() {
107
107
108
108
// If we created a new filesystem, halt until user RESETs device.
109
109
if (_freshFS)
110
- fsHalt ();
110
+ fsHalt (" New filesystem created! Please RESET your board. " );
111
111
}
112
112
113
113
/* ***********************************************************/
@@ -325,7 +325,7 @@ void Wippersnapper_FS::createSecretsFile() {
325
325
" Please edit it to reflect your Adafruit IO and network credentials. "
326
326
" When you're done, press RESET on the board." );
327
327
#endif
328
- fsHalt ();
328
+ fsHalt (" ERROR: Please edit the secrets.json file. Then, reset your board. " );
329
329
}
330
330
331
331
/* *************************************************************************/
@@ -337,17 +337,14 @@ void Wippersnapper_FS::parseSecrets() {
337
337
// Attempt to open the secrets.json file for reading
338
338
File32 secretsFile = wipperFatFs.open (" /secrets.json" );
339
339
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!" );
342
341
}
343
342
344
343
// Attempt to deserialize the file's JSON document
345
344
JsonDocument doc;
346
345
DeserializationError error = deserializeJson (doc, secretsFile);
347
346
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 ());
351
348
}
352
349
353
350
// Extract a config struct from the JSON document
@@ -362,7 +359,7 @@ void Wippersnapper_FS::parseSecrets() {
362
359
" The \" io_username/io_key\" fields within secrets.json are invalid, please "
363
360
" change it to match your Adafruit IO credentials. Then, press RESET." );
364
361
#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! " );
366
363
}
367
364
368
365
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() {
373
370
" The \" network_ssid and network_password\" fields within secrets.json are invalid, please "
374
371
" change it to match your WiFi credentials. Then, press RESET." );
375
372
#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! " );
377
374
}
378
375
379
376
// Close secrets.json file
@@ -396,16 +393,24 @@ void Wippersnapper_FS::writeToBootOut(PGM_P str) {
396
393
bootFile.close ();
397
394
} else {
398
395
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)
399
398
}
400
399
}
401
400
402
401
/* *************************************************************************/
403
402
/* !
404
403
@brief Halts execution and blinks the status LEDs yellow.
404
+ @param msg
405
+ Error message to print to serial console.
405
406
*/
406
407
/* *************************************************************************/
407
- void Wippersnapper_FS::fsHalt () {
408
+ void Wippersnapper_FS::fsHalt (String msg) {
409
+ TinyUSBDevice.attach ();
410
+ delay (1500 );
408
411
while (1 ) {
412
+ WS_DEBUG_PRINTLN (" ERROR: Halted execution!" );
413
+ WS_DEBUG_PRINTLN (msg.c_str ());
409
414
// statusLEDSolid(WS_LED_STATUS_FS_WRITE);
410
415
delay (1000 );
411
416
yield ();
@@ -432,8 +437,7 @@ void Wippersnapper_FS::createDisplayConfig() {
432
437
// Create and fill JSON document from displayConfig
433
438
JsonDocument doc;
434
439
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!" );
437
441
}
438
442
// Write the file out to the filesystem
439
443
serializeJsonPretty (doc, displayFile);
@@ -454,18 +458,14 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
454
458
// Attempt to open file for JSON parsing
455
459
File32 file = wipperFatFs.open (" /display_config.json" , FILE_READ);
456
460
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" );
460
462
}
461
463
462
464
// Attempt to deserialize the file's json document
463
465
JsonDocument doc;
464
466
DeserializationError error = deserializeJson (doc, file);
465
467
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 ());
469
469
}
470
470
// Close the file, we're done with it
471
471
file.close ();
0 commit comments