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.

81 lines
1.9 KiB

6 years ago
  1. #include <ControlStates.h>
  2. ControlTimeState::ControlTimeState(DS3231 &_ds3231, AT24C32 &_at24c32)
  3. {
  4. ds3231 = _ds3231;
  5. at24c32 = _at24c32;
  6. }
  7. void ControlTimeState::leftPressed(ViewStates &viewState, ControlStates &controlState)
  8. {
  9. switch (controlState)
  10. {
  11. case ControlStates::TIME_HOURS:
  12. controlState = ControlStates::TIME_MODE;
  13. break;
  14. case ControlStates::TIME_MINUTES:
  15. controlState = ControlStates::TIME_HOURS;
  16. break;
  17. case ControlStates::TIME_MODE:
  18. controlState = ControlStates::TIME_MINUTES;
  19. break;
  20. }
  21. };
  22. void ControlTimeState::rightPressed(ViewStates &viewState, ControlStates &controlState)
  23. {
  24. switch (controlState)
  25. {
  26. case ControlStates::TIME_HOURS:
  27. controlState = ControlStates::TIME_MINUTES;
  28. break;
  29. case ControlStates::TIME_MINUTES:
  30. controlState = ControlStates::TIME_MODE;
  31. break;
  32. case ControlStates::TIME_MODE:
  33. controlState = ControlStates::TIME_HOURS;
  34. break;
  35. }
  36. };
  37. void ControlTimeState::enterPressed(ViewStates &viewState, ControlStates &controlState)
  38. {
  39. controlState = ControlStates::VIEW;
  40. };
  41. void ControlTimeState::decrementPressed(ViewStates &viewState, ControlStates &controlState)
  42. {
  43. switch (controlState)
  44. {
  45. case ControlStates::TIME_HOURS:
  46. ds3231.decrementHours();
  47. break;
  48. case ControlStates::TIME_MINUTES:
  49. ds3231.decrementMinutes();
  50. break;
  51. case ControlStates::TIME_MODE:
  52. uint8_t mode = at24c32.read(TIME_MODE_ADDRESS);
  53. mode = (mode - 1) % 3;
  54. at24c32.write(TIME_MODE_ADDRESS, mode);
  55. break;
  56. }
  57. };
  58. void ControlTimeState::incrementPressed(ViewStates &viewState, ControlStates &controlState)
  59. {
  60. switch (controlState)
  61. {
  62. case ControlStates::TIME_HOURS:
  63. ds3231.incrementHours();
  64. break;
  65. case ControlStates::TIME_MINUTES:
  66. ds3231.incrementMinutes();
  67. break;
  68. case ControlStates::TIME_MODE:
  69. uint8_t mode = at24c32.read(TIME_MODE_ADDRESS);
  70. mode = (mode + 1) % 3;
  71. at24c32.write(TIME_MODE_ADDRESS, mode);
  72. break;
  73. }
  74. };