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.

TempEditorActivity.cpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <stdio.h>
  2. #include "TempEditorActivity.h"
  3. #include "Helpers.h"
  4. #include "defines.h"
  5. #include "globals.h"
  6. TempEditorActivity::TempEditorActivity(
  7. IActivity* mParentActivity
  8. , IActivity* mPreviousActivity
  9. , IActivity* mNextActivity
  10. , const char* line1
  11. , temp_t* value
  12. )
  13. : BaseActivity(mParentActivity, nullptr, mPreviousActivity, mNextActivity)
  14. , m_line1(line1)
  15. , m_value(value)
  16. , m_tmpValue(*value)
  17. , m_isEditMode(false)
  18. {
  19. }
  20. void TempEditorActivity::begin()
  21. {
  22. m_tmpValue = *m_value;
  23. BaseActivity::begin();
  24. }
  25. void TempEditorActivity::getLcdText(char** lines)
  26. {
  27. Helpers::center(lines[0], m_line1, 16, ' ');
  28. char temp[7];
  29. Helpers::tempToStr(temp, m_tmpValue, 5);
  30. snprintf(lines[1], 17, "%c %s C %c", m_isEditMode ? '>' : ' ', temp, *m_value != m_tmpValue ? '*' : ' ');
  31. }
  32. void TempEditorActivity::onButtonReleased(BaseActivity::Button button)
  33. {
  34. if (m_isEditMode)
  35. {
  36. if (button == Cancel)
  37. {
  38. m_tmpValue = *m_value;
  39. m_isEditMode = false;
  40. }
  41. else if (button == Ok)
  42. {
  43. *m_value = m_tmpValue;
  44. g_storage.save();
  45. m_isEditMode = false;
  46. }
  47. else if (button == Minus)
  48. {
  49. m_tmpValue -= TEMP_INTERVAL;
  50. }
  51. else if (button == Plus)
  52. {
  53. m_tmpValue += TEMP_INTERVAL;
  54. }
  55. m_lcdUpdateNeeded = true;
  56. }
  57. else
  58. {
  59. if (button == Ok)
  60. {
  61. m_isEditMode = true;
  62. m_lcdUpdateNeeded = true;
  63. }
  64. else
  65. {
  66. BaseActivity::onButtonReleased(button);
  67. }
  68. }
  69. }