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.

141 lines
2.5 KiB

6 years ago
  1. #ifndef ViewState_h
  2. #define ViewState_h
  3. #include <States.h>
  4. #include <DS3231.h>
  5. #include <AT24C32.h>
  6. using namespace std;
  7. // I2C address
  8. #define TEXT_INTERVAL 1000
  9. #define CONTROL_BLINK_INTERVAL 250
  10. /**
  11. led matrix entry
  12. */
  13. struct matrix_entry
  14. {
  15. uint8_t row;
  16. uint8_t columnFrom;
  17. uint8_t columnTo;
  18. bool notNull;
  19. };
  20. /**
  21. abstract view state
  22. */
  23. class ViewState
  24. {
  25. public:
  26. virtual void render(uint8_t matrix[121], ControlStates controlState) = 0;
  27. void setColor(uint8_t _color);
  28. protected:
  29. void renderBinaryClock(uint8_t matrix[121], DS3231 &ds3231);
  30. uint8_t color = 0xFF;
  31. };
  32. /**
  33. view time state
  34. */
  35. class ViewTimeState : public ViewState
  36. {
  37. public:
  38. ViewTimeState(DS3231 &_ds3231, AT24C32 &_at24c32);
  39. void render(uint8_t matrix[121], ControlStates controlState);
  40. protected:
  41. DS3231 ds3231;
  42. AT24C32 at24c32;
  43. matrix_entry text[2];
  44. matrix_entry hours[12][2];
  45. matrix_entry minutes[12][3];
  46. uint8_t increment;
  47. uint8_t mode = 0;
  48. void init();
  49. void setWord(uint8_t matrix[121], matrix_entry word);
  50. void setWessi();
  51. void setOssi();
  52. };
  53. /**
  54. view text state
  55. */
  56. class ViewTextState : public ViewState
  57. {
  58. public:
  59. ViewTextState(AT24C32 &_at24c32);
  60. void render(uint8_t matrix[121], ControlStates controlState);
  61. protected:
  62. void writeText(uint8_t matrix[121]);
  63. void writeChars(uint8_t matrix[121]);
  64. AT24C32 at24c32;
  65. uint8_t text[0xFF];
  66. uint8_t length = 0;
  67. uint8_t position = 0;
  68. uint8_t v_offset = 1;
  69. long renderOffset;
  70. };
  71. /**
  72. view seconds state
  73. */
  74. class ViewSecondsState : public ViewTextState
  75. {
  76. public:
  77. ViewSecondsState(DS3231 &_ds3231, AT24C32 &_at24c32);
  78. void render(uint8_t matrix[121], ControlStates controlState);
  79. protected:
  80. DS3231 ds3231;
  81. };
  82. /**
  83. view temperature state
  84. */
  85. class ViewTemperatureState : public ViewTextState
  86. {
  87. public:
  88. ViewTemperatureState(DS3231 &_ds3231, AT24C32 &_at24c32);
  89. void render(uint8_t matrix[121], ControlStates controlState);
  90. protected:
  91. DS3231 ds3231;
  92. };
  93. /**
  94. view date state
  95. */
  96. class ViewDateState : public ViewTextState
  97. {
  98. public:
  99. ViewDateState(DS3231 &_ds3231, AT24C32 &_at24c32, char _delimiter);
  100. void render(uint8_t matrix[121], ControlStates controlState);
  101. protected:
  102. DS3231 ds3231;
  103. char delimiter;
  104. };
  105. /**
  106. view LED demo state
  107. */
  108. class ViewLEDState : public ViewState
  109. {
  110. public:
  111. ViewLEDState();
  112. void render(uint8_t matrix[121], ControlStates controlState);
  113. };
  114. /**
  115. view Remote demo state
  116. */
  117. class ViewRemoteState : public ViewState
  118. {
  119. public:
  120. ViewRemoteState();
  121. void render(uint8_t matrix[121], ControlStates controlState);
  122. };
  123. #endif