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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. g_hibernateService.setPaused(false);
  41. }
  42. else if (button == Ok)
  43. {
  44. *m_value = m_tmpValue;
  45. g_storage.save();
  46. m_isEditMode = false;
  47. g_hibernateService.setPaused(false);
  48. }
  49. else if (button == Minus)
  50. {
  51. m_tmpValue -= TEMP_INTERVAL;
  52. }
  53. else if (button == Plus)
  54. {
  55. m_tmpValue += TEMP_INTERVAL;
  56. }
  57. m_lcdUpdateNeeded = true;
  58. }
  59. else
  60. {
  61. if (button == Ok)
  62. {
  63. m_isEditMode = true;
  64. m_lcdUpdateNeeded = true;
  65. g_hibernateService.setPaused(true);
  66. }
  67. else
  68. {
  69. BaseActivity::onButtonReleased(button);
  70. }
  71. }
  72. }