12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #include "HibernateService.h"
- #include "defines.h"
- #include "Logs.h"
- #include "globals.h"
- #include <Arduino.h>
-
- HibernateService::HibernateService()
- : m_buttons{
- &g_btnCancel,
- &g_btnOk,
- &g_btnMinus,
- &g_btnPlus,
- nullptr
- }
- , m_lastEventMs(0)
- {
- }
-
- void HibernateService::begin()
- {
- m_lastEventMs = millis();
- setValue(false);
- g_lcdLed.setEnabled(!m_lastValue);
- }
-
- void HibernateService::loop()
- {
- auto currentMs = millis();
- bool shouldHibernate = m_lastValue;
-
- for (auto i = 0; m_buttons[i]; ++i)
- {
- if (m_buttons[i]->wasReleased())
- {
- m_lastEventMs = currentMs;
- shouldHibernate = false;
- break;
- }
- }
- if (!m_lastValue && currentMs - m_lastEventMs > HIBERNATE_DELAY)
- {
- shouldHibernate = true;
- }
-
- setValue(shouldHibernate);
-
- if (hasChanged())
- {
- LOG(1, "Hibernate event");
- g_lcdLed.setEnabled(!m_lastValue);
- }
- }
|