Skip to content

Commit

Permalink
SensorInterrupt Enhancements (#138 #29)
Browse files Browse the repository at this point in the history
  • Loading branch information
user2684 committed Mar 25, 2018
1 parent 31e653b commit 58fc106
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions NodeManagerLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ class SensorInterrupt: public Sensor {
void setInitial(int value);
// [105] Set active state (default: HIGH)
void setActiveState(int value);
// [106] Set armed, if false the sensor will not trigger until armed (default: true)
void setArmed(bool value);
#if FEATURE_TIME == ON
// [107] when keeping track of the time, trigger only after X consecutive interrupts within the same minute (default: 1)
void setThreshold(int value);
#endif
// define what to do at each stage of the sketch
void onSetup();
void onLoop(Child* child);
Expand All @@ -940,6 +946,12 @@ class SensorInterrupt: public Sensor {
int _mode = CHANGE;
int _initial = HIGH;
int _active_state = HIGH;
bool _armed = true;
#if FEATURE_TIME == ON
int _threshold = 1;
int _counter = 0;
int _current_minute = minute();
#endif
};

/*
Expand Down
22 changes: 22 additions & 0 deletions NodeManagerLibrary.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,15 @@ void SensorInterrupt::setInitial(int value) {
void SensorInterrupt::setActiveState(int value) {
_active_state = value;
}
void SensorInterrupt::setArmed(bool value) {
_armed = value;
}
#if FEATURE_TIME == ON
void SensorInterrupt::setThreshold(int value) {
_threshold = value;
}
#endif


// what to do during setup
void SensorInterrupt::onSetup() {
Expand All @@ -1556,6 +1565,12 @@ void SensorInterrupt::onReceive(MyMessage* message) {

// what to do when receiving an interrupt
void SensorInterrupt::onInterrupt() {
#if FEATURE_TIME == ON
// if this interrupt came in a new minute, reset the counter
if (minute() != _current_minute) _counter = 0;
// increase the counter
_counter = _counter + 1;
#endif
Child* child = children.get(1);
// wait to ensure the the input is not floating
if (_debounce > 0) _node->sleepOrWait(_debounce);
Expand All @@ -1574,6 +1589,11 @@ void SensorInterrupt::onInterrupt() {
Serial.print(F(" V="));
Serial.println(value);
#endif
if (! _armed) return;
#if FEATURE_TIME == ON
// report only when there are at least _threshold triggers
if (_counter < _threshold) return;
#endif
((ChildInt*)child)->setValueInt(value);
// allow the signal to be restored to its normal value
if (_trigger_time > 0) _node->sleepOrWait(_trigger_time);
Expand Down Expand Up @@ -4101,6 +4121,8 @@ void SensorConfiguration::onReceive(MyMessage* message) {
case 103: custom_sensor->setTriggerTime(request.getValueInt()); break;
case 104: custom_sensor->setInitial(request.getValueInt()); break;
case 105: custom_sensor->setActiveState(request.getValueInt()); break;
case 106: custom_sensor->setArmed(request.getValueInt()); break;
case 107: custom_sensor->setThreshold(request.getValueInt()); break;
default: return;
}
}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ Each sensor class exposes additional methods.
void setInitial(int value);
// [105] Set active state (default: HIGH)
void setActiveState(int value);
// [106] Set armed, if false the sensor will not trigger until armed (default: true)
void setArmed(bool value);
#if FEATURE_TIME == ON
// [107] when keeping track of the time, trigger only after X consecutive interrupts within the same minute (default: 1)
void setThreshold(int value);
#endif
~~~
* SensorDs18b20
Expand Down

0 comments on commit 58fc106

Please sign in to comment.