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.

95 lines
2.3 KiB

5 years ago
  1. #include <ViewStates.h>
  2. ViewDateState::ViewDateState(DS3231 &_ds3231, AT24C32 &_at24c32, char _delimiter) : ViewTextState(at24c32)
  3. {
  4. ds3231 = _ds3231;
  5. at24c32 = _at24c32;
  6. delimiter = _delimiter;
  7. renderOffset = (millis() / TEXT_INTERVAL);
  8. };
  9. void ViewDateState::render(uint8_t matrix[121], ControlStates controlState)
  10. {
  11. bool const blink = (millis() / CONTROL_BLINK_INTERVAL) % 2 == 0;
  12. length = 0;
  13. position = 0;
  14. uint8_t date = ds3231.getDate();
  15. uint8_t month = ds3231.getMonth();
  16. int16_t year = ds3231.getYear();
  17. if (controlState == ControlStates::DATE_DATE && blink)
  18. {
  19. length = 2;
  20. text[0] = (date / 10) + 0x30;
  21. text[1] = (date % 10) + 0x30;
  22. ViewTextState::writeChars(matrix);
  23. }
  24. else if (controlState == ControlStates::DATE_MONTH && blink)
  25. {
  26. length = 2;
  27. text[0] = (month / 10) + 0x30;
  28. text[1] = (month % 10) + 0x30;
  29. ViewTextState::writeChars(matrix);
  30. }
  31. else if (controlState == ControlStates::DATE_YEAR && blink)
  32. {
  33. if (year == 2000 || year == 1900)
  34. {
  35. length = 4;
  36. text[0] = ((year / 100) / 10) + 0x30;
  37. text[1] = ((year / 100) % 10) + 0x30;
  38. position = (millis() / TEXT_INTERVAL) % length;
  39. }
  40. else
  41. {
  42. length = 2;
  43. }
  44. if (year > 1999)
  45. {
  46. year = year - 2000;
  47. }
  48. else
  49. {
  50. year = year - 1900;
  51. }
  52. text[length - 2] = (year / 10) + 0x30;
  53. text[length - 1] = (year % 10) + 0x30;
  54. ViewTextState::writeChars(matrix);
  55. }
  56. else if (controlState != ControlStates::DATE_DATE && controlState != ControlStates::DATE_MONTH && controlState != ControlStates::DATE_YEAR)
  57. {
  58. length = 10;
  59. text[0] = (date / 10) + 0x30;
  60. text[1] = (date % 10) + 0x30;
  61. text[2] = char(delimiter);
  62. text[3] = (month / 10) + 0x30;
  63. text[4] = (month % 10) + 0x30;
  64. text[5] = char(delimiter);
  65. text[6] = ((year / 100) / 10) + 0x30;
  66. text[7] = ((year / 100) % 10) + 0x30;
  67. if (year > 1999)
  68. {
  69. text[8] = ((year - 2000) / 10) + 0x30;
  70. text[9] = ((year - 2000) % 10) + 0x30;
  71. }
  72. else
  73. {
  74. text[8] = ((year - 1900) / 10) + 0x30;
  75. text[9] = ((year - 1900) % 10) + 0x30;
  76. }
  77. position = (millis() / TEXT_INTERVAL - renderOffset - 1) % length;
  78. ViewTextState::writeChars(matrix);
  79. }
  80. renderBinaryClock(matrix, ds3231);
  81. };