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.

127 lines
3.0 KiB

5 years ago
  1. #include <ControlStates.h>
  2. ControlColorState::ControlColorState(AT24C32 &_at24c32)
  3. {
  4. at24c32 = _at24c32;
  5. }
  6. void ControlColorState::leftPressed(ViewStates &viewState, ControlStates &controlState)
  7. {
  8. switch (controlState)
  9. {
  10. case ControlStates::COLOR_R:
  11. controlState = ControlStates::COLOR_B;
  12. break;
  13. case ControlStates::COLOR_G:
  14. controlState = ControlStates::COLOR_R;
  15. break;
  16. case ControlStates::COLOR_B:
  17. controlState = ControlStates::COLOR_G;
  18. break;
  19. }
  20. };
  21. void ControlColorState::rightPressed(ViewStates &viewState, ControlStates &controlState)
  22. {
  23. switch (controlState)
  24. {
  25. case ControlStates::COLOR_R:
  26. controlState = ControlStates::COLOR_G;
  27. break;
  28. case ControlStates::COLOR_G:
  29. controlState = ControlStates::COLOR_B;
  30. break;
  31. case ControlStates::COLOR_B:
  32. controlState = ControlStates::COLOR_R;
  33. break;
  34. }
  35. };
  36. void ControlColorState::enterPressed(ViewStates &viewState, ControlStates &controlState)
  37. {
  38. controlState = ControlStates::VIEW;
  39. };
  40. void ControlColorState::decrementPressed(ViewStates &viewState, ControlStates &controlState)
  41. {
  42. switch (controlState)
  43. {
  44. case ControlStates::COLOR_R:
  45. decrementColorR();
  46. break;
  47. case ControlStates::COLOR_G:
  48. decrementColorG();
  49. break;
  50. case ControlStates::COLOR_B:
  51. decrementColorB();
  52. break;
  53. }
  54. };
  55. void ControlColorState::incrementPressed(ViewStates &viewState, ControlStates &controlState)
  56. {
  57. switch (controlState)
  58. {
  59. case ControlStates::COLOR_R:
  60. incrementColorR();
  61. break;
  62. case ControlStates::COLOR_G:
  63. incrementColorG();
  64. break;
  65. case ControlStates::COLOR_B:
  66. incrementColorB();
  67. break;
  68. }
  69. };
  70. void ControlColorState::decrementColorR()
  71. {
  72. uint8_t color = at24c32.read(COLOR_ADDRESS);
  73. uint8_t red = (color >> 5);
  74. red = (red - 1) % 8;
  75. color = (red << 5) + (color & 0x1F);
  76. at24c32.write(COLOR_ADDRESS, color);
  77. }
  78. void ControlColorState::incrementColorR()
  79. {
  80. uint8_t color = at24c32.read(COLOR_ADDRESS);
  81. uint8_t red = (color >> 5);
  82. red = (red + 1) % 8;
  83. color = (red << 5) + (color & 0x1F);
  84. at24c32.write(COLOR_ADDRESS, color);
  85. }
  86. void ControlColorState::decrementColorG()
  87. {
  88. uint8_t color = at24c32.read(COLOR_ADDRESS);
  89. uint8_t green = (color >> 2) & 0x07;
  90. green = (green - 1) % 8;
  91. color = (green << 2) + (color & 0xE3);
  92. at24c32.write(COLOR_ADDRESS, color);
  93. }
  94. void ControlColorState::incrementColorG()
  95. {
  96. uint8_t color = at24c32.read(COLOR_ADDRESS);
  97. uint8_t green = (color >> 2) & 0x07;
  98. green = (green + 1) % 8;
  99. color = (green << 2) + (color & 0xE3);
  100. at24c32.write(COLOR_ADDRESS, color);
  101. }
  102. void ControlColorState::decrementColorB()
  103. {
  104. uint8_t color = at24c32.read(COLOR_ADDRESS);
  105. uint8_t blue = color & 0x03;
  106. blue = (blue - 1) % 4;
  107. color = blue + (color & 0xFC);
  108. at24c32.write(COLOR_ADDRESS, color);
  109. }
  110. void ControlColorState::incrementColorB()
  111. {
  112. uint8_t color = at24c32.read(COLOR_ADDRESS);
  113. uint8_t blue = color & 0x03;
  114. blue = (blue + 1) % 4;
  115. color = blue + (color & 0xFC);
  116. at24c32.write(COLOR_ADDRESS, color);
  117. }