No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

52 líneas
1.1 KiB

  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. gps::powerOn();
  10. SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition(GPS_DEFAULT_TOTAL_TIMEOUT_MS);
  11. SIM808ChargingStatus battery = hardware::sim808::device.getChargingState();
  12. gps::powerOff();
  13. if (gpsStatus > SIM808_GPS_STATUS::NO_FIX) {
  14. tmElements_t time;
  15. gps::getTime(time);
  16. rtc::setTime(time);
  17. positions::appendLast(battery, gpsStatus);
  18. uint8_t velocity;
  19. gps::getVelocity(velocity);
  20. core::setSleepTime(velocity);
  21. }
  22. if (positions::needsToSend()) {
  23. positions::send();
  24. }
  25. mainunit::deepSleep(core::sleepTime);
  26. }
  27. void setSleepTime(uint8_t velocity) {
  28. sleepTime = SLEEP_DEFAULT_TIME_SECONDS;
  29. for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) {
  30. sleepTimings_t timing;
  31. flash::read(&config::defaultSleepTimings[i], timing);
  32. if (velocity > timing.speed) continue;
  33. sleepTime = timing.seconds;
  34. break;
  35. }
  36. VERBOSE_FORMAT("setSleepTime", "%d", sleepTime);
  37. }
  38. }