diff --git a/usermods/powerap/powerap.h b/usermods/powerap/powerap.h new file mode 100644 index 00000000..b1aa91e7 --- /dev/null +++ b/usermods/powerap/powerap.h @@ -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; } + +}; \ No newline at end of file diff --git a/wled00/usermods_list.cpp b/wled00/usermods_list.cpp index 2f38d42c..88f42079 100644 --- a/wled00/usermods_list.cpp +++ b/wled00/usermods_list.cpp @@ -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 }