mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Fix watchdog code in repeater
This commit is contained in:
parent
9df34e09d0
commit
53ff4ed57f
3 changed files with 29 additions and 6 deletions
|
|
@ -29,6 +29,10 @@ void setup() {
|
|||
|
||||
board.begin();
|
||||
|
||||
#ifdef HAS_EX_WATCHDOG
|
||||
ex_watchdog.begin();
|
||||
#endif
|
||||
|
||||
#if defined(MESH_DEBUG) && defined(NRF52_PLATFORM)
|
||||
// give some extra time for serial to settle so
|
||||
// boot debug messages can be seen on terminal
|
||||
|
|
@ -134,11 +138,24 @@ void loop() {
|
|||
#endif
|
||||
rtc_clock.tick();
|
||||
|
||||
#ifdef HAS_EX_WATCHDOG
|
||||
ex_watchdog.loop();
|
||||
#endif
|
||||
if (the_mesh.getNodePrefs()->powersaving_enabled && !the_mesh.hasPendingWork()) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#ifdef HAS_EX_WATCHDOG
|
||||
uint32_t sleep_interval = ex_watchdog.getIntervalMs()/1000;
|
||||
board.sleep((sleep_interval > 1800) ? 1800 : sleep_interval); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
|
||||
#else
|
||||
board.sleep(1800); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
|
||||
#endif
|
||||
board.sleep(1800); // nrf ignores seconds param, sleeps whenever possible
|
||||
#else
|
||||
#else
|
||||
if (the_mesh.millisHasNowPassed(lastActive + nextSleepinSecs * 1000)) { // To check if it is time to sleep
|
||||
#ifdef HAS_EX_WATCHDOG
|
||||
uint32_t sleep_interval = ex_watchdog.getIntervalMs()/1000;
|
||||
board.sleep((sleep_interval > 1800) ? 1800 : sleep_interval); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
|
||||
#else
|
||||
board.sleep(1800); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
|
||||
#endif
|
||||
lastActive = millis();
|
||||
|
|
@ -146,6 +163,6 @@ void loop() {
|
|||
} else {
|
||||
nextSleepinSecs += 5; // When there is pending work, to work another 5s
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
class ExWatchdogManager {
|
||||
public:
|
||||
protected:
|
||||
unsigned long next_feed_watchdog;
|
||||
public:
|
||||
ExWatchdogManager() { next_feed_watchdog = 0; }
|
||||
virtual bool begin() { return false; }
|
||||
virtual void loop() { }
|
||||
|
|
|
|||
|
|
@ -141,11 +141,16 @@ void SolarExWatchdog::loop() {
|
|||
}
|
||||
|
||||
unsigned long SolarExWatchdog::getIntervalMs() const {
|
||||
return next_feed_watchdog - millis();
|
||||
unsigned long interval_ms = 0;
|
||||
interval_ms = next_feed_watchdog - millis();
|
||||
if(interval_ms > EX_WATCHDOG_TIMEOUT_MS) {
|
||||
interval_ms = EX_WATCHDOG_TIMEOUT_MS;
|
||||
}
|
||||
return interval_ms;
|
||||
}
|
||||
|
||||
void SolarExWatchdog::feed() {
|
||||
digitalWrite(EX_WATCHDOG_DONE_PIN, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(EX_WATCHDOG_DONE_PIN, LOW);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue