From 246f0b21fd10b7912623fdc9048433df4f2bcb89 Mon Sep 17 00:00:00 2001 From: Jason Cobb Date: Sat, 26 Aug 2023 22:19:52 -0500 Subject: [PATCH] staircase toggle power on/off option bool --- .../Animated_Staircase/Animated_Staircase.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/usermods/Animated_Staircase/Animated_Staircase.h b/usermods/Animated_Staircase/Animated_Staircase.h index 151cf1d4..6d02dce7 100644 --- a/usermods/Animated_Staircase/Animated_Staircase.h +++ b/usermods/Animated_Staircase/Animated_Staircase.h @@ -25,6 +25,7 @@ class Animated_Staircase : public Usermod { bool useUSSensorBottom = false; // using PIR or UltraSound sensor? unsigned int topMaxDist = 50; // default maximum measured distance in cm, top unsigned int bottomMaxDist = 50; // default maximum measured distance in cm, bottom + bool togglePower = false; // toggle power on/off with staircase on/off /* runtime variables */ bool initDone = false; @@ -90,7 +91,8 @@ class Animated_Staircase : public Usermod { static const char _bottomEcho_pin[]; static const char _topEchoCm[]; static const char _bottomEchoCm[]; - + static const char _togglePower[]; + void publishMqtt(bool bottom, const char* state) { #ifndef WLED_DISABLE_MQTT //Check if MQTT Connected, otherwise it will crash the 8266 @@ -196,6 +198,7 @@ class Animated_Staircase : public Usermod { if (on) { lastSensor = topSensorRead; } else { + if (togglePower && onIndex == offIndex && offMode) toggleOnOff(); // toggle power on if off // If the bottom sensor triggered, we need to swipe up, ON swipe = bottomSensorRead; @@ -249,7 +252,10 @@ class Animated_Staircase : public Usermod { offIndex = MAX(onIndex, offIndex - 1); } } - if (oldOn != onIndex || oldOff != offIndex) updateSegments(); // reduce the number of updates to necessary ones + if (oldOn != onIndex || oldOff != offIndex) { + updateSegments(); // reduce the number of updates to necessary ones + if (togglePower && onIndex == offIndex && !offMode && !on) toggleOnOff(); // toggle power off for all segments off + } } } @@ -295,6 +301,7 @@ class Animated_Staircase : public Usermod { strip.setTransition(segment_delay_ms/100); strip.trigger(); } else { + if (togglePower && !on && offMode) toggleOnOff(); // toggle power on if off // Restore segment options for (int i = 0; i <= strip.getLastActiveSegmentId(); i++) { Segment &seg = strip.getSegment(i); @@ -444,6 +451,7 @@ class Animated_Staircase : public Usermod { staircase[FPSTR(_bottomEcho_pin)] = useUSSensorBottom ? bottomEchoPin : -1; staircase[FPSTR(_topEchoCm)] = topMaxDist; staircase[FPSTR(_bottomEchoCm)] = bottomMaxDist; + staircase[FPSTR(_togglePower)] = togglePower; DEBUG_PRINTLN(F("Staircase config saved.")); } @@ -488,6 +496,8 @@ class Animated_Staircase : public Usermod { bottomMaxDist = top[FPSTR(_bottomEchoCm)] | bottomMaxDist; bottomMaxDist = min(150,max(30,(int)bottomMaxDist)); // max distance ~1.5m (a lag of 9ms may be expected) + togglePower = top[FPSTR(_togglePower)] | togglePower; // staircase toggles power on/off + DEBUG_PRINT(FPSTR(_name)); if (!initDone) { // first run: reading from cfg.json @@ -511,7 +521,7 @@ class Animated_Staircase : public Usermod { if (changed) setup(); } // use "return !top["newestParameter"].isNull();" when updating Usermod with new features - return true; + return !top[FPSTR(_togglePower)].isNull(); } /* @@ -551,3 +561,4 @@ const char Animated_Staircase::_bottomPIRorTrigger_pin[] PROGMEM = "bottomPIR const char Animated_Staircase::_bottomEcho_pin[] PROGMEM = "bottomEcho_pin"; const char Animated_Staircase::_topEchoCm[] PROGMEM = "top-dist-cm"; const char Animated_Staircase::_bottomEchoCm[] PROGMEM = "bottom-dist-cm"; +const char Animated_Staircase::_togglePower[] PROGMEM = "toggle-on-off";