Browse Source

Added Power Saving for NRF52 companions

pull/2286/head
Kevin Le 3 months ago
parent
commit
6b1099161c
  1. 8
      examples/companion_radio/MyMesh.cpp
  2. 3
      examples/companion_radio/MyMesh.h
  3. 6
      examples/companion_radio/main.cpp

8
examples/companion_radio/MyMesh.cpp

@ -2222,3 +2222,11 @@ bool MyMesh::advert() {
return false; return false;
} }
} }
// To check if there is pending work
bool MyMesh::hasPendingWork() const {
#if defined(WITH_BRIDGE)
if (bridge.isRunning()) return true; // bridge needs WiFi radio, can't sleep
#endif
return _mgr->getOutboundTotal() > 0;
}

3
examples/companion_radio/MyMesh.h

@ -175,6 +175,9 @@ public:
sensors.setSettingValue("gps_interval", interval_str); sensors.setSettingValue("gps_interval", interval_str);
} }
} }
// To check if there is pending work
bool hasPendingWork() const;
#endif #endif
private: private:

6
examples/companion_radio/main.cpp

@ -248,6 +248,12 @@ void loop() {
#endif #endif
rtc_clock.tick(); rtc_clock.tick();
if (!the_mesh.hasPendingWork()) {
#if defined(NRF52_PLATFORM)
board.sleep(0); // nrf ignores seconds param, sleeps whenever possible
#endif
}
#if defined(ESP32) && defined(WIFI_SSID) #if defined(ESP32) && defined(WIFI_SSID)
// Safely attempt to reconnect every 10 seconds if flagged // Safely attempt to reconnect every 10 seconds if flagged
if (wifi_needs_reconnect && (millis() - last_wifi_reconnect_attempt > 10000)) { if (wifi_needs_reconnect && (millis() - last_wifi_reconnect_attempt > 10000)) {

Loading…
Cancel
Save