123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include <stdio.h>
- #include "BoilerTankModeEditorActivity.h"
- #include "Helpers.h"
- #include "globals.h"
-
- BoilerTankModeEditorActivity::BoilerTankModeEditorActivity(
- IActivity* mParentActivity
- , IActivity* mPreviousActivity
- , IActivity* mNextActivity
- , const char* line1
- , BoilerTankState::Mode* value
- )
- : BaseActivity(mParentActivity, nullptr, mPreviousActivity, mNextActivity)
- , m_line1(line1)
- , m_value(value)
- , m_tmpValue(*value)
- , m_isEditMode(false)
- {
- }
-
- void BoilerTankModeEditorActivity::begin()
- {
- m_tmpValue = *m_value;
- BaseActivity::begin();
- }
-
- void BoilerTankModeEditorActivity::getLcdText(char** lines)
- {
- Helpers::center(lines[0], m_line1, 16, ' ');
-
- const char* str = "??";
- if (m_tmpValue == BoilerTankState::Auto)
- {
- str = "Auto";
- }
- else if (m_tmpValue == BoilerTankState::On)
- {
- str = "On ";
- }
- else if (m_tmpValue == BoilerTankState::Off)
- {
- str = "Off ";
- }
- snprintf(lines[1], 17, "%c %s %c", m_isEditMode ? '>' : ' ', str, *m_value != m_tmpValue ? '*' : ' ');
- }
-
- void BoilerTankModeEditorActivity::onButtonReleased(BaseActivity::Button button)
- {
- if (m_isEditMode)
- {
- if (button == Cancel)
- {
- m_tmpValue = *m_value;
- m_isEditMode = false;
- g_hibernateService.setPaused(false);
- }
- else if (button == Ok)
- {
- *m_value = m_tmpValue;
- g_storage.save();
- m_isEditMode = false;
- g_hibernateService.setPaused(false);
- }
- else if (button == Minus)
- {
- switch (m_tmpValue)
- {
- case BoilerTankState::Auto:
- m_tmpValue = BoilerTankState::Off;
- break;
- case BoilerTankState::On:
- m_tmpValue = BoilerTankState::Auto;
- break;
- case BoilerTankState::Off:
- default:
- m_tmpValue = BoilerTankState::On;
- break;
- }
- }
- else if (button == Plus)
- {
- switch (m_tmpValue)
- {
- case BoilerTankState::Auto:
- m_tmpValue = BoilerTankState::On;
- break;
- case BoilerTankState::On:
- m_tmpValue = BoilerTankState::Off;
- break;
- case BoilerTankState::Off:
- default:
- m_tmpValue = BoilerTankState::Auto;
- break;
- }
- }
- m_lcdUpdateNeeded = true;
- }
- else
- {
- if (button == Ok)
- {
- m_isEditMode = true;
- m_lcdUpdateNeeded = true;
- g_hibernateService.setPaused(true);
- }
- else
- {
- BaseActivity::onButtonReleased(button);
- }
- }
- }
|