From e186b0568dd2354398f993fe83ae937bbc97bc6a Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sat, 10 Dec 2022 01:44:16 +0100 Subject: [PATCH] Bugfix. --- usermods/powerap/powerap.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/usermods/powerap/powerap.h b/usermods/powerap/powerap.h index 0ac3554e..339af7d6 100644 --- a/usermods/powerap/powerap.h +++ b/usermods/powerap/powerap.h @@ -10,20 +10,24 @@ class PowerAPUsermod : public Usermod { public: void setup() { if (WLED_FS.exists(fname)) { - File fl = WLED_FS.open(fname,"w"); - fl.seek(0); + File fl = WLED_FS.open(fname,"r+"); + if (!fl) DEBUG_PRINTLN(F("--- File read failed ---")); char data = fl.read(); + DEBUG_PRINT(F("--- Read ")); DEBUG_PRINT(data); DEBUG_PRINT('('); DEBUG_PRINT((int)data); DEBUG_PRINTLN(F(") ---")); if (data == '0') { + DEBUG_PRINTLN(F("--- 2nd boot ---")); fl.seek(0); fl.write('1'); } else if (data == '1') { + DEBUG_PRINTLN(F("--- 3rd boot ---")); apBehavior = AP_BEHAVIOR_ALWAYS; WLED::instance().initAP(true); } fl.close(); } else { + DEBUG_PRINTLN(F("--- 1st boot ---")); File fl = WLED_FS.open(fname,"w"); - fl.write('0'); + fl.write((uint8_t*)"0 ", 2); fl.close(); } } @@ -32,6 +36,7 @@ class PowerAPUsermod : public Usermod { if (millis() < 10000 && millis() - lastTime > 5000) { lastTime = millis(); if (WLED_FS.exists(fname)) { + DEBUG_PRINTLN(F("--- Removing boot file ---")); WLED_FS.remove(fname); } }