Force AP mode on power bounce
- requires 3 power cycles
This commit is contained in:
parent
33f4e8cf73
commit
f85a6f7c3c
43
usermods/powerap/powerap.h
Normal file
43
usermods/powerap/powerap.h
Normal 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; }
|
||||
|
||||
};
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user