WLED/usermods/powerap/powerap.h

47 lines
1.3 KiB
C
Raw Normal View History

#pragma once
#include "wled.h"
class PowerAPUsermod : public Usermod {
private:
unsigned long lastTime = 0;
String fname = F("/boot.dat");
public:
void setup() {
if (WLED_FS.exists(fname)) {
2022-12-10 01:44:16 +01:00
File fl = WLED_FS.open(fname,"r+");
if (!fl) DEBUG_PRINTLN(F("--- File read failed ---"));
char data = fl.read();
2022-12-10 01:44:16 +01:00
DEBUG_PRINT(F("--- Read ")); DEBUG_PRINT(data); DEBUG_PRINT('('); DEBUG_PRINT((int)data); DEBUG_PRINTLN(F(") ---"));
if (data == '0') {
2022-12-10 01:44:16 +01:00
DEBUG_PRINTLN(F("--- 2nd boot ---"));
fl.seek(0);
fl.write('1');
} else if (data == '1') {
2022-12-10 01:44:16 +01:00
DEBUG_PRINTLN(F("--- 3rd boot ---"));
apBehavior = AP_BEHAVIOR_ALWAYS;
WLED::instance().initAP(true);
}
fl.close();
} else {
2022-12-10 01:44:16 +01:00
DEBUG_PRINTLN(F("--- 1st boot ---"));
File fl = WLED_FS.open(fname,"w");
2022-12-10 01:44:16 +01:00
fl.write((uint8_t*)"0 ", 2);
fl.close();
}
}
void loop() {
if (millis() < 10000 && millis() - lastTime > 5000) {
lastTime = millis();
if (WLED_FS.exists(fname)) {
2022-12-10 01:44:16 +01:00
DEBUG_PRINTLN(F("--- Removing boot file ---"));
WLED_FS.remove(fname);
}
}
}
uint16_t getId() { return USERMOD_ID_UNSPECIFIED; }
};