Merge pull request #2093 from blazoncek/PIR-sensor-update
Added PIR option to trigger only if WLED is off.
This commit is contained in:
commit
b058fb8db4
@ -76,6 +76,9 @@ private:
|
|||||||
bool m_nightTimeOnly = false;
|
bool m_nightTimeOnly = false;
|
||||||
// flag to send MQTT message only (assuming it is enabled)
|
// flag to send MQTT message only (assuming it is enabled)
|
||||||
bool m_mqttOnly = false;
|
bool m_mqttOnly = false;
|
||||||
|
// flag to enable triggering only if WLED is initially off (LEDs are not on, preventing running effect being overwritten by PIR)
|
||||||
|
bool m_offOnly = false;
|
||||||
|
bool PIRtriggered = false;
|
||||||
|
|
||||||
unsigned long lastLoop = 0;
|
unsigned long lastLoop = 0;
|
||||||
|
|
||||||
@ -87,6 +90,7 @@ private:
|
|||||||
static const char _offPreset[];
|
static const char _offPreset[];
|
||||||
static const char _nightTime[];
|
static const char _nightTime[];
|
||||||
static const char _mqttOnly[];
|
static const char _mqttOnly[];
|
||||||
|
static const char _offOnly[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if it is daytime
|
* check if it is daytime
|
||||||
@ -118,6 +122,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
void switchStrip(bool switchOn)
|
void switchStrip(bool switchOn)
|
||||||
{
|
{
|
||||||
|
PIRtriggered = switchOn;
|
||||||
if (switchOn && m_onPreset) {
|
if (switchOn && m_onPreset) {
|
||||||
applyPreset(m_onPreset);
|
applyPreset(m_onPreset);
|
||||||
} else if (!switchOn && m_offPreset) {
|
} else if (!switchOn && m_offPreset) {
|
||||||
@ -222,7 +227,7 @@ public:
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// only check sensors 4x/s
|
// only check sensors 4x/s
|
||||||
if (!enabled || millis() - lastLoop < 250 || strip.isUpdating()) return;
|
if (!enabled || millis() - lastLoop < 250 || strip.isUpdating() || (m_offOnly && bri && !PIRtriggered)) return;
|
||||||
lastLoop = millis();
|
lastLoop = millis();
|
||||||
|
|
||||||
if (!updatePIRsensorState()) {
|
if (!updatePIRsensorState()) {
|
||||||
@ -313,6 +318,7 @@ public:
|
|||||||
top[FPSTR(_offPreset)] = m_offPreset;
|
top[FPSTR(_offPreset)] = m_offPreset;
|
||||||
top[FPSTR(_nightTime)] = m_nightTimeOnly;
|
top[FPSTR(_nightTime)] = m_nightTimeOnly;
|
||||||
top[FPSTR(_mqttOnly)] = m_mqttOnly;
|
top[FPSTR(_mqttOnly)] = m_mqttOnly;
|
||||||
|
top[FPSTR(_offOnly)] = m_offOnly;
|
||||||
DEBUG_PRINTLN(F("PIR config saved."));
|
DEBUG_PRINTLN(F("PIR config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +341,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
PIRsensorPin = top["pin"] | PIRsensorPin;
|
PIRsensorPin = top["pin"] | PIRsensorPin;
|
||||||
// PIRsensorPin = min(39,max(-1,(int)PIRsensorPin)); // check bounds
|
|
||||||
|
|
||||||
enabled = top[FPSTR(_enabled)] | enabled;
|
enabled = top[FPSTR(_enabled)] | enabled;
|
||||||
|
|
||||||
@ -349,6 +354,7 @@ public:
|
|||||||
|
|
||||||
m_nightTimeOnly = top[FPSTR(_nightTime)] | m_nightTimeOnly;
|
m_nightTimeOnly = top[FPSTR(_nightTime)] | m_nightTimeOnly;
|
||||||
m_mqttOnly = top[FPSTR(_mqttOnly)] | m_mqttOnly;
|
m_mqttOnly = top[FPSTR(_mqttOnly)] | m_mqttOnly;
|
||||||
|
m_offOnly = top[FPSTR(_offOnly)] | m_offOnly;
|
||||||
|
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
@ -376,7 +382,7 @@ public:
|
|||||||
DEBUG_PRINTLN(F(" config (re)loaded."));
|
DEBUG_PRINTLN(F(" config (re)loaded."));
|
||||||
}
|
}
|
||||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
return true;
|
return !top[FPSTR(_offOnly)].isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -397,3 +403,4 @@ const char PIRsensorSwitch::_onPreset[] PROGMEM = "on-preset";
|
|||||||
const char PIRsensorSwitch::_offPreset[] PROGMEM = "off-preset";
|
const char PIRsensorSwitch::_offPreset[] PROGMEM = "off-preset";
|
||||||
const char PIRsensorSwitch::_nightTime[] PROGMEM = "nighttime-only";
|
const char PIRsensorSwitch::_nightTime[] PROGMEM = "nighttime-only";
|
||||||
const char PIRsensorSwitch::_mqttOnly[] PROGMEM = "mqtt-only";
|
const char PIRsensorSwitch::_mqttOnly[] PROGMEM = "mqtt-only";
|
||||||
|
const char PIRsensorSwitch::_offOnly[] PROGMEM = "off-only";
|
||||||
|
Loading…
Reference in New Issue
Block a user