Merge pull request #95 from troyhacks/mdev
Fixes for animated staircase usermod
This commit is contained in:
@@ -16,7 +16,7 @@ class Animated_Staircase : public Usermod {
|
|||||||
/* configuration (available in API and stored in flash) */
|
/* configuration (available in API and stored in flash) */
|
||||||
bool enabled = false; // Enable this usermod
|
bool enabled = false; // Enable this usermod
|
||||||
unsigned long segment_delay_ms = 150; // Time between switching each segment
|
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 topPIRorTriggerPin = -1; // disabled
|
||||||
int8_t bottomPIRorTriggerPin = -1; // disabled
|
int8_t bottomPIRorTriggerPin = -1; // disabled
|
||||||
int8_t topEchoPin = -1; // disabled
|
int8_t topEchoPin = -1; // disabled
|
||||||
@@ -161,28 +161,37 @@ class Animated_Staircase : public Usermod {
|
|||||||
if ((millis() - lastScanTime) > scanDelay) {
|
if ((millis() - lastScanTime) > scanDelay) {
|
||||||
lastScanTime = millis();
|
lastScanTime = millis();
|
||||||
|
|
||||||
bottomSensorRead = bottomSensorWrite ||
|
if (useUSSensorBottom) {
|
||||||
(!useUSSensorBottom ?
|
bottomSensorRead = ultrasoundRead(bottomPIRorTriggerPin, bottomEchoPin, bottomMaxDist*59); // US
|
||||||
(bottomPIRorTriggerPin<0 ? false : digitalRead(bottomPIRorTriggerPin)) :
|
} else if (bottomPIRorTriggerPin > 0) {
|
||||||
ultrasoundRead(bottomPIRorTriggerPin, bottomEchoPin, bottomMaxDist*59) // cm to us
|
bottomSensorRead = digitalRead(bottomPIRorTriggerPin); // PIR
|
||||||
);
|
} else {
|
||||||
topSensorRead = topSensorWrite ||
|
bottomSensorRead = false; // DUNNO
|
||||||
(!useUSSensorTop ?
|
}
|
||||||
(topPIRorTriggerPin<0 ? false : digitalRead(topPIRorTriggerPin)) :
|
|
||||||
ultrasoundRead(topPIRorTriggerPin, topEchoPin, topMaxDist*59) // cm to us
|
if (useUSSensorTop) {
|
||||||
);
|
topSensorRead = ultrasoundRead(topPIRorTriggerPin, topEchoPin, topMaxDist*59); // US
|
||||||
|
} else if (topPIRorTriggerPin > 0) {
|
||||||
|
topSensorRead = digitalRead(topPIRorTriggerPin); // PIR
|
||||||
|
} else {
|
||||||
|
topSensorRead = false; // DUNNO
|
||||||
|
}
|
||||||
|
|
||||||
if (bottomSensorRead != bottomSensorState) {
|
if (bottomSensorRead != bottomSensorState) {
|
||||||
bottomSensorState = bottomSensorRead; // change previous state
|
bottomSensorState = bottomSensorRead; // change previous state
|
||||||
sensorChanged = true;
|
sensorChanged = true;
|
||||||
publishMqtt(true, bottomSensorState ? "on" : "off");
|
#ifndef WLED_DISABLE_MQTT
|
||||||
|
publishMqtt(true, bottomSensorState ? "on" : "off");
|
||||||
|
#endif
|
||||||
DEBUG_PRINTLN(F("Bottom sensor changed."));
|
DEBUG_PRINTLN(F("Bottom sensor changed."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topSensorRead != topSensorState) {
|
if (topSensorRead != topSensorState) {
|
||||||
topSensorState = topSensorRead; // change previous state
|
topSensorState = topSensorRead; // change previous state
|
||||||
sensorChanged = true;
|
sensorChanged = true;
|
||||||
publishMqtt(false, topSensorState ? "on" : "off");
|
#ifndef WLED_DISABLE_MQTT
|
||||||
|
publishMqtt(false, topSensorState ? "on" : "off");
|
||||||
|
#endif#endif
|
||||||
DEBUG_PRINTLN(F("Top sensor changed."));
|
DEBUG_PRINTLN(F("Top sensor changed."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +233,13 @@ class Animated_Staircase : public Usermod {
|
|||||||
if (bottomSensorState || topSensorState) return;
|
if (bottomSensorState || topSensorState) return;
|
||||||
|
|
||||||
// Swipe OFF in the direction of the last sensor detection
|
// 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;
|
on = false;
|
||||||
|
|
||||||
DEBUG_PRINT(F("OFF -> Swipe "));
|
DEBUG_PRINT(F("OFF -> Swipe "));
|
||||||
|
|||||||
Reference in New Issue
Block a user