Skip to content

Commit

Permalink
Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
todd-herbert committed Jun 12, 2024
1 parent 9d29ec7 commit 8b697cd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ void GPS::setGPSPower(bool on, bool standbyOnly, uint32_t sleepTime)
powerState = GPS_ACTIVE;
else if (!enabled) // User has disabled with triple press
powerState = GPS_OFF;
else if (sleepTime <= GPS_IDLE_THRESHOLD_SECONDS * 1000UL)
else if (sleepTime <= GPS_IDLE_THRESHOLD_SECONDS * 1000UL && sleepTime > 0) // sleepTime=0 indicates indefinite GPS poweroff
powerState = GPS_IDLE;
else if (standbyOnly)
powerState = GPS_STANDBY;
Expand Down Expand Up @@ -940,7 +940,8 @@ void GPS::setAwake(bool wantAwake)

// How long to wait before attempting next GPS update
// Aims to hit position.gps_update_interval by using the lock-time prediction
uint32_t compensatedSleepTime = (getSleepTime() > predictedLockTime) ? (getSleepTime() - predictedLockTime) : 0;
// Sleep for at least 1 second, so we don't ask GPS hardware to sleep indefinitely with a "0 second PMREQ"
uint32_t compensatedSleepTime = (getSleepTime() > predictedLockTime) ? (getSleepTime() - predictedLockTime) : 1;

// If long interval between updates: power off between updates
if (compensatedSleepTime > GPS_STANDBY_THRESHOLD_MINUTES * MS_IN_MINUTE) {
Expand Down Expand Up @@ -1129,11 +1130,10 @@ void GPS::clearBuffer()
/// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs
int GPS::prepareDeepSleep(void *unused)
{
LOG_INFO("GPS deep sleep!\n");

// Manually enter GPSPowerState::OFF, so we can ensure a PMREQ with duration 0 has been sent
setGPSPower(false, false, 0);

/*
* GPS power was previously set here.
* Now removed, as the same call is already made directly in doDeepSleep.
*/
return 0;
}

Expand Down

0 comments on commit 8b697cd

Please sign in to comment.