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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. }
  51. else if (button == Ok)
  52. {
  53. *m_value = m_tmpValue;
  54. g_storage.save();
  55. m_isEditMode = false;
  56. }
  57. else if (button == Minus)
  58. {
  59. switch (m_tmpValue)
  60. {
  61. case BoilerTankState::Auto:
  62. m_tmpValue = BoilerTankState::Off;
  63. break;
  64. case BoilerTankState::On:
  65. m_tmpValue = BoilerTankState::Auto;
  66. break;
  67. case BoilerTankState::Off:
  68. default:
  69. m_tmpValue = BoilerTankState::On;
  70. break;
  71. }
  72. }
  73. else if (button == Plus)
  74. {
  75. switch (m_tmpValue)
  76. {
  77. case BoilerTankState::Auto:
  78. m_tmpValue = BoilerTankState::On;
  79. break;
  80. case BoilerTankState::On:
  81. m_tmpValue = BoilerTankState::Off;
  82. break;
  83. case BoilerTankState::Off:
  84. default:
  85. m_tmpValue = BoilerTankState::Auto;
  86. break;
  87. }
  88. }
  89. m_lcdUpdateNeeded = true;
  90. }
  91. else
  92. {
  93. if (button == Ok)
  94. {
  95. m_isEditMode = true;
  96. m_lcdUpdateNeeded = true;
  97. }
  98. else
  99. {
  100. BaseActivity::onButtonReleased(button);
  101. }
  102. }
  103. }