gui.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. gui.h
  3. */
  4. #ifndef _GUI_H
  5. #define _GUI_H
  6. #include "menu.h"
  7. extern u8g2_t u8g2;
  8. #define GUI_STATE_STOP 0
  9. #define GUI_STATE_SIGNAL_ALARM 1
  10. #define GUI_STATE_DISPLAY_TIME 2
  11. #define GUI_STATE_MENU 3
  12. #define GUI_ALARM_CNT 4
  13. #define SNOOZE_MINUTES 5
  14. #define ALLOW_SKIP_HOURS 10
  15. struct _gui_data
  16. {
  17. uint16_t uptime; /* uptime in days, 10 bits, counts from 0 to 999, this value will be stored in the backup register */
  18. uint16_t week_time; /* calculated: derived from h, mt, mo and weekday */
  19. uint8_t gui_state; /* global running state, see guistate.c, defaults to 0 (GUI_STATE_STOP) */
  20. uint8_t h, mt, mo, st, so; /* input: current time */
  21. uint8_t day; /* input: 1 .. 31 current day in month */
  22. uint8_t last_day; /* last day. This is used to check, whether the day has changed. Required for uptime calc. This is also stored in the backup register. */
  23. uint8_t month; /* input: 1..12 */
  24. uint8_t year_t, year_o; /* input: current year */
  25. uint8_t weekday; /* calculated: 0 = Monday */
  26. uint8_t next_alarm_index; /* calculated: index for the next alarm or GUI_ALARM_CNT if there is no next alarm */
  27. uint8_t is_skip_possible; /* calculated: whether the next alarm (next_alarm_index) can be skipped */
  28. uint8_t is_equal; /* calculated: whether the current time matches any alarm, will be set to 0 automatically */
  29. uint8_t equal_h;
  30. uint8_t equal_mt;
  31. uint8_t equal_mo;
  32. uint8_t is_alarm; /* input/calculated: set by the software, has to be reset by the user */
  33. uint8_t active_alarm_idx; /* input/calculated: set by the software, has to be reset by the user */
  34. uint8_t contrast; /* value 1..7, 0 is default (do not set) */
  35. uint8_t display_voltage;
  36. char s[16]; /* string buffer */
  37. };
  38. typedef struct _gui_data gui_data_t;
  39. struct _gui_alarm_struct
  40. {
  41. /* next alarm, all na_ fields are derived from the alarm information */
  42. uint16_t na_week_time_in_minutes;
  43. uint16_t na_minutes_diff; /* calculated: time in minutes until next alarm, 0x0ffff = no alarm */
  44. uint8_t na_h; /* calculated */
  45. uint8_t na_m; /* calculated */
  46. uint8_t na_wd; /* calculated: 0...7, 0=monday, 7=no alarm */
  47. /* alarm information */
  48. uint8_t snooze_count; /* input, 1 bit*/
  49. volatile uint8_t enable; /* input, 1 bit */
  50. uint8_t skip_wd; /* input 0 = no skip, 1 = Monday, ... 3 bits*/
  51. uint8_t h; /* input 5 bits */
  52. uint8_t m; /* input 6 bits */
  53. uint8_t wd[7]; /* input: 0 or 1, 0=weekday not selected, 7 bits */
  54. };
  55. typedef struct _gui_alarm_struct gui_alarm_t;
  56. /* guimenu.c */
  57. extern const me_t melist_setup_time[];
  58. extern const me_t melist_display_time[];
  59. extern const me_t melist_setup_date[];
  60. extern const me_t melist_setup_alarm[];
  61. extern const me_t melist_alarm_menu[];
  62. extern const me_t melist_setup_menu[];
  63. extern const me_t melist_active_alarm_menu[];
  64. extern const me_t melist_top_menu[];
  65. /* guifn.c */
  66. extern gui_alarm_t gui_alarm_list[GUI_ALARM_CNT];
  67. extern char gui_alarm_str[GUI_ALARM_CNT][8];
  68. extern gui_data_t gui_data;
  69. extern menu_t gui_menu;
  70. void gui_date_adjust(void);
  71. void gui_LoadData(void);
  72. void gui_Recalculate(void);
  73. void gui_SignalTimeChange(void);
  74. void gui_Init(u8g2_t *u8g2, uint8_t is_por);
  75. void gui_Draw(void);
  76. void gui_Next(void);
  77. void gui_Select(void);
  78. /* guihal.c */
  79. void do_reset(void);
  80. void store_gui_data(uint32_t *data);
  81. void load_gui_data(uint32_t *data);
  82. int is_por_reset(void);
  83. int is_button_reset(void);
  84. uint32_t get_boot_status_register(void);
  85. uint32_t get_pwr_status_register(void);
  86. uint32_t get_reset_reason(void);
  87. uint32_t get_wakeup_count(void);
  88. uint32_t get_dst_by_date(void);
  89. uint32_t get_dst_by_RTC(void);
  90. void enable_alarm(void);
  91. void disable_alarm(void);
  92. void set_time(uint8_t ht, uint8_t ho, uint8_t mt, uint8_t mo, uint8_t st, uint8_t so);
  93. void set_date(uint8_t yt, uint8_t yo, uint8_t mt, uint8_t mo, uint8_t dayt, uint8_t dayo, uint8_t weekday);
  94. void set_contrast(void); /* set contrast to gui_data.contrast, value 1..7, 0 is default (do not set) */
  95. #endif