mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-11 07:32:14 +00:00
Dection Sensor module duty cycle interval optimization (#2723)
* WIP * Updates * Move it out of the macro guard so portduino can build * Changes from feedback * Use minimum_broadcast_secs as interval if we just broadcasted to avoid wasting cpu cycles * Fmt * Merge conflict resolution boogered me up * Missed a spot
This commit is contained in:
parent
144dfe9805
commit
03fe4c629a
@ -18,9 +18,10 @@ int32_t DetectionSensorModule::runOnce()
|
||||
*/
|
||||
// moduleConfig.detection_sensor.enabled = true;
|
||||
// moduleConfig.detection_sensor.monitor_pin = 10; // WisBlock PIR IO6
|
||||
// moduleConfig.detection_sensor.minimum_broadcast_secs = 60;
|
||||
// moduleConfig.detection_sensor.monitor_pin = 21; // WisBlock RAK12013 Radar IO6
|
||||
// moduleConfig.detection_sensor.minimum_broadcast_secs = 30;
|
||||
// moduleConfig.detection_sensor.state_broadcast_secs = 120;
|
||||
// moduleConfig.detection_sensor.detection_triggered_high = false;
|
||||
// moduleConfig.detection_sensor.detection_triggered_high = true;
|
||||
// strcpy(moduleConfig.detection_sensor.name, "Motion");
|
||||
|
||||
if (moduleConfig.detection_sensor.enabled == false)
|
||||
@ -40,10 +41,12 @@ int32_t DetectionSensorModule::runOnce()
|
||||
return DELAYED_INTERVAL;
|
||||
}
|
||||
|
||||
// LOG_DEBUG("Detection Sensor Module: Current pin state: %i\n", digitalRead(moduleConfig.detection_sensor.monitor_pin));
|
||||
|
||||
if ((millis() - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.detection_sensor.minimum_broadcast_secs) &&
|
||||
hasDetectionEvent()) {
|
||||
sendDetectionMessage();
|
||||
return DELAYED_INTERVAL;
|
||||
return moduleConfig.detection_sensor.minimum_broadcast_secs;
|
||||
}
|
||||
// Even if we haven't detected an event, broadcast our current state to the mesh on the scheduled interval as a sort
|
||||
// of heartbeat. We only do this if the minimum broadcast interval is greater than zero, otherwise we'll only broadcast state
|
||||
@ -51,7 +54,7 @@ int32_t DetectionSensorModule::runOnce()
|
||||
else if (moduleConfig.detection_sensor.state_broadcast_secs > 0 &&
|
||||
(millis() - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.detection_sensor.state_broadcast_secs)) {
|
||||
sendCurrentStateMessage();
|
||||
return DELAYED_INTERVAL;
|
||||
return moduleConfig.detection_sensor.minimum_broadcast_secs;
|
||||
}
|
||||
return GPIO_POLLING_INTERVAL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user