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.

HibernateService.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "HibernateService.h"
  2. #include "defines.h"
  3. #include "Logs.h"
  4. #include "globals.h"
  5. #include <Arduino.h>
  6. HibernateService::HibernateService()
  7. : m_buttons{
  8. &g_btnCancel,
  9. &g_btnOk,
  10. &g_btnMinus,
  11. &g_btnPlus,
  12. nullptr
  13. }
  14. , m_lastEventMs(0)
  15. , m_paused(false)
  16. {
  17. }
  18. void HibernateService::begin()
  19. {
  20. m_lastEventMs = millis();
  21. setValue(false);
  22. g_lcdLed.setEnabled(!m_lastValue);
  23. }
  24. void HibernateService::loop()
  25. {
  26. auto currentMs = millis();
  27. bool shouldHibernate = m_lastValue;
  28. for (auto i = 0; m_buttons[i]; ++i)
  29. {
  30. if (m_buttons[i]->wasReleased())
  31. {
  32. m_lastEventMs = currentMs;
  33. shouldHibernate = false;
  34. break;
  35. }
  36. }
  37. if (!m_lastValue && !m_paused && currentMs - m_lastEventMs > HIBERNATE_DELAY)
  38. {
  39. shouldHibernate = true;
  40. }
  41. setValue(shouldHibernate);
  42. if (hasChanged())
  43. {
  44. LOG(1, "Hibernate event");
  45. g_lcdLed.setEnabled(!m_lastValue);
  46. if (m_lastValue && g_appCore.getCurrentActivity() != &g_homeActivity)
  47. {
  48. g_appCore.setActivity(&g_homeActivity);
  49. }
  50. }
  51. }
  52. void HibernateService::setPaused(bool paused)
  53. {
  54. m_paused = paused;
  55. }