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.

218 lines
5.2 KiB

6 years ago
  1. #include <ViewStates.h>
  2. ViewTimeState::ViewTimeState(DS3231 &_ds3231, AT24C32 &_at24c32)
  3. {
  4. ds3231 = _ds3231;
  5. at24c32 = _at24c32;
  6. init();
  7. }
  8. /*
  9. default german matrix layout
  10. 'E', 'S', 'K', 'I', 'S', 'T', 'L', 'F', 'Ü', 'N', 'F',
  11. 'Z', 'E', 'H', 'N', 'Z', 'W', 'A', 'N', 'Z', 'I', 'G',
  12. 'D', 'R', 'E', 'I', 'V', 'I', 'E', 'R', 'T', 'E', 'L',
  13. 'T', 'A', 'N', 'A', 'C', 'H', 'V', 'O', 'R', 'J', 'M',
  14. 'H', 'A', 'L', 'B', 'X', 'Z', 'W', 'Ö', 'L', 'F', 'P',
  15. 'Z', 'W', 'E', 'I', 'N', 'S', 'I', 'E', 'B', 'E', 'N',
  16. 'K', 'D', 'R', 'E', 'I', 'R', 'H', 'F', 'Ü', 'N', 'F',
  17. 'E', 'L', 'F', 'N', 'E', 'U', 'N', 'V', 'I', 'E', 'R',
  18. 'W', 'A', 'C', 'H', 'T', 'Z', 'E', 'H', 'N', 'R', 'S',
  19. 'B', 'S', 'E', 'C', 'H', 'S', 'F', 'M', 'U', 'H', 'R',
  20. 'B', 'S', 'E', 'C', 'H', 'S', 'F', 'M', 'U', 'H', 'R',
  21. '', '', '', '', '', '', '', '', '', '', '',
  22. */
  23. void ViewTimeState::init()
  24. {
  25. text[0] = {0, 0, 1, true};
  26. text[1] = {0, 3, 5, true};
  27. hours[0][0] = {4, 5, 9, true};
  28. hours[0][1] = {0, 0, 0, false};
  29. hours[1][0] = {5, 2, 4, true};
  30. hours[1][1] = {5, 2, 5, true};
  31. hours[2][0] = {5, 0, 3, true};
  32. hours[2][1] = {0, 0, 0, false};
  33. hours[3][0] = {6, 1, 4, true};
  34. hours[3][1] = {0, 0, 0, false};
  35. hours[4][0] = {7, 7, 10, true};
  36. hours[4][1] = {0, 0, 0, false};
  37. hours[5][0] = {6, 7, 10, true};
  38. hours[5][1] = {0, 0, 0, false};
  39. hours[6][0] = {9, 1, 5, true};
  40. hours[6][1] = {0, 0, 0, false};
  41. hours[7][0] = {5, 5, 10, true};
  42. hours[7][1] = {0, 0, 0, false};
  43. hours[8][0] = {8, 1, 4, true};
  44. hours[8][1] = {0, 0, 0, false};
  45. hours[9][0] = {7, 3, 6, true};
  46. hours[9][1] = {0, 0, 0, false};
  47. hours[10][0] = {8, 5, 8, true};
  48. hours[10][1] = {0, 0, 0, false};
  49. hours[11][0] = {7, 0, 2, true};
  50. hours[11][1] = {0, 0, 0, false};
  51. // 0
  52. minutes[0][0] = {9, 8, 10, true};
  53. minutes[0][1] = {0, 0, 0, false};
  54. minutes[0][2] = {0, 0, 0, false};
  55. // 5
  56. minutes[1][0] = {0, 7, 10, true};
  57. minutes[1][1] = {3, 2, 5, true};
  58. minutes[1][2] = {0, 0, 0, false};
  59. // 10
  60. minutes[2][0] = {1, 0, 3, true};
  61. minutes[2][1] = {3, 2, 5, true};
  62. minutes[2][2] = {0, 0, 0, false};
  63. // 15
  64. minutes[3][0] = {2, 4, 10, true};
  65. minutes[3][1] = {3, 2, 5, true};
  66. minutes[3][2] = {0, 0, 0, false};
  67. // 20
  68. minutes[4][0] = {1, 4, 10, true};
  69. minutes[4][1] = {3, 2, 5, true};
  70. minutes[4][2] = {0, 0, 0, false};
  71. // 25
  72. minutes[5][0] = {0, 7, 10, true};
  73. minutes[5][1] = {3, 6, 8, true};
  74. minutes[5][2] = {4, 0, 3, true};
  75. // 30
  76. minutes[6][0] = {4, 0, 3, true};
  77. minutes[6][1] = {0, 0, 0, false};
  78. minutes[6][2] = {0, 0, 0, false};
  79. // 35
  80. minutes[7][0] = {0, 7, 10, true};
  81. minutes[7][1] = {3, 2, 5, true};
  82. minutes[7][2] = {4, 0, 3, true};
  83. // 40
  84. minutes[8][0] = {1, 4, 10, true};
  85. minutes[8][1] = {3, 6, 8, true};
  86. minutes[8][2] = {0, 0, 0, false};
  87. // 45
  88. minutes[9][0] = {2, 4, 10, true};
  89. minutes[9][1] = {3, 6, 8, true};
  90. minutes[9][2] = {0, 0, 0, false};
  91. // 50
  92. minutes[10][0] = {1, 0, 3, true};
  93. minutes[10][1] = {3, 6, 8, true};
  94. minutes[10][2] = {0, 0, 0, false};
  95. // 55
  96. minutes[11][0] = {0, 7, 10, true};
  97. minutes[11][1] = {3, 6, 8, true};
  98. minutes[11][2] = {0, 0, 0, false};
  99. increment = 24;
  100. }
  101. void ViewTimeState::setWessi()
  102. {
  103. init();
  104. minutes[4][0] = {1, 0, 3, true};
  105. minutes[4][1] = {3, 6, 8, true};
  106. minutes[4][2] = {4, 0, 3, true};
  107. minutes[8][0] = {1, 0, 3, true};
  108. minutes[8][1] = {3, 2, 5, true};
  109. minutes[8][2] = {4, 0, 3, true};
  110. increment = 19;
  111. }
  112. void ViewTimeState::setOssi()
  113. {
  114. setWessi();
  115. minutes[3][0] = {2, 4, 10, true};
  116. minutes[3][1] = {0, 0, 0, false};
  117. minutes[9][0] = {2, 0, 10, true};
  118. minutes[9][1] = {0, 0, 0, false};
  119. increment = 14;
  120. }
  121. void ViewTimeState::setWord(uint8_t matrix[121], matrix_entry word)
  122. {
  123. int row;
  124. for (int i = word.columnFrom; i <= word.columnTo; i++)
  125. {
  126. row = word.row * 11 + i;
  127. matrix[row] = color;
  128. }
  129. }
  130. void ViewTimeState::render(uint8_t matrix[121], ControlStates controlState)
  131. {
  132. uint8_t currentMode = at24c32.read(TIME_MODE_ADDRESS);
  133. if (mode != currentMode)
  134. {
  135. mode = currentMode;
  136. switch (mode)
  137. {
  138. case 1:
  139. setWessi();
  140. break;
  141. case 2:
  142. setOssi();
  143. break;
  144. default:
  145. init();
  146. }
  147. }
  148. bool const blink = (millis() / CONTROL_BLINK_INTERVAL) % 2 == 0;
  149. if (controlState != ControlStates::TIME_MODE || blink)
  150. {
  151. setWord(matrix, text[0]);
  152. setWord(matrix, text[1]);
  153. }
  154. uint8_t mm = ds3231.getMinutes();
  155. uint8_t m = mm / 5;
  156. uint8_t h = ds3231.getHours() % 12;
  157. uint8_t s = ds3231.getSeconds();
  158. // increment hours
  159. if (mm > increment)
  160. {
  161. h = (h + 1) % 12;
  162. }
  163. // set hours
  164. if (controlState != ControlStates::TIME_HOURS || blink)
  165. {
  166. setWord(matrix, hours[h][0]);
  167. if (mm >= 5 && hours[h][1].notNull == true)
  168. {
  169. setWord(matrix, hours[h][1]);
  170. }
  171. }
  172. // set 5 minutes
  173. if (controlState != ControlStates::TIME_MINUTES || blink)
  174. {
  175. for (int i = 0; i < 3; i++)
  176. {
  177. if (minutes[m][i].notNull == true)
  178. {
  179. setWord(matrix, minutes[m][i]);
  180. }
  181. }
  182. }
  183. // set minutes
  184. if (mm % 5 > 0)
  185. {
  186. if (controlState != ControlStates::TIME_MINUTES || blink)
  187. {
  188. setWord(matrix, {10, 0, mm % 5 - 1});
  189. }
  190. }
  191. // set seconds
  192. setWord(matrix, {10, 5, 5 + (s / 10)});
  193. }