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.

BoilerTankModeEditorActivity.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <stdio.h>
  2. #include "BoilerTankModeEditorActivity.h"
  3. #include "Helpers.h"
  4. #include "globals.h"
  5. BoilerTankModeEditorActivity::BoilerTankModeEditorActivity(
  6. IActivity* mParentActivity
  7. , IActivity* mPreviousActivity
  8. , IActivity* mNextActivity
  9. , const char* line1
  10. , BoilerTankState::Mode* value
  11. )
  12. : BaseActivity(mParentActivity, nullptr, mPreviousActivity, mNextActivity)
  13. , m_line1(line1)
  14. , m_value(value)
  15. , m_tmpValue(*value)
  16. , m_isEditMode(false)
  17. {
  18. }
  19. void BoilerTankModeEditorActivity::begin()
  20. {
  21. m_tmpValue = *m_value;
  22. BaseActivity::begin();
  23. }
  24. void BoilerTankModeEditorActivity::getLcdText(char** lines)
  25. {
  26. Helpers::center(lines[0], m_line1, 16, ' ');
  27. const char* str = "??";
  28. if (m_tmpValue == BoilerTankState::Auto)
  29. {
  30. str = "Auto";
  31. }
  32. else if (m_tmpValue == BoilerTankState::On)
  33. {
  34. str = "On ";
  35. }
  36. else if (m_tmpValue == BoilerTankState::Off)
  37. {
  38. str = "Off ";
  39. }
  40. snprintf(lines[1], 17, "%c %s %c", m_isEditMode ? '>' : ' ', str, *m_value != m_tmpValue ? '*' : ' ');
  41. }
  42. void BoilerTankModeEditorActivity::onButtonReleased(BaseActivity::Button button)
  43. {
  44. if (m_isEditMode)
  45. {
  46. if (button == Cancel)
  47. {
  48. m_tmpValue = *m_value;
  49. m_isEditMode = false;
  50. g_hibernateService.setPaused(false);
  51. }
  52. else if (button == Ok)
  53. {
  54. *m_value = m_tmpValue;
  55. g_storage.save();
  56. m_isEditMode = false;
  57. g_hibernateService.setPaused(false);
  58. }
  59. else if (button == Minus)
  60. {
  61. switch (m_tmpValue)
  62. {
  63. case BoilerTankState::Auto:
  64. m_tmpValue = BoilerTankState::Off;
  65. break;
  66. case BoilerTankState::On:
  67. m_tmpValue = BoilerTankState::Auto;
  68. break;
  69. case BoilerTankState::Off:
  70. default:
  71. m_tmpValue = BoilerTankState::On;
  72. break;
  73. }
  74. }
  75. else if (button == Plus)
  76. {
  77. switch (m_tmpValue)
  78. {
  79. case BoilerTankState::Auto:
  80. m_tmpValue = BoilerTankState::On;
  81. break;
  82. case BoilerTankState::On:
  83. m_tmpValue = BoilerTankState::Off;
  84. break;
  85. case BoilerTankState::Off:
  86. default:
  87. m_tmpValue = BoilerTankState::Auto;
  88. break;
  89. }
  90. }
  91. m_lcdUpdateNeeded = true;
  92. }
  93. else
  94. {
  95. if (button == Ok)
  96. {
  97. m_isEditMode = true;
  98. m_lcdUpdateNeeded = true;
  99. g_hibernateService.setPaused(true);
  100. }
  101. else
  102. {
  103. BaseActivity::onButtonReleased(button);
  104. }
  105. }
  106. }