staircase toggle power on/off option bool
This commit is contained in:
parent
fc1dd2daac
commit
246f0b21fd
@ -25,6 +25,7 @@ class Animated_Staircase : public Usermod {
|
|||||||
bool useUSSensorBottom = false; // using PIR or UltraSound sensor?
|
bool useUSSensorBottom = false; // using PIR or UltraSound sensor?
|
||||||
unsigned int topMaxDist = 50; // default maximum measured distance in cm, top
|
unsigned int topMaxDist = 50; // default maximum measured distance in cm, top
|
||||||
unsigned int bottomMaxDist = 50; // default maximum measured distance in cm, bottom
|
unsigned int bottomMaxDist = 50; // default maximum measured distance in cm, bottom
|
||||||
|
bool togglePower = false; // toggle power on/off with staircase on/off
|
||||||
|
|
||||||
/* runtime variables */
|
/* runtime variables */
|
||||||
bool initDone = false;
|
bool initDone = false;
|
||||||
@ -90,7 +91,8 @@ class Animated_Staircase : public Usermod {
|
|||||||
static const char _bottomEcho_pin[];
|
static const char _bottomEcho_pin[];
|
||||||
static const char _topEchoCm[];
|
static const char _topEchoCm[];
|
||||||
static const char _bottomEchoCm[];
|
static const char _bottomEchoCm[];
|
||||||
|
static const char _togglePower[];
|
||||||
|
|
||||||
void publishMqtt(bool bottom, const char* state) {
|
void publishMqtt(bool bottom, const char* state) {
|
||||||
#ifndef WLED_DISABLE_MQTT
|
#ifndef WLED_DISABLE_MQTT
|
||||||
//Check if MQTT Connected, otherwise it will crash the 8266
|
//Check if MQTT Connected, otherwise it will crash the 8266
|
||||||
@ -196,6 +198,7 @@ class Animated_Staircase : public Usermod {
|
|||||||
if (on) {
|
if (on) {
|
||||||
lastSensor = topSensorRead;
|
lastSensor = topSensorRead;
|
||||||
} else {
|
} else {
|
||||||
|
if (togglePower && onIndex == offIndex && offMode) toggleOnOff(); // toggle power on if off
|
||||||
// If the bottom sensor triggered, we need to swipe up, ON
|
// If the bottom sensor triggered, we need to swipe up, ON
|
||||||
swipe = bottomSensorRead;
|
swipe = bottomSensorRead;
|
||||||
|
|
||||||
@ -249,7 +252,10 @@ class Animated_Staircase : public Usermod {
|
|||||||
offIndex = MAX(onIndex, offIndex - 1);
|
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.setTransition(segment_delay_ms/100);
|
||||||
strip.trigger();
|
strip.trigger();
|
||||||
} else {
|
} else {
|
||||||
|
if (togglePower && !on && offMode) toggleOnOff(); // toggle power on if off
|
||||||
// Restore segment options
|
// Restore segment options
|
||||||
for (int i = 0; i <= strip.getLastActiveSegmentId(); i++) {
|
for (int i = 0; i <= strip.getLastActiveSegmentId(); i++) {
|
||||||
Segment &seg = strip.getSegment(i);
|
Segment &seg = strip.getSegment(i);
|
||||||
@ -444,6 +451,7 @@ class Animated_Staircase : public Usermod {
|
|||||||
staircase[FPSTR(_bottomEcho_pin)] = useUSSensorBottom ? bottomEchoPin : -1;
|
staircase[FPSTR(_bottomEcho_pin)] = useUSSensorBottom ? bottomEchoPin : -1;
|
||||||
staircase[FPSTR(_topEchoCm)] = topMaxDist;
|
staircase[FPSTR(_topEchoCm)] = topMaxDist;
|
||||||
staircase[FPSTR(_bottomEchoCm)] = bottomMaxDist;
|
staircase[FPSTR(_bottomEchoCm)] = bottomMaxDist;
|
||||||
|
staircase[FPSTR(_togglePower)] = togglePower;
|
||||||
DEBUG_PRINTLN(F("Staircase config saved."));
|
DEBUG_PRINTLN(F("Staircase config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,6 +496,8 @@ class Animated_Staircase : public Usermod {
|
|||||||
bottomMaxDist = top[FPSTR(_bottomEchoCm)] | bottomMaxDist;
|
bottomMaxDist = top[FPSTR(_bottomEchoCm)] | bottomMaxDist;
|
||||||
bottomMaxDist = min(150,max(30,(int)bottomMaxDist)); // max distance ~1.5m (a lag of 9ms may be expected)
|
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));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
// first run: reading from cfg.json
|
// first run: reading from cfg.json
|
||||||
@ -511,7 +521,7 @@ class Animated_Staircase : public Usermod {
|
|||||||
if (changed) setup();
|
if (changed) setup();
|
||||||
}
|
}
|
||||||
// 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(_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::_bottomEcho_pin[] PROGMEM = "bottomEcho_pin";
|
||||||
const char Animated_Staircase::_topEchoCm[] PROGMEM = "top-dist-cm";
|
const char Animated_Staircase::_topEchoCm[] PROGMEM = "top-dist-cm";
|
||||||
const char Animated_Staircase::_bottomEchoCm[] PROGMEM = "bottom-dist-cm";
|
const char Animated_Staircase::_bottomEchoCm[] PROGMEM = "bottom-dist-cm";
|
||||||
|
const char Animated_Staircase::_togglePower[] PROGMEM = "toggle-on-off";
|
||||||
|
Loading…
Reference in New Issue
Block a user