Skip to content

Commit 4d429fa

Browse files
authored
Fix bug where loop() is run for ALL sensors after an interrupt (#506)
`_last_interrupt_pin` should be reset AFTER the for loop has finished running over all the sensors, not DURING the for loop. I have a node with 1x SensorDoor and 1x SensorDS18b20 (with 4 children) and before this fix, every time the SensorDoor changed state the node would also measure and report all the DS18B20 before going back to sleep. After this fix, the node reports SensorDoor only, then goes straight back to sleep.
1 parent 00a8ba2 commit 4d429fa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

nodemanager/Node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ void NodeManager::loop() {
265265
if (_last_interrupt_pin != -1 && sensor->getInterruptPin() == _last_interrupt_pin) {
266266
// call the sensor interrupt() and then loop(), provided the interrupt has been "accepted" by interrupt()
267267
if (sensor->interrupt()) sensor->loop(nullptr);
268-
// reset the last interrupt pin
269-
_last_interrupt_pin = -1;
270268
}
271269
else if (_last_interrupt_pin == -1) {
272270
#endif
@@ -276,6 +274,8 @@ void NodeManager::loop() {
276274
}
277275
#endif
278276
}
277+
// reset the last interrupt pin
278+
_last_interrupt_pin = -1;
279279
#if NODEMANAGER_POWER_MANAGER == ON
280280
// turn off the pin powering all the sensors
281281
powerOff();

0 commit comments

Comments
 (0)