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.

84 lines
1.7 KiB

5 years ago
  1. #include <ViewStates.h>
  2. ViewTextState::ViewTextState(AT24C32 &_at24c32)
  3. {
  4. at24c32 = _at24c32;
  5. renderOffset = (millis() / TEXT_INTERVAL);
  6. };
  7. void ViewTextState::render(uint8_t matrix[121], ControlStates controlState)
  8. {
  9. length = at24c32.read(TEXT_SIZE_ADDRESS);
  10. if (controlState != ControlStates::TEXT)
  11. {
  12. for (uint8_t i = 0; i < length; i++)
  13. {
  14. text[i] = at24c32.read(TEXT_ADDRESS + i);
  15. }
  16. writeText(matrix);
  17. }
  18. else
  19. {
  20. bool const blink = (millis() / CONTROL_BLINK_INTERVAL) % 2 == 0;
  21. position = 0;
  22. text[0] = 0x20;
  23. text[1] = 0x20;
  24. if (length > 2)
  25. {
  26. text[0] = at24c32.read(TEXT_ADDRESS + length - 2);
  27. if (blink)
  28. {
  29. text[1] = at24c32.read(TEXT_ADDRESS + length - 1);
  30. }
  31. }
  32. else if (length > 1 && blink)
  33. {
  34. text[0] = at24c32.read(TEXT_ADDRESS + length - 1);
  35. }
  36. writeChars(matrix);
  37. }
  38. }
  39. void ViewTextState::writeText(uint8_t matrix[121])
  40. {
  41. position = (millis() / TEXT_INTERVAL - renderOffset - 1) % (length + 2);
  42. writeChars(matrix);
  43. }
  44. void ViewTextState::writeChars(uint8_t matrix[121])
  45. {
  46. uint8_t char1 = 0x20;
  47. uint8_t char2 = 0x20;
  48. if (length > position)
  49. {
  50. char1 = text[position];
  51. }
  52. if (length > position + 1)
  53. {
  54. char2 = text[position + 1];
  55. }
  56. for (int col = 0; col < 5; col++)
  57. {
  58. // created ascii chars in 'ascii_memory.ino' to AT23C32 epromm
  59. uint8_t char1Byte = at24c32.read(char1 * 5 + col);
  60. uint8_t char2Byte = at24c32.read(char2 * 5 + col);
  61. for (int row = 0; row < 8; row++)
  62. {
  63. if (!!(char1Byte & (1 << row)))
  64. {
  65. matrix[(row + v_offset) * 11 + col] = color;
  66. }
  67. if (!!(char2Byte & (1 << row)))
  68. {
  69. matrix[(row + v_offset) * 11 + col + 6] = color;
  70. }
  71. }
  72. }
  73. }