Update factory reset procedure in README and main.cpp for clarity and functionality
This commit is contained in:
+20
-13
@@ -613,7 +613,7 @@ static void startServer() {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Factory reset (hold BOOT button 3s at startup)
|
||||
// Factory reset (rapid reset 5× within a few seconds)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void factoryReset() {
|
||||
@@ -699,19 +699,25 @@ static void factoryReset() {
|
||||
}
|
||||
|
||||
static void checkFactoryReset() {
|
||||
pinMode(0, INPUT_PULLUP);
|
||||
delay(10);
|
||||
if (digitalRead(0) == LOW) {
|
||||
Serial.println("[BOOT] BOOT button held, hold 3s for factory reset...");
|
||||
unsigned long start = millis();
|
||||
while (millis() - start < 3000) {
|
||||
delay(50);
|
||||
if (digitalRead(0) != LOW) {
|
||||
Serial.println("[BOOT] factory reset aborted (button released)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const int THRESHOLD = 5;
|
||||
int count = 0;
|
||||
File f = LittleFS.open("/reset_count", "r");
|
||||
if (f) {
|
||||
count = f.parseInt();
|
||||
f.close();
|
||||
}
|
||||
count++;
|
||||
if (count >= THRESHOLD) {
|
||||
LittleFS.remove("/reset_count");
|
||||
Serial.printf("[BOOT] reset count %d, triggering factory reset\n", count);
|
||||
factoryReset();
|
||||
return;
|
||||
}
|
||||
f = LittleFS.open("/reset_count", "w");
|
||||
if (f) {
|
||||
f.print(count);
|
||||
f.close();
|
||||
Serial.printf("[BOOT] reset count %d/%d\n", count, THRESHOLD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,6 +760,7 @@ void setup() {
|
||||
startMDNS();
|
||||
mqttReconnectAt = 0;
|
||||
|
||||
LittleFS.remove("/reset_count");
|
||||
Serial.printf("[BOOT] ready at http://%s.local or http://%s\n",
|
||||
hostname, WiFi.localIP().toString().c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user