-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_page.h
169 lines (136 loc) · 5.57 KB
/
main_page.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// ------------------------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------
static const page_definition_t * page_current;
static const page_definition_t * page_pending;
static void page_handler__command (const command_t command) {
if (strcmp (command.name, command__pat.name) == 0)
return;
if (page_current->action_command (command))
display_update ();
}
static void page_handler__touched (const position_t position) {
static uint32_t spaced = 0;
if (!__isspaced (&spaced, DISPLAY_BUTTON_MINIMUM_MSECS))
return;
if (display_content_touched (page_current->buttons_enabled ? corners_content : corners_screen, position)) {
debug ("page_content: touched");
if (page_current->action_touch != NULL)
if (page_current->action_touch ())
display_update ();
} else if (page_current->buttons_enabled) {
for (int i = 0; i < PAGE_BUTTONS; i ++) {
const position_t position_button [2] = {
display_content_button_positions [i],
{ display_content_button_positions [i].x + DISPLAY_BUTTON_W, display_content_button_positions [i].y + DISPLAY_BUTTON_H }
};
if (display_content_touched (position_button, position)) {
debug ("page_button: touched (%s)", page_current->buttons [i].name);
if (page_current->buttons [i].handler != NULL)
if (page_current->buttons [i].handler ())
display_update ();
return;
}
}
}
}
static void page_handler__sidekey (__attribute__ ((unused)) sidekey_t sidekey) {
static uint32_t spaced = 0;
if (!__isspaced (&spaced, DISPLAY_BUTTON_MINIMUM_MSECS))
return;
/* not used */
}
static bool page_handler__timer (struct repeating_timer * const t) {
if (page_current->action_timer != NULL)
if (page_current->action_timer ((uint32_t) (t->delay_us / 1000)))
display_update ();
return true;
}
static bool page_handler__timer_pat (__attribute__ ((unused)) struct repeating_timer * const t) {
console_send (command__pat);
const char * const watchdog_rebooted = hardware_watchdog_reboot ();
if (watchdog_rebooted != NULL) {
char buf [64];
snprintf (buf, sizeof (buf) - 1, "note: watchdog_reboot (%s)", watchdog_rebooted);
command_t command = { command__put_logs.name, buf };
console_send (command);
}
return true;
}
static bool page_handler__timer_cond (__attribute__ ((unused)) struct repeating_timer * const t) {
char buf [20];
snprintf (buf, sizeof (buf) - 1, "temp=%0.2f", hardware_temp_get ());
command_t command = { command__put_cond.name, buf };
console_send (command);
return true;
}
static const uint32_t page_interval = 1000;
static struct repeating_timer page_content__timer;
static struct repeating_timer page_content__timer_pat;
static struct repeating_timer page_content__timer_cond;
static void page_timers_start (void) {
add_repeating_timer_ms (page_interval, page_handler__timer, NULL, &page_content__timer);
add_repeating_timer_ms (command_interval_pat, page_handler__timer_pat, NULL, &page_content__timer_pat);
add_repeating_timer_ms (command_interval_put_cond, page_handler__timer_cond, NULL, &page_content__timer_cond);
}
static void page_timers_stop (void) {
cancel_repeating_timer (&page_content__timer);
cancel_repeating_timer (&page_content__timer_pat);
cancel_repeating_timer (&page_content__timer_cond);
}
static void page_init (void) {
}
static bool page_enter (const page_definition_t * const page) {
bool updated = false;
if (page->buttons_enabled) {
for (int i = 0; i < PAGE_BUTTONS; i ++)
if (page->buttons [i].font != NULL)
if (display_content_button (display_content_button_positions [i], page->buttons [i].font, page->buttons [i].code)) updated = true;
}
if (page->action_enter != NULL)
if (page->action_enter ()) updated = true;
page_current = page;
return updated;
}
static bool page_leave (void) {
if (page_current->action_leave != NULL)
return page_current->action_leave ();
return false;
}
static bool page_change (const page_definition_t * const page) {
page_pending = page;
return false;
}
static bool __page_change (const page_definition_t * const page) {
bool updated = false;
if (page != page_current) {
debug ("page_change: %s --> %s", page_current->name, page->name);
if (page_leave ()) updated = true;
if (page_enter (page)) updated = true;
}
return updated;
}
static void page_open (void) {
page_init ();
page_current = page_pending = NULL;
page_enter (&page_definition_home);
display_update (); /* always */
page_timers_start ();
}
static void page_close (void) {
page_timers_stop ();
page_leave ();
display_update (); /* always */
}
static void page_update (void) {
bool updated = false;
if (page_pending != NULL) {
const page_definition_t * page = page_pending;
page_pending = NULL;
if (__page_change (page)) updated = true;
}
if (updated)
display_update ();
}
// ------------------------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------