Fix for not honouring enabled state for PIR usermod. (#2090)
This commit is contained in:
parent
02b6d53544
commit
9ba7e5d567
@ -193,16 +193,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// pin retrieved from cfg.json (readFromConfig()) prior to running setup()
|
if (enabled) {
|
||||||
if (!pinManager.allocatePin(PIRsensorPin,false)) {
|
// pin retrieved from cfg.json (readFromConfig()) prior to running setup()
|
||||||
PIRsensorPin = -1; // allocation failed
|
if (PIRsensorPin >= 0 && pinManager.allocatePin(PIRsensorPin,false)) {
|
||||||
enabled = false;
|
// PIR Sensor mode INPUT_PULLUP
|
||||||
DEBUG_PRINTLN(F("PIRSensorSwitch pin allocation failed."));
|
pinMode(PIRsensorPin, INPUT_PULLUP);
|
||||||
} else {
|
|
||||||
// PIR Sensor mode INPUT_PULLUP
|
|
||||||
pinMode(PIRsensorPin, INPUT_PULLUP);
|
|
||||||
if (enabled) {
|
|
||||||
sensorPinState = digitalRead(PIRsensorPin);
|
sensorPinState = digitalRead(PIRsensorPin);
|
||||||
|
} else {
|
||||||
|
if (PIRsensorPin >= 0) DEBUG_PRINTLN(F("PIRSensorSwitch pin allocation failed."));
|
||||||
|
PIRsensorPin = -1; // allocation failed
|
||||||
|
enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initDone = true;
|
initDone = true;
|
||||||
@ -221,8 +221,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// only check sensors 10x/s
|
// only check sensors 4x/s
|
||||||
if (millis() - lastLoop < 100 || strip.isUpdating()) return;
|
if (!enabled || millis() - lastLoop < 250 || strip.isUpdating()) return;
|
||||||
lastLoop = millis();
|
lastLoop = millis();
|
||||||
|
|
||||||
if (!updatePIRsensorState()) {
|
if (!updatePIRsensorState()) {
|
||||||
@ -335,6 +335,7 @@ 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;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user