Add CustomEffects as usermod: step 2: ui works

This commit is contained in:
Ewowi
2022-08-30 12:55:01 +02:00
parent 9a87d2bd8e
commit 068089751d
7 changed files with 2130 additions and 1874 deletions

View File

@@ -100,10 +100,16 @@ class CustomEffectsUserMod : public Usermod {
unsigned long lastTime = 0; //will be used to download new forecast every hour
char errorMessage[100] = "";
bool enabled = false;
bool initDone = false;
public:
void setup() {
strip.addEffect(255, &mode_customEffect, _data_FX_MODE_CUSTOMEFFECT);
if (!initDone)
strip.addEffect(255, &mode_customEffect, _data_FX_MODE_CUSTOMEFFECT);
initDone = true;
enabled = true;
}
void connected() {
@@ -140,6 +146,12 @@ class CustomEffectsUserMod : public Usermod {
void addToJsonState(JsonObject& root)
{
//root["user0"] = userVar0;
if (!initDone) return; // prevent crash on boot applyPreset()
JsonObject usermod = root[FPSTR(_name)];
if (usermod.isNull()) {
usermod = root.createNestedObject(FPSTR(_name));
}
usermod["on"] = enabled;
}
@@ -196,4 +208,4 @@ class CustomEffectsUserMod : public Usermod {
};
// strings to reduce flash memory usage (used more than twice)
const char CustomEffectsUserMod::_name[] PROGMEM = "Custom Effects";
const char CustomEffectsUserMod::_name[] PROGMEM = "CustomEffects";