|
@@ -8,6 +8,7 @@ using namespace utils; |
|
|
|
|
|
|
|
|
namespace core { |
|
|
namespace core { |
|
|
uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS;; |
|
|
uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS;; |
|
|
|
|
|
uint8_t increaseInARow = 0; |
|
|
|
|
|
|
|
|
void main() { |
|
|
void main() { |
|
|
VERBOSE("main"); |
|
|
VERBOSE("main"); |
|
@@ -15,29 +16,40 @@ namespace core { |
|
|
PositionEntryMetadata metadata; |
|
|
PositionEntryMetadata metadata; |
|
|
if (positions::acquire(metadata)) { |
|
|
if (positions::acquire(metadata)) { |
|
|
positions::appendLast(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++) { |
|
|
for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) { |
|
|
sleepTimings_t timing; |
|
|
sleepTimings_t timing; |
|
|
flash::read(&config::defaultSleepTimings[i], timing); |
|
|
flash::read(&config::defaultSleepTimings[i], timing); |
|
|
|
|
|
|
|
|
if (velocity > timing.speed) continue; |
|
|
if (velocity > timing.speed) continue; |
|
|
|
|
|
|
|
|
sleepTime = timing.seconds; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = timing.seconds; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
VERBOSE_FORMAT("setSleepTime", "%d", sleepTime); |
|
|
|
|
|
|
|
|
VERBOSE_FORMAT("computeSleepTime", "%d,%d", velocity, result); |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |