You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 line
918 B

  1. #include "Core.h"
  2. #include "Config.h"
  3. #include "Flash.h"
  4. #define LOGGER_NAME "Core"
  5. namespace core {
  6. uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS;;
  7. void main() {
  8. VERBOSE("main");
  9. PositionEntryMetadata metadata;
  10. if (positions::acquire(metadata)) {
  11. positions::appendLast(metadata);
  12. updateSleepTime();
  13. }
  14. if (positions::needsToSend()) {
  15. positions::send();
  16. }
  17. }
  18. void updateSleepTime() {
  19. VERBOSE("updateSleepTime");
  20. uint8_t velocity;
  21. gps::getVelocity(velocity);
  22. setSleepTime(velocity);
  23. }
  24. void setSleepTime(uint8_t velocity) {
  25. sleepTime = SLEEP_DEFAULT_TIME_SECONDS;
  26. for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) {
  27. sleepTimings_t timing;
  28. flash::read(&config::defaultSleepTimings[i], timing);
  29. if (velocity > timing.speed) continue;
  30. sleepTime = timing.seconds;
  31. break;
  32. }
  33. VERBOSE_FORMAT("setSleepTime", "%d", sleepTime);
  34. }
  35. }