From c38f0d751b37a55480d8df0369451f42994253e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Kristan?= Date: Tue, 13 Apr 2021 08:11:51 +0200 Subject: [PATCH] Cleanup & typo fix. --- usermods/Temperature/usermod_temperature.h | 15 +++++--- .../usermod_v2_auto_save.h | 37 +++++++------------ .../usermod_v2_four_line_display.h | 4 +- wled00/data/index.js | 2 +- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/usermods/Temperature/usermod_temperature.h b/usermods/Temperature/usermod_temperature.h index 4fcf8adb..569c31b2 100644 --- a/usermods/Temperature/usermod_temperature.h +++ b/usermods/Temperature/usermod_temperature.h @@ -147,6 +147,11 @@ class UsermodTemperature : public Usermod { } } + /* + * addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API. + * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. + * Below it is shown how this could be used for e.g. a light sensor + */ void addToJsonInfo(JsonObject& root) { // dont add temperature to info if we are disabled if (disabled) return; @@ -155,6 +160,7 @@ class UsermodTemperature : public Usermod { if (user.isNull()) user = root.createNestedObject("u"); JsonArray temp = user.createNestedArray(FPSTR(_um_Temperature)); + //temp.add(F("Loaded.")); if (!getTemperatureComplete) { // if we haven't read the sensor yet, let the user know @@ -178,13 +184,10 @@ class UsermodTemperature : public Usermod { /** * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object). * Values in the state object may be modified by connected clients - * Add "_" to json state. This can be used to check which GPIO pin usermod uses. */ - void addToJsonState(JsonObject &root) - { - //root[F("Temperature_pin")] = temperaturePin; - //root[F("Temperature_degC")] = degC ? ("C") : ("F"); - } + //void addToJsonState(JsonObject &root) + //{ + //} /** * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). diff --git a/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h b/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h index 9413140f..f0e3c1e7 100644 --- a/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h +++ b/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h @@ -2,9 +2,8 @@ #include "wled.h" -// // v2 Usermod to automatically save settings -// to preset number AUTOSAVE_PRESET_NUM after a change to any of +// to configurable preset after a change to any of // // * brightness // * effect speed @@ -12,24 +11,17 @@ // * mode (effect) // * palette // -// but it will wait for AUTOSAVE_SETTLE_MS milliseconds, a "settle" +// but it will wait for configurable number of seconds, a "settle" // period in case there are other changes (any change will // extend the "settle" window). // -// It will additionally load preset AUTOSAVE_PRESET_NUM at startup. -// during the first `loop()`. Reasoning below. +// It can be configured to load auto saved preset at startup, +// during the first `loop()`. // // AutoSaveUsermod is standalone, but if FourLineDisplayUsermod // is installed, it will notify the user of the saved changes. -// -// Note: I don't love that WLED doesn't respect the brightness -// of the preset being auto loaded, so the AutoSaveUsermod -// will set the AUTOSAVE_PRESET_NUM preset in the first loop, -// so brightness IS honored. This means WLED will effectively -// ignore Default brightness and Apply N preset at boot when -// the AutoSaveUsermod is installed. -// "~ MM-DD HH:MM:SS ~" +// format: "~ MM-DD HH:MM:SS ~" #define PRESET_NAME_BUFFER_SIZE 25 // strings @@ -42,19 +34,17 @@ class AutoSaveUsermod : public Usermod { private: + bool firstLoop = true; + bool initDone = false; + + // configurable parameters unsigned long autoSaveAfterSec = 15; // 15s by default uint8_t autoSavePreset = 250; // last possible preset - bool initDone = false; - bool applyAutoSaveOnBoot = false; + bool applyAutoSaveOnBoot = false; // do we load auto-saved preset on boot? - // If we've detected the need to auto save, this will - // be non zero. + // If we've detected the need to auto save, this will be non zero. unsigned long autoSaveAfter = 0; - char presetNameBuffer[PRESET_NAME_BUFFER_SIZE]; - - bool firstLoop = true; - uint8_t knownBrightness = 0; uint8_t knownEffectSpeed = 0; uint8_t knownEffectIntensity = 0; @@ -66,6 +56,7 @@ class AutoSaveUsermod : public Usermod { #endif void inline saveSettings() { + char presetNameBuffer[PRESET_NAME_BUFFER_SIZE]; updateLocalTime(); sprintf_P(presetNameBuffer, PSTR("~ %02d-%02d %02d:%02d:%02d ~"), @@ -100,7 +91,7 @@ class AutoSaveUsermod : public Usermod { // interfaces here void connected() {} - /** + /* * Da loop. */ void loop() { @@ -233,4 +224,4 @@ class AutoSaveUsermod : public Usermod { return USERMOD_ID_AUTO_SAVE; } -}; \ No newline at end of file +}; diff --git a/usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h b/usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h index 19fac2c6..261f8e0b 100644 --- a/usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h +++ b/usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h @@ -621,8 +621,8 @@ class FourLineDisplayUsermod : public Usermod { * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object). * Values in the state object may be modified by connected clients */ - void addToJsonState(JsonObject& root) { - } + //void addToJsonState(JsonObject& root) { + //} /* * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). diff --git a/wled00/data/index.js b/wled00/data/index.js index c082dc30..665e4b05 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -159,7 +159,7 @@ function loadBg(iUrl) for (var i=0; i=hs && today<=he) img.src = hol[i][4]; }