1 | /* |
---|
2 | menus.c |
---|
3 | |
---|
4 | Defines the default menus the server provides. Also includes the |
---|
5 | plug-in functions attached to menu items... |
---|
6 | |
---|
7 | So far, all menus are static, and not dynamically generated. I'll |
---|
8 | have to find a way to fix this, since many menu items will be dynamic. |
---|
9 | (clients connected, screens available, etc...) |
---|
10 | |
---|
11 | */ |
---|
12 | |
---|
13 | |
---|
14 | #include <stdlib.h> |
---|
15 | #include <stdio.h> |
---|
16 | #include <unistd.h> |
---|
17 | |
---|
18 | #include "../shared/debug.h" |
---|
19 | |
---|
20 | #include "drivers/lcd.h" |
---|
21 | |
---|
22 | #include "main.h" |
---|
23 | #include "menus.h" |
---|
24 | #include "render.h" |
---|
25 | #include "serverscreens.h" |
---|
26 | |
---|
27 | |
---|
28 | int Shutdown_func(); |
---|
29 | int System_halt_func(); |
---|
30 | int Reboot_func(); |
---|
31 | int Close_func(); |
---|
32 | int OK_func(); |
---|
33 | int Time24_func(int input); |
---|
34 | int Heartbeat_func(int input); |
---|
35 | int Backlight_func(int input); |
---|
36 | int Server_screen_func(int input); |
---|
37 | int Contrast_func(int input); |
---|
38 | int Backlight_Brightness_func(int input); |
---|
39 | int Backlight_Off_Brightness_func(int input); |
---|
40 | int Backlight_Off_func(); |
---|
41 | int Backlight_On_func(); |
---|
42 | int Backlight_Open_func(); |
---|
43 | |
---|
44 | |
---|
45 | menu_item main_menu[] = { |
---|
46 | { "LCDproc", 0, 0 },// Title |
---|
47 | { "Options", TYPE_MENU, (void *)options_menu}, |
---|
48 | { "Screens", TYPE_MENU, (void *)screens_menu}, |
---|
49 | { "Shutdown", TYPE_MENU, (void *)shutdown_menu }, |
---|
50 | { 0, 0, 0 }, |
---|
51 | |
---|
52 | }; |
---|
53 | |
---|
54 | menu_item options_menu[] = { |
---|
55 | { "OPTIONS", TYPE_TITL, 0}, // Title |
---|
56 | // "24-hour Time", TYPE_CHEK, (void *)Time24_func, |
---|
57 | { "Contrast...", TYPE_SLID, (void *)Contrast_func}, |
---|
58 | { "Backlight", TYPE_MENU, (void *)Backlight_menu}, |
---|
59 | { "Heartbeat", TYPE_CHEK, (void *)Heartbeat_func}, |
---|
60 | // { "Backlight...", TYPE_SLID, (void *)Backlight_func}, |
---|
61 | // "OK", TYPE_FUNC, (void *)OK_func, |
---|
62 | // "Close Menu", TYPE_FUNC, (void *)Close_func, |
---|
63 | // "Exit Program", TYPE_FUNC, (void *)Shutdown_func, |
---|
64 | // "Another Title",TYPE_TITL, 0, |
---|
65 | // "Main menu?", TYPE_MENU, (void *)main_menu, |
---|
66 | // "Nothing!", TYPE_FUNC, 0, |
---|
67 | { 0, 0, 0}, |
---|
68 | }; |
---|
69 | |
---|
70 | menu_item screens_menu[] = { |
---|
71 | { "SCREENS", TYPE_TITL, 0}, // Title |
---|
72 | { "Server Scr",TYPE_CHEK, (void *)Server_screen_func}, |
---|
73 | { 0, 0, 0}, |
---|
74 | }; |
---|
75 | |
---|
76 | menu_item shutdown_menu[] = { |
---|
77 | { "Shut Down...", TYPE_TITL, 0}, // Title |
---|
78 | { "Kill LCDproc", TYPE_FUNC, (void *)Shutdown_func}, |
---|
79 | { "System halt", TYPE_FUNC, (void *)System_halt_func}, |
---|
80 | { "Reboot", TYPE_FUNC, (void *)Reboot_func}, |
---|
81 | { 0, 0, 0}, |
---|
82 | }; |
---|
83 | |
---|
84 | menu_item Backlight_menu[] = { |
---|
85 | { "BACKLIGHT MENU", TYPE_TITL, 0}, // Title |
---|
86 | { "Brightness...", TYPE_SLID, (void *)Backlight_Brightness_func}, |
---|
87 | { "\"Off\" Brightness", TYPE_SLID, (void *)Backlight_Off_Brightness_func}, |
---|
88 | { "Backlight Mode:", TYPE_FUNC, 0}, // Label |
---|
89 | { " - Off", TYPE_FUNC, Backlight_Off_func}, |
---|
90 | { " - On", TYPE_FUNC, Backlight_On_func}, |
---|
91 | { " - Open", TYPE_FUNC, Backlight_Open_func}, |
---|
92 | { 0, 0, 0}, |
---|
93 | }; |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | /////////////////////////////////////////////////////////////////////// |
---|
98 | // Plug-in functions for menu items |
---|
99 | // |
---|
100 | |
---|
101 | // Exits the program. |
---|
102 | int Shutdown_func() |
---|
103 | { |
---|
104 | exit_program(0); |
---|
105 | |
---|
106 | return MENU_KILL; |
---|
107 | } |
---|
108 | |
---|
109 | // Shuts down the system, if possible |
---|
110 | int System_halt_func() |
---|
111 | { |
---|
112 | int err; |
---|
113 | uid_t id; |
---|
114 | |
---|
115 | id = geteuid(); |
---|
116 | |
---|
117 | err = system("init 0"); |
---|
118 | |
---|
119 | if(err < 0) return MENU_KILL; |
---|
120 | if(err == 127) return MENU_KILL; |
---|
121 | |
---|
122 | // If we're root, exit |
---|
123 | if(id == 0) exit_program(0); |
---|
124 | |
---|
125 | // Otherwise, assume shutdown will fail; and show more stats. |
---|
126 | return MENU_KILL; |
---|
127 | } |
---|
128 | |
---|
129 | // Shuts down the system and restarts it |
---|
130 | int Reboot_func() |
---|
131 | { |
---|
132 | int err; |
---|
133 | uid_t id; |
---|
134 | |
---|
135 | id = geteuid(); |
---|
136 | |
---|
137 | err = system("init 6"); |
---|
138 | |
---|
139 | if(err < 0) return MENU_KILL; |
---|
140 | if(err == 127) return MENU_KILL; |
---|
141 | |
---|
142 | // If we're root, exit |
---|
143 | if(id == 0) exit_program(0); |
---|
144 | |
---|
145 | // Otherwise, assume shutdown will fail; and show more stats. |
---|
146 | return MENU_KILL; |
---|
147 | } |
---|
148 | |
---|
149 | int Close_func() |
---|
150 | { |
---|
151 | return MENU_CLOSE; |
---|
152 | } |
---|
153 | |
---|
154 | int OK_func() |
---|
155 | { |
---|
156 | return MENU_OK; |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | int Time24_func(int input) |
---|
161 | { |
---|
162 | static int status=0; |
---|
163 | |
---|
164 | if(input == MENU_READ) return status; |
---|
165 | if(input == MENU_CHECK) status ^= 1; // does something. |
---|
166 | return (status | MENU_OK); |
---|
167 | // The status is "or"-ed with the MENU value to let do_menu() |
---|
168 | // know what to do after selecting the item. (two return |
---|
169 | // values in one. :) |
---|
170 | |
---|
171 | // Also, "MENU_OK" happens to be zero, so it does not matter |
---|
172 | // unless you want something else (like MENU_CLOSE) |
---|
173 | } |
---|
174 | |
---|
175 | int Heartbeat_func(int input) |
---|
176 | { |
---|
177 | if(input == MENU_READ) return (heartbeat != HEART_OFF); |
---|
178 | if(input == MENU_CHECK) |
---|
179 | { |
---|
180 | if(heartbeat) heartbeat = HEART_OFF; |
---|
181 | else heartbeat = HEART_OPEN; |
---|
182 | } |
---|
183 | return ((heartbeat != HEART_OFF) | MENU_OK); |
---|
184 | } |
---|
185 | |
---|
186 | int Backlight_func(int input) |
---|
187 | { |
---|
188 | int status = 128; |
---|
189 | |
---|
190 | switch(backlight) |
---|
191 | { |
---|
192 | case BACKLIGHT_OFF: |
---|
193 | if(input == MENU_READ) status = 0; |
---|
194 | if(input == MENU_PLUS) |
---|
195 | { |
---|
196 | backlight = BACKLIGHT_OPEN; |
---|
197 | status = 128; |
---|
198 | } |
---|
199 | if(input == MENU_MINUS) |
---|
200 | { |
---|
201 | status = 0; |
---|
202 | } |
---|
203 | break; |
---|
204 | case BACKLIGHT_ON: |
---|
205 | if(input == MENU_READ) status = 255; |
---|
206 | if(input == MENU_PLUS) |
---|
207 | { |
---|
208 | status = 255; |
---|
209 | } |
---|
210 | if(input == MENU_MINUS) |
---|
211 | { |
---|
212 | backlight = BACKLIGHT_OPEN; |
---|
213 | status = 128; |
---|
214 | } |
---|
215 | break; |
---|
216 | case BACKLIGHT_OPEN: |
---|
217 | if(input == MENU_READ) status = 128; |
---|
218 | if(input == MENU_PLUS) |
---|
219 | { |
---|
220 | backlight = BACKLIGHT_ON; |
---|
221 | backlight_state = BACKLIGHT_ON; |
---|
222 | status = 255; |
---|
223 | } |
---|
224 | if(input == MENU_MINUS) |
---|
225 | { |
---|
226 | backlight = BACKLIGHT_OFF; |
---|
227 | backlight_state = BACKLIGHT_OFF; |
---|
228 | status = 0; |
---|
229 | } |
---|
230 | break; |
---|
231 | } |
---|
232 | |
---|
233 | /* |
---|
234 | if(input == MENU_READ) return (backlight != BACKLIGHT_OFF); |
---|
235 | if(input == MENU_CHECK) |
---|
236 | { |
---|
237 | if(backlight) backlight = BACKLIGHT_OFF; |
---|
238 | else backlight = BACKLIGHT_OPEN; |
---|
239 | } |
---|
240 | */ |
---|
241 | lcd.backlight(backlight_state & BACKLIGHT_ON); |
---|
242 | |
---|
243 | return (status | MENU_OK); |
---|
244 | } |
---|
245 | |
---|
246 | int Server_screen_func(int input) |
---|
247 | { |
---|
248 | if(input == MENU_READ) return (server_screen->priority < 256); |
---|
249 | if(input == MENU_CHECK) |
---|
250 | { |
---|
251 | if(server_screen->priority < 256) server_screen->priority = 256; |
---|
252 | else server_screen->priority = 128; |
---|
253 | } |
---|
254 | |
---|
255 | return (MENU_OK | (server_screen->priority < 256)); |
---|
256 | } |
---|
257 | |
---|
258 | int Contrast_func(int input) |
---|
259 | { |
---|
260 | int status; |
---|
261 | |
---|
262 | status=lcd.contrast(-1); |
---|
263 | |
---|
264 | if(input == MENU_READ) return status; |
---|
265 | if(input == MENU_PLUS) status+=5; // does something. |
---|
266 | if(input == MENU_MINUS) status-=5; // does something. |
---|
267 | |
---|
268 | if(status<0) status=0; |
---|
269 | if(status>255) status=255; |
---|
270 | lcd.contrast(status); |
---|
271 | |
---|
272 | return (status | MENU_OK); |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | void server_menu() |
---|
277 | { |
---|
278 | debug("server_menu()\n"); |
---|
279 | |
---|
280 | do_menu(main_menu); |
---|
281 | |
---|
282 | } |
---|
283 | |
---|
284 | int Backlight_Brightness_func(int input) |
---|
285 | { |
---|
286 | int status = backlight_brightness; |
---|
287 | |
---|
288 | if(input == MENU_READ) return status; |
---|
289 | if(input == MENU_PLUS) status+=5; // does something. |
---|
290 | if(input == MENU_MINUS) status-=5; // does something. |
---|
291 | |
---|
292 | if(status<0) status=0; |
---|
293 | if(status>255) status=255; |
---|
294 | lcd.backlight(status); |
---|
295 | |
---|
296 | backlight_brightness = status; |
---|
297 | |
---|
298 | return (status | MENU_OK); |
---|
299 | } |
---|
300 | |
---|
301 | int Backlight_Off_Brightness_func(int input) |
---|
302 | { |
---|
303 | int status = backlight_off_brightness; |
---|
304 | |
---|
305 | if(input == MENU_READ) return status; |
---|
306 | if(input == MENU_PLUS) status+=5; // does something. |
---|
307 | if(input == MENU_MINUS) status-=5; // does something. |
---|
308 | |
---|
309 | if(status<0) status=0; |
---|
310 | if(status>255) status=255; |
---|
311 | lcd.backlight(status); |
---|
312 | |
---|
313 | backlight_off_brightness = status; |
---|
314 | |
---|
315 | return (status | MENU_OK); |
---|
316 | } |
---|
317 | |
---|
318 | int Backlight_Off_func() |
---|
319 | { |
---|
320 | backlight_state = BACKLIGHT_OFF; |
---|
321 | backlight = BACKLIGHT_OFF; |
---|
322 | lcd.backlight(backlight_off_brightness); |
---|
323 | return MENU_OK; |
---|
324 | } |
---|
325 | |
---|
326 | int Backlight_On_func() |
---|
327 | { |
---|
328 | backlight_state = BACKLIGHT_ON; |
---|
329 | backlight = BACKLIGHT_ON; |
---|
330 | lcd.backlight(backlight_brightness * (backlight_state & BACKLIGHT_ON)); |
---|
331 | return MENU_OK; |
---|
332 | } |
---|
333 | |
---|
334 | int Backlight_Open_func() |
---|
335 | { |
---|
336 | backlight = BACKLIGHT_OPEN; |
---|
337 | return MENU_OK; |
---|
338 | } |
---|
339 | |
---|