Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

HibernateService.cpp 1001B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. {
  16. }
  17. void HibernateService::begin()
  18. {
  19. m_lastEventMs = millis();
  20. setValue(false);
  21. g_lcdLed.setEnabled(!m_lastValue);
  22. }
  23. void HibernateService::loop()
  24. {
  25. auto currentMs = millis();
  26. bool shouldHibernate = m_lastValue;
  27. for (auto i = 0; m_buttons[i]; ++i)
  28. {
  29. if (m_buttons[i]->wasReleased())
  30. {
  31. m_lastEventMs = currentMs;
  32. shouldHibernate = false;
  33. break;
  34. }
  35. }
  36. if (!m_lastValue && currentMs - m_lastEventMs > HIBERNATE_DELAY)
  37. {
  38. shouldHibernate = true;
  39. }
  40. setValue(shouldHibernate);
  41. if (hasChanged())
  42. {
  43. LOG(1, "Hibernate event");
  44. g_lcdLed.setEnabled(!m_lastValue);
  45. }
  46. }