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.

75 lines
1.6 KiB

5 years ago
  1. #include <ViewStates.h>
  2. ViewLEDState::ViewLEDState(){
  3. };
  4. void ViewLEDState::render(uint8_t matrix[121], ControlStates controlState)
  5. {
  6. if (controlState != ControlStates::COLOR_R && controlState != ControlStates::COLOR_G && controlState != ControlStates::COLOR_B)
  7. {
  8. int const color = (millis() / 500) % 256;
  9. for (int i = 0; i < 121; i++)
  10. {
  11. matrix[i] = color - i % 256;
  12. }
  13. }
  14. else
  15. {
  16. // special color edit view
  17. bool const blink = (millis() / CONTROL_BLINK_INTERVAL) % 2 == 0;
  18. if (controlState != ControlStates::COLOR_R || blink)
  19. {
  20. uint8_t red = color >> 5;
  21. matrix[0] = 0x07 << 5;
  22. matrix[10] = 0x07 << 5;
  23. matrix[11] = 0x07 << 5;
  24. matrix[21] = 0x07 << 5;
  25. for (int i = 0; i < red; i++)
  26. {
  27. // red
  28. matrix[i + 2] = red << 5;
  29. matrix[i + 13] = red << 5;
  30. }
  31. }
  32. if (controlState != ControlStates::COLOR_G || blink)
  33. {
  34. uint8_t green = (color >> 2) & 0x07;
  35. matrix[22] = 0x07 << 2;
  36. matrix[32] = 0x07 << 2;
  37. matrix[33] = 0x07 << 2;
  38. matrix[43] = 0x07 << 2;
  39. for (int i = 0; i < green; i++)
  40. {
  41. // green
  42. matrix[i + 24] = green << 2;
  43. matrix[i + 35] = green << 2;
  44. }
  45. }
  46. if (controlState != ControlStates::COLOR_B || blink)
  47. {
  48. uint8_t blue = color & 0x03;
  49. matrix[44] = 0x03;
  50. matrix[54] = 0x03;
  51. matrix[55] = 0x03;
  52. matrix[65] = 0x03;
  53. for (int i = 0; i < blue; i++)
  54. {
  55. // blue
  56. matrix[i + 46] = blue;
  57. matrix[i + 57] = blue;
  58. }
  59. }
  60. for (int i = 77; i < 121; i++)
  61. {
  62. matrix[i] = color;
  63. }
  64. }
  65. }