Merge pull request #95 from troyhacks/mdev

Fixes for animated staircase usermod
This commit is contained in:
Troy
2023-12-11 16:36:50 -05:00
committed by GitHub

View File

@@ -16,7 +16,7 @@ class Animated_Staircase : public Usermod {
/* configuration (available in API and stored in flash) */
bool enabled = false; // Enable this usermod
unsigned long segment_delay_ms = 150; // Time between switching each segment
unsigned long on_time_ms = 30000; // The time for the light to stay on
unsigned long on_time_ms = 5000; // The time for the light to stay on - TroyHacks: 5s for testing
int8_t topPIRorTriggerPin = -1; // disabled
int8_t bottomPIRorTriggerPin = -1; // disabled
int8_t topEchoPin = -1; // disabled
@@ -161,28 +161,37 @@ class Animated_Staircase : public Usermod {
if ((millis() - lastScanTime) > scanDelay) {
lastScanTime = millis();
bottomSensorRead = bottomSensorWrite ||
(!useUSSensorBottom ?
(bottomPIRorTriggerPin<0 ? false : digitalRead(bottomPIRorTriggerPin)) :
ultrasoundRead(bottomPIRorTriggerPin, bottomEchoPin, bottomMaxDist*59) // cm to us
);
topSensorRead = topSensorWrite ||
(!useUSSensorTop ?
(topPIRorTriggerPin<0 ? false : digitalRead(topPIRorTriggerPin)) :
ultrasoundRead(topPIRorTriggerPin, topEchoPin, topMaxDist*59) // cm to us
);
if (useUSSensorBottom) {
bottomSensorRead = ultrasoundRead(bottomPIRorTriggerPin, bottomEchoPin, bottomMaxDist*59); // US
} else if (bottomPIRorTriggerPin > 0) {
bottomSensorRead = digitalRead(bottomPIRorTriggerPin); // PIR
} else {
bottomSensorRead = false; // DUNNO
}
if (useUSSensorTop) {
topSensorRead = ultrasoundRead(topPIRorTriggerPin, topEchoPin, topMaxDist*59); // US
} else if (topPIRorTriggerPin > 0) {
topSensorRead = digitalRead(topPIRorTriggerPin); // PIR
} else {
topSensorRead = false; // DUNNO
}
if (bottomSensorRead != bottomSensorState) {
bottomSensorState = bottomSensorRead; // change previous state
sensorChanged = true;
publishMqtt(true, bottomSensorState ? "on" : "off");
#ifndef WLED_DISABLE_MQTT
publishMqtt(true, bottomSensorState ? "on" : "off");
#endif
DEBUG_PRINTLN(F("Bottom sensor changed."));
}
if (topSensorRead != topSensorState) {
topSensorState = topSensorRead; // change previous state
sensorChanged = true;
publishMqtt(false, topSensorState ? "on" : "off");
#ifndef WLED_DISABLE_MQTT
publishMqtt(false, topSensorState ? "on" : "off");
#endif#endif
DEBUG_PRINTLN(F("Top sensor changed."));
}
@@ -224,7 +233,13 @@ class Animated_Staircase : public Usermod {
if (bottomSensorState || topSensorState) return;
// Swipe OFF in the direction of the last sensor detection
swipe = lastSensor;
// WLED-MM/TroyHacks: This should follow you up/dowm the stairs.
if (lastSensor == SWIPE_UP) {
swipe = SWIPE_DOWN;
} else {
swipe = SWIPE_UP;
}
on = false;
DEBUG_PRINT(F("OFF -> Swipe "));