Added PIR sensor switch on/off presets.

Added empty config info.
Minor fixes.
This commit is contained in:
Blaz Kristan 2021-05-08 12:11:12 +02:00
parent e6111c0d48
commit 8a6945ff3b
6 changed files with 31 additions and 11 deletions

View File

@ -69,11 +69,16 @@ private:
bool m_PIRenabled = true;
// status of initialisation
bool initDone = false;
// on and off presets
uint8_t m_onPreset = 0;
uint8_t m_offPreset = 0;
// strings to reduce flash memory usage (used more than twice)
static const char _name[];
static const char _switchOffDelay[];
static const char _enabled[];
static const char _onPreset[];
static const char _offPreset[];
/**
* return or change if new PIR sensor state is available
@ -90,13 +95,14 @@ private:
*/
void switchStrip(bool switchOn)
{
if (switchOn && bri == 0)
{
if (switchOn && m_onPreset) {
applyPreset(m_onPreset);
} else if (!switchOn && m_offPreset) {
applyPreset(m_offPreset);
} else if (switchOn && bri == 0) {
bri = briLast;
colorUpdated(NotifyUpdateMode);
}
else if (!switchOn && bri != 0)
{
} else if (!switchOn && bri != 0) {
briLast = bri;
bri = 0;
colorUpdated(NotifyUpdateMode);
@ -341,6 +347,8 @@ public:
top[FPSTR(_enabled)] = m_PIRenabled;
top[FPSTR(_switchOffDelay)] = m_switchOffDelay / 1000;
top["pin"] = PIRsensorPin;
top[FPSTR(_onPreset)] = m_onPreset;
top[FPSTR(_offPreset)] = m_offPreset;
DEBUG_PRINTLN(F("PIR config saved."));
}
@ -374,6 +382,14 @@ public:
m_switchOffDelay = (top[FPSTR(_switchOffDelay)].as<int>() * 1000);
}
if (top[FPSTR(_onPreset)] != nullptr) {
m_onPreset = max(0,min(250,top[FPSTR(_onPreset)].as<int>()));
}
if (top[FPSTR(_offPreset)] != nullptr) {
m_offPreset = max(0,min(250,top[FPSTR(_offPreset)].as<int>()));
}
if (!initDone) {
// reading config prior to setup()
DEBUG_PRINTLN(F("PIR config loaded."));
@ -437,3 +453,5 @@ void IRAM_ATTR PIRsensorSwitch::ISR_PIRstateChange()
const char PIRsensorSwitch::_name[] PROGMEM = "PIRsensorSwitch";
const char PIRsensorSwitch::_enabled[] PROGMEM = "PIRenabled";
const char PIRsensorSwitch::_switchOffDelay[] PROGMEM = "PIRoffSec";
const char PIRsensorSwitch::_onPreset[] PROGMEM = "on-preset";
const char PIRsensorSwitch::_offPreset[] PROGMEM = "off-preset";

View File

@ -1,8 +1,6 @@
#pragma once
#include "wled.h"
//#include <DallasTemperature.h> //DS18B20
#include "OneWire.h"
//Pin defaults for QuinLed Dig-Uno if not overriden

View File

@ -281,7 +281,7 @@ class MultiRelay : public Usermod {
* loop() is called continuously. Here you can check for events, read sensors, etc.
*/
void loop() {
if (!enabled) return;
if (!enabled || strip.isUpdating()) return;
static unsigned long lastUpdate = 0;
if (millis() - lastUpdate < 200) return; // update only 5 times/s

View File

@ -99,8 +99,12 @@
urows += `<hr><h3>${k}</h3>`;
addField(k,'unknown',o);
}
gId("um").innerHTML = urows;
if (urows==="")
urows = "No Usermods configuration found.<br>Press <i>Save</i> to initialize defaults.";
} else {
urows = "Usermods configuration not found.<br>Most likely no Usermods exist.<br>Press <i>Save</i> to initialize defaults.";
}
gId("um").innerHTML = urows;
})
.catch(function (error) {
gId('lserr').style.display = "inline"

View File

@ -395,7 +395,7 @@ type="submit">Save & Reboot</button></form></body></html>)=====";
// Autogenerated from wled00/data/settings_um.htm, do not edit!!
const char PAGE_settings_um[] PROGMEM = R"=====(<!DOCTYPE html><html><head lang="en"><meta charset="utf-8"><meta
name="viewport" content="width=500"><title>UI Settings</title><script>
var owner,locip,urows,d=document,umCfg={},pins=[6,7,8,9,10,11],pinO=["reserved","reserved","reserved","reserved","reserved","reserved"],loc=!1;function gId(e){return d.getElementById(e)}function isO(e){return e&&"object"==typeof e&&!Array.isArray(e)}function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#usermod-settings")}function B(){window.open("/settings","_self")}function S(){"file:"==window.location.protocol&&(loc=!0,(locip=localStorage.getItem("locIp"))||(locip=prompt("File Mode. Please enter WLED IP!"),localStorage.setItem("locIp",locip))),ldS()}function check(e,n){var o=e.name.replace("[]","").substr(-3);if("number"==e.type&&"pin"==o.substr(0,3))for(var i=0;i<pins.length;i++)if(n!=pinO[i]){if(e.value==pins[i]||e.value<-1||e.value>39){e.style.color="red";break}e.style.color=e.value>33?"orange":"#fff"}}function getPins(e){if(isO(e))for(const[o,i]of Object.entries(e))if(isO(i))owner=o,getPins(i);else if("pin"==o.replace("[]","").substr(-3))if(Array.isArray(i))for(var n=0;n<i.length;n++)i[n]>=0&&(pins.push(i[n]),pinO.push(owner));else i>=0&&(pins.push(i),pinO.push(owner));else if(Array.isArray(i))for(n=0;n<i.length;n++)getPins(i[n])}function addField(e,n,o,i=!1){if(isO(o))for(const[n,i]of Object.entries(o))addField(e,n,i);else if(Array.isArray(o))for(var r=0;r<o.length;r++)addField(e,n,o[r],!0);else{var t,s;switch(typeof o){case"boolean":t="checkbox",s=o?'checked value="on"':"";break;case"number":t="number",s=`value="${parseInt(o,10)}"`;break;case"string":default:t="text",s=`value="${o}"`}"checkbox"==t&&(urows+=`<input type="hidden" name="${e}_${n}${i?"[]":""}" value="off">`),urows+=`${n}: <input type="${t}" name="${e}_${n}${i?"[]":""}" ${s} oninput="check(this,'${e}')"><br>`}}function ldS(){fetch((loc?"http://"+locip:"")+"/cfg.json",{method:"get"}).then(e=>(e.ok||(gId("lserr").style.display="inline"),e.json())).then(e=>{if(umCfg=e.um,getPins(e),urows="",isO(umCfg)){for(const[e,n]of Object.entries(umCfg))urows+=`<hr><h3>${e}</h3>`,addField(e,"unknown",n);gId("um").innerHTML=urows}}).catch((function(e){gId("lserr").style.display="inline",console.log(e)}))}function svS(e){e.preventDefault(),console.log(d.Sf),d.Sf.checkValidity()&&d.Sf.submit()}function GetV(){}
var owner,locip,urows,d=document,umCfg={},pins=[6,7,8,9,10,11],pinO=["reserved","reserved","reserved","reserved","reserved","reserved"],loc=!1;function gId(e){return d.getElementById(e)}function isO(e){return e&&"object"==typeof e&&!Array.isArray(e)}function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#usermod-settings")}function B(){window.open("/settings","_self")}function S(){"file:"==window.location.protocol&&(loc=!0,(locip=localStorage.getItem("locIp"))||(locip=prompt("File Mode. Please enter WLED IP!"),localStorage.setItem("locIp",locip))),ldS()}function check(e,o){var n=e.name.replace("[]","").substr(-3);if("number"==e.type&&"pin"==n.substr(0,3))for(var i=0;i<pins.length;i++)if(o!=pinO[i]){if(e.value==pins[i]||e.value<-1||e.value>39){e.style.color="red";break}e.style.color=e.value>33?"orange":"#fff"}}function getPins(e){if(isO(e))for(const[n,i]of Object.entries(e))if(isO(i))owner=n,getPins(i);else if("pin"==n.replace("[]","").substr(-3))if(Array.isArray(i))for(var o=0;o<i.length;o++)i[o]>=0&&(pins.push(i[o]),pinO.push(owner));else i>=0&&(pins.push(i),pinO.push(owner));else if(Array.isArray(i))for(o=0;o<i.length;o++)getPins(i[o])}function addField(e,o,n,i=!1){if(isO(n))for(const[o,i]of Object.entries(n))addField(e,o,i);else if(Array.isArray(n))for(var r=0;r<n.length;r++)addField(e,o,n[r],!0);else{var s,t;switch(typeof n){case"boolean":s="checkbox",t=n?'checked value="on"':"";break;case"number":s="number",t=`value="${parseInt(n,10)}"`;break;case"string":default:s="text",t=`value="${n}"`}"checkbox"==s&&(urows+=`<input type="hidden" name="${e}_${o}${i?"[]":""}" value="off">`),urows+=`${o}: <input type="${s}" name="${e}_${o}${i?"[]":""}" ${t} oninput="check(this,'${e}')"><br>`}}function ldS(){fetch((loc?"http://"+locip:"")+"/cfg.json",{method:"get"}).then(e=>(e.ok||(gId("lserr").style.display="inline"),e.json())).then(e=>{if(umCfg=e.um,getPins(e),urows="",isO(umCfg)){for(const[e,o]of Object.entries(umCfg))urows+=`<hr><h3>${e}</h3>`,addField(e,"unknown",o);""===urows&&(urows="No Usermods configuration found.<br>Press <i>Save</i> to initialize defaults.")}else urows="Usermods configuration not found.<br>Most likely no Usermods exist.<br>Press <i>Save</i> to initialize defaults.";gId("um").innerHTML=urows}).catch((function(e){gId("lserr").style.display="inline",console.log(e)}))}function svS(e){e.preventDefault(),console.log(d.Sf),d.Sf.checkValidity()&&d.Sf.submit()}function GetV(){}
</script>%CSS%%SCSS%</head><body onload="S()"><form
id="form_s" name="Sf" method="post" onsubmit="svS(event)"><div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div><button

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2105071
#define VERSION 2105081
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG