From 4c57546657379cd58c5e05057e4c5d76a7800b18 Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 17 Oct 2024 02:15:15 +0200 Subject: [PATCH] basics of factory reset implemented --- Arduino/CanGrow/CanGrow.ino | 40 +++++++++++++++++++++++++------ Arduino/CanGrow/include/CanGrow.h | 8 +++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index bbfd80e..6f1590c 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -63,6 +63,9 @@ void setup() { + // define output for onboard LED/WIPE pin + pinMode(PinWIPE, OUTPUT); + // Start Serial Serial.begin(115200); @@ -75,14 +78,37 @@ void setup() { Serial.print(CanGrowBuild); Serial.println(" starting ::."); + + Serial.print(":: To format LittleFS, pull "); + Serial.print(PinWIPE); + Serial.println("(PinWIPE) to LOW - NOW! (2 seconds left) ::"); + + // blink with the onboard LED on D4 (PinWIPE) + for(byte i = 0; i <= 6 ; i++) { + if(i % 2) { + digitalWrite(PinWIPE, LOW); + } else { + digitalWrite(PinWIPE, HIGH); + } + delay(333); + } + // set back to HIGH because thats the default + digitalWrite(PinWIPE, HIGH); + //delay(2000); + + // read status from PinWIPE to WIPE + // when PinWIPE is set to LOW, format LittleFS + if(digitalRead(PinWIPE) == LOW) { + Serial.println("!! formatting LittleFS !!"); + LittleFS.format(); + } + + Serial.println(":: initialise LittleFS ::"); if(LittleFS.begin()) { - Serial.println(":: LittleFS successfully initialized ::"); + Serial.println(":: LittleFS successfully initialised ::"); } else { - Serial.println("!! LittleFS failed initializing !!"); - delay(10000); - LittleFS.format(); - Serial.println("!! formatting LittleFS !!"); + Serial.println("!! LittleFS failed initialising !!"); } // read the configfile from LittleFS @@ -93,14 +119,14 @@ void setup() { if(lfs_configfile) { Serial.println(":: LittleFS: config.json successfully created ::"); // write into the file - lfs_configfile.print("{}"); + lfs_configfile.print("{test: 2}"); // close the file lfs_configfile.close(); } } else { Serial.println(":: LittleFS: config.json successfully opened ::"); String configfile_content = ""; - Serial.println(lfs_configfile.available()); + while (lfs_configfile.available()) { configfile_content += (char)lfs_configfile.read(); } diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index 3c45e53..e281ab0 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -31,3 +31,11 @@ const char* configfile = "config.json"; + +#ifdef ESP8266 +const uint8_t PinWIPE = D4; +#endif + +#ifdef ESP32 +const uint8_t PinWIPE = 2; +#endif