-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Added support for inverting logic of PIR pins #5300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skykingjwc
wants to merge
1
commit into
wled:main
Choose a base branch
from
skykingjwc:AnimatedStaircasePIRInvert
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ class Animated_Staircase : public Usermod { | |
| 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 | ||
| bool topAPinInvert = false; // invert output of top sensor | ||
| bool bottomAPinInvert = false; // invert output of bottom sensor | ||
|
|
||
| /* runtime variables */ | ||
| bool initDone = false; | ||
|
|
@@ -91,6 +93,8 @@ class Animated_Staircase : public Usermod { | |
| static const char _topEchoCm[]; | ||
| static const char _bottomEchoCm[]; | ||
| static const char _togglePower[]; | ||
| static const char _topPIRorTrigger_pin_invert[]; | ||
| static const char _bottomPIRorTrigger_pin_invert[]; | ||
|
|
||
| void publishMqtt(bool bottom, const char* state) { | ||
| #ifndef WLED_DISABLE_MQTT | ||
|
|
@@ -156,6 +160,12 @@ class Animated_Staircase : public Usermod { | |
| return pulseIn(echoPin, HIGH, maxTimeUs) > 0; | ||
| } | ||
|
|
||
| bool readPIRPin(int8_t pin, bool invert) { | ||
| if (pin < 0) return false; | ||
| bool v = digitalRead(pin); | ||
| return invert ? !v : v; | ||
| } | ||
|
|
||
| bool checkSensors() { | ||
| bool sensorChanged = false; | ||
|
|
||
|
|
@@ -164,15 +174,16 @@ class Animated_Staircase : public Usermod { | |
|
|
||
| bottomSensorRead = bottomSensorWrite || | ||
| (!useUSSensorBottom ? | ||
| (bottomPIRorTriggerPin<0 ? false : digitalRead(bottomPIRorTriggerPin)) : | ||
| (bottomPIRorTriggerPin<0 ? false : readPIRPin(bottomPIRorTriggerPin, bottomAPinInvert)) : | ||
| ultrasoundRead(bottomPIRorTriggerPin, bottomEchoPin, bottomMaxDist*59) // cm to us | ||
| ); | ||
| topSensorRead = topSensorWrite || | ||
| (!useUSSensorTop ? | ||
| (topPIRorTriggerPin<0 ? false : digitalRead(topPIRorTriggerPin)) : | ||
| (topPIRorTriggerPin<0 ? false : readPIRPin(topPIRorTriggerPin, topAPinInvert)) : | ||
| ultrasoundRead(topPIRorTriggerPin, topEchoPin, topMaxDist*59) // cm to us | ||
| ); | ||
|
|
||
|
|
||
| if (bottomSensorRead != bottomSensorState) { | ||
| bottomSensorState = bottomSensorRead; // change previous state | ||
| sensorChanged = true; | ||
|
|
@@ -451,6 +462,8 @@ class Animated_Staircase : public Usermod { | |
| staircase[FPSTR(_topEchoCm)] = topMaxDist; | ||
| staircase[FPSTR(_bottomEchoCm)] = bottomMaxDist; | ||
| staircase[FPSTR(_togglePower)] = togglePower; | ||
| staircase[FPSTR(_topPIRorTrigger_pin_invert)] = topAPinInvert; | ||
| staircase[FPSTR(_bottomPIRorTrigger_pin_invert)] = bottomAPinInvert; | ||
| DEBUG_PRINTLN(F("Staircase config saved.")); | ||
| } | ||
|
|
||
|
|
@@ -462,10 +475,14 @@ class Animated_Staircase : public Usermod { | |
| bool readFromConfig(JsonObject& root) { | ||
| bool oldUseUSSensorTop = useUSSensorTop; | ||
| bool oldUseUSSensorBottom = useUSSensorBottom; | ||
| bool oldTopAPinInvert = topAPinInvert; | ||
| bool oldBottomAPinInvert = bottomAPinInvert; | ||
| int8_t oldTopAPin = topPIRorTriggerPin; | ||
| int8_t oldTopBPin = topEchoPin; | ||
| int8_t oldBottomAPin = bottomPIRorTriggerPin; | ||
| int8_t oldBottomBPin = bottomEchoPin; | ||
|
|
||
|
|
||
|
|
||
| JsonObject top = root[FPSTR(_name)]; | ||
| if (top.isNull()) { | ||
|
|
@@ -485,10 +502,13 @@ class Animated_Staircase : public Usermod { | |
| useUSSensorTop = top[FPSTR(_useTopUltrasoundSensor)] | useUSSensorTop; | ||
| topPIRorTriggerPin = top[FPSTR(_topPIRorTrigger_pin)] | topPIRorTriggerPin; | ||
| topEchoPin = top[FPSTR(_topEcho_pin)] | topEchoPin; | ||
| topAPinInvert = top[FPSTR(_topPIRorTrigger_pin_invert)] | topAPinInvert; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation |
||
|
|
||
|
|
||
| useUSSensorBottom = top[FPSTR(_useBottomUltrasoundSensor)] | useUSSensorBottom; | ||
| bottomPIRorTriggerPin = top[FPSTR(_bottomPIRorTrigger_pin)] | bottomPIRorTriggerPin; | ||
| bottomEchoPin = top[FPSTR(_bottomEcho_pin)] | bottomEchoPin; | ||
| bottomAPinInvert = top[FPSTR(_bottomPIRorTrigger_pin_invert)] | bottomAPinInvert; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation |
||
|
|
||
| topMaxDist = top[FPSTR(_topEchoCm)] | topMaxDist; | ||
| topMaxDist = min(150,max(30,(int)topMaxDist)); // max distance ~1.5m (a lag of 9ms may be expected) | ||
|
|
@@ -554,9 +574,11 @@ const char Animated_Staircase::_segmentDelay[] PROGMEM = "segment-d | |
| const char Animated_Staircase::_onTime[] PROGMEM = "on-time-s"; | ||
| const char Animated_Staircase::_useTopUltrasoundSensor[] PROGMEM = "useTopUltrasoundSensor"; | ||
| const char Animated_Staircase::_topPIRorTrigger_pin[] PROGMEM = "topPIRorTrigger_pin"; | ||
| const char Animated_Staircase::_topPIRorTrigger_pin_invert[] PROGMEM = "topPIRorTrigger_pin_invert"; | ||
| const char Animated_Staircase::_topEcho_pin[] PROGMEM = "topEcho_pin"; | ||
| const char Animated_Staircase::_useBottomUltrasoundSensor[] PROGMEM = "useBottomUltrasoundSensor"; | ||
| const char Animated_Staircase::_bottomPIRorTrigger_pin[] PROGMEM = "bottomPIRorTrigger_pin"; | ||
| const char Animated_Staircase::_bottomPIRorTrigger_pin_invert[] PROGMEM = "bottomPIRorTrigger_pin_invert"; | ||
| 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"; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove added blank lines (several places)