GPS PowerSaving v2: Added GPS wake up upon telemtry requests for companions. Bug fixes for "gps" CLI.

This commit is contained in:
Kevin Le committed 2026-09-25 22:37:04 +07:00
1 parent d9c42964eb
commit 1aa8ae90fb
16 files changed
+177 -201

No files matched your search

+23 -33
View File
@@ -47,7 +47,7 @@ void HWTSensorManager::start_gps() {
_location->begin(); // Claims periph_power via RefCountedDigitalPin
gps_active = true;
if (powersaving_enabled && _location->isPowerSavingEnabled()) {
if (_location->isPowerSavingEnabled()) {
gps_wake = true; // gps_active is true
_location->syncTime(); // Clear GPS data and force sync time
_location->setNextSleep(); // Next time to off
@@ -59,7 +59,7 @@ void HWTSensorManager::start_gps() {
void HWTSensorManager::stop_gps() {
if (gps_active) {
if (powersaving_enabled && _location->isPowerSavingEnabled()) {
if (_location->isPowerSavingEnabled()) {
gps_wake = false; // gps_active is unchanged (true) even the GPS sleep (e.g: off)
_location->stopTimeSync(); // Stop time sync
_location->setNextWake(); // Next time to on
@@ -89,35 +89,33 @@ void HWTSensorManager::loop() {
static long next_gps_update = 0;
// PowerSaving
if (powersaving_enabled) {
if (_location->isPowerSavingEnabled()) {
if (gps_wake && ((int32_t)(millis() - _location->getNextSleep()) >= 0 ||
!_location->waitingTimeSync())) { // Time to off or GPS set
if ((int32_t)(millis() - _location->getNextSleep()) >= 0) {
POWERSAVING_DEBUG_PRINTLN("GPS wake timeout. Enter sleep");
} else if (!_location->waitingTimeSync()) {
POWERSAVING_DEBUG_PRINTLN("GPS set. Enter sleep early");
}
stop_gps();
} else if (!gps_wake && ((int32_t)(millis() - _location->getNextWake()) >= 0)) { // Time to on
POWERSAVING_DEBUG_PRINTLN("GPS sleep timeout. Wakeup.");
start_gps();
} else if (!gps_wake && _location->waitingTimeSync()) { // On for "gps sync"
POWERSAVING_DEBUG_PRINTLN("CLI gps sync. Wakeup");
start_gps();
if (_location->isPowerSavingEnabled()) {
if (gps_wake && ((int32_t)(millis() - _location->getNextSleep()) >= 0 ||
!_location->waitingTimeSync())) { // Time to off or GPS set
if ((int32_t)(millis() - _location->getNextSleep()) >= 0) {
POWERSAVING_DEBUG_PRINTLN("GPS wake timeout. Enter sleep");
} else if (!_location->waitingTimeSync()) {
POWERSAVING_DEBUG_PRINTLN("GPS set. Enter sleep early");
}
stop_gps();
} else if (!gps_wake && ((int32_t)(millis() - _location->getNextWake()) >= 0)) { // Time to on
POWERSAVING_DEBUG_PRINTLN("GPS sleep timeout. Wakeup.");
start_gps();
} else if (!gps_wake && _location->waitingTimeSync()) { // On for "gps sync"
POWERSAVING_DEBUG_PRINTLN("CLI gps sync. Wakeup");
start_gps();
}
}
if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) {
if ((!_location->isPowerSavingEnabled() && gps_active) || (_location->isPowerSavingEnabled() && gps_wake)) {
_location->loop();
}
if ((int32_t)(millis() - next_gps_update) >= 0) {
if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) {
if ((!_location->isPowerSavingEnabled() && gps_active) || (_location->isPowerSavingEnabled() && gps_wake)) {
if (_location->isValid()) {
node_lat = ((double)_location->getLatitude()) / 1000000.;
node_lon = ((double)_location->getLongitude()) / 1000000.;
@@ -126,10 +124,10 @@ void HWTSensorManager::loop() {
}
// In powersaving mode, GPS is on and off. Only update data when GPS is on
if (powersaving_enabled) next_gps_update = millis() + 1000;
if (_location->isPowerSavingEnabled()) next_gps_update = millis() + 1000;
}
if (!powersaving_enabled) next_gps_update = millis() + 1000;
if (!_location->isPowerSavingEnabled()) next_gps_update = millis() + 1000;
}
}
@@ -147,16 +145,8 @@ const char* HWTSensorManager::getSettingValue(int i) const {
bool HWTSensorManager::setSettingValue(const char* name, const char* value) {
if (strcmp(name, "gps") == 0) {
if (strcmp(value, "0") == 0) {
if (powersaving_enabled) {
_location->enablePowerSaving(false);
}
stop_gps();
} else {
if (powersaving_enabled) {
_location->enablePowerSaving(true);
}
start_gps();
}
return true;