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.

91 lines
2.2 KiB

6 years ago
  1. #include <ControlStates.h>
  2. ControlViewState::ControlViewState(AT24C32 &_at24c32)
  3. {
  4. at24c32 = _at24c32;
  5. }
  6. void ControlViewState::leftPressed(ViewStates &viewState, ControlStates &controlState)
  7. {
  8. switch (viewState)
  9. {
  10. case ViewStates::TIME:
  11. viewState = ViewStates::LED_DEMO;
  12. break;
  13. case ViewStates::TEMPERATURE:
  14. viewState = ViewStates::TIME;
  15. break;
  16. case ViewStates::SECONDS:
  17. viewState = ViewStates::TEMPERATURE;
  18. break;
  19. case ViewStates::DATE:
  20. viewState = ViewStates::SECONDS;
  21. break;
  22. case ViewStates::TEXT:
  23. viewState = ViewStates::DATE;
  24. break;
  25. case ViewStates::LED_DEMO:
  26. viewState = ViewStates::TEXT;
  27. break;
  28. }
  29. };
  30. void ControlViewState::rightPressed(ViewStates &viewState, ControlStates &controlState)
  31. {
  32. switch (viewState)
  33. {
  34. case ViewStates::TIME:
  35. viewState = ViewStates::TEMPERATURE;
  36. break;
  37. case ViewStates::TEMPERATURE:
  38. viewState = ViewStates::SECONDS;
  39. break;
  40. case ViewStates::SECONDS:
  41. viewState = ViewStates::DATE;
  42. break;
  43. case ViewStates::DATE:
  44. viewState = ViewStates::TEXT;
  45. break;
  46. case ViewStates::TEXT:
  47. viewState = ViewStates::LED_DEMO;
  48. break;
  49. case ViewStates::LED_DEMO:
  50. viewState = ViewStates::TIME;
  51. break;
  52. }
  53. };
  54. void ControlViewState::enterPressed(ViewStates &viewState, ControlStates &controlState)
  55. {
  56. switch (viewState)
  57. {
  58. case ViewStates::TIME:
  59. controlState = ControlStates::TIME_HOURS;
  60. break;
  61. case ViewStates::SECONDS:
  62. controlState = ControlStates::TIME_SECONDS;
  63. break;
  64. case ViewStates::DATE:
  65. controlState = ControlStates::DATE_DATE;
  66. break;
  67. case ViewStates::TEXT:
  68. controlState = ControlStates::TEXT;
  69. break;
  70. case ViewStates::LED_DEMO:
  71. controlState = ControlStates::COLOR_R;
  72. break;
  73. }
  74. };
  75. void ControlViewState::decrementPressed(ViewStates &viewState, ControlStates &controlState)
  76. {
  77. uint8_t value = at24c32.read(BRIGHTNESS_ADDRESS);
  78. value = (value - 5) % 256;
  79. at24c32.write(BRIGHTNESS_ADDRESS, value);
  80. };
  81. void ControlViewState::incrementPressed(ViewStates &viewState, ControlStates &controlState)
  82. {
  83. uint8_t value = at24c32.read(BRIGHTNESS_ADDRESS);
  84. value = (value + 5) % 256;
  85. at24c32.write(BRIGHTNESS_ADDRESS, value);
  86. };