Force AP mode on power bounce

-  requires 3 power cycles
This commit is contained in:
Blaz Kristan 2022-12-03 12:35:48 +01:00
parent 33f4e8cf73
commit f85a6f7c3c
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,43 @@
#pragma once
#include "wled.h"
//class name. Use something descriptive and leave the ": public Usermod" part :)
class PowerAPUsermod : public Usermod {
private:
unsigned long lastTime = 0;
String fname = F("/boot.dat");
public:
void setup() {
if (WLED_FS.exists(fname)) {
File fl = WLED_FS.open(fname,"w");
fl.seek(0);
char data = fl.read();
if (data == '0') {
fl.seek(0);
fl.write('1');
} else if (data == '1') {
apBehavior = AP_BEHAVIOR_ALWAYS;
WLED::instance().initAP(true);
}
fl.close();
} else {
File fl = WLED_FS.open(fname,"w");
fl.write('0');
fl.close();
}
}
void loop() {
if (millis() < 10000 && millis() - lastTime > 5000) {
lastTime = millis();
if (WLED_FS.exists(fname)) {
WLED_FS.remove(fname);
}
}
}
uint16_t getId() { return USERMOD_ID_UNSPECIFIED; }
};

View File

@ -176,6 +176,10 @@
#include "../usermods/pwm_outputs/usermod_pwm_outputs.h"
#endif
#ifdef USERMOD_POWER_AP
#include "../usermods/powerap/powerap.h"
#endif
void registerUsermods()
{
@ -332,4 +336,8 @@ void registerUsermods()
#ifdef USERMOD_PWM_OUTPUTS
usermods.add(new PwmOutputsUsermod());
#endif
#ifdef USERMOD_POWER_AP
usermods.add(new PowerAPUsermod());
#endif
}