#include #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); } } }