Cleanup & typo fix.

This commit is contained in:
Blaž Kristan 2021-04-13 08:11:51 +02:00
parent 3623afa721
commit c38f0d751b
4 changed files with 26 additions and 32 deletions

View File

@ -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 "<usermodename>_<usermodparam>" 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).

View File

@ -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() {

View File

@ -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).

View File

@ -159,7 +159,7 @@ function loadBg(iUrl)
for (var i=0; i<hol.length; i++) {
var yr = hol[i][0]==0 ? today.getFullYear() : hol[i][0];
var hs = new Date(yr,hol[i][1],hol[i][2]);
var he = new Date(hs)
var he = new Date(hs);
he.setDate(he.getDate() + hol[i][3]);
if (today>=hs && today<=he) img.src = hol[i][4];
}