From 01f3a488a1a93aebe009b903d2cd852302d5733b Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Fri, 16 Mar 2018 22:46:24 +1300 Subject: [PATCH] Added some code to reduce the effect of a gps fix that would indicate no speed, leaving the device in sleep mode for too long --- GpsTracker/Core.cpp | 30 +++++++++++++++++++++--------- GpsTracker/Core.h | 4 ++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/GpsTracker/Core.cpp b/GpsTracker/Core.cpp index 477001c..ce756f3 100644 --- a/GpsTracker/Core.cpp +++ b/GpsTracker/Core.cpp @@ -8,6 +8,7 @@ using namespace utils; namespace core { uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS;; + uint8_t increaseInARow = 0; void main() { VERBOSE("main"); @@ -15,29 +16,40 @@ namespace core { PositionEntryMetadata metadata; if (positions::acquire(metadata)) { positions::appendLast(metadata); - setSleepTime(); + updateSleepTime(gps::getVelocity()); } - positions::doBackup(); + positions::doBackup(); + mainunit::deepSleep(sleepTime); } - void setSleepTime() { - setSleepTime(gps::getVelocity()); + void updateSleepTime(uint8_t velocity) { + uint16_t result = computeSleepTime(velocity); + + if (result > sleepTime) { + increaseInARow++; + if (increaseInARow < SLEEP_DEFAULT_INCREASE_THRESHOLD) return; + + } + else increaseInARow = 0; + + sleepTime = result; } - void setSleepTime(uint8_t velocity) { - sleepTime = SLEEP_DEFAULT_TIME_SECONDS; + uint16_t computeSleepTime(uint8_t velocity) { + uint16_t result; for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) { sleepTimings_t timing; flash::read(&config::defaultSleepTimings[i], timing); if (velocity > timing.speed) continue; - - sleepTime = timing.seconds; + + result = timing.seconds; break; } - VERBOSE_FORMAT("setSleepTime", "%d", sleepTime); + VERBOSE_FORMAT("computeSleepTime", "%d,%d", velocity, result); + return result; } } \ No newline at end of file diff --git a/GpsTracker/Core.h b/GpsTracker/Core.h index 78172ab..7539d51 100644 --- a/GpsTracker/Core.h +++ b/GpsTracker/Core.h @@ -14,6 +14,6 @@ namespace core { extern uint16_t sleepTime; void main(); - void setSleepTime(uint8_t velocity); - void setSleepTime(); + void updateSleepTime(uint8_t velocity); + uint16_t computeSleepTime(uint8_t velocity); } \ No newline at end of file