source: npl/mediabox/lcdproc_edwin/src/server/menus.c

Last change on this file was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 7.5 KB
Line 
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
28int Shutdown_func();
29int System_halt_func();
30int Reboot_func();
31int Close_func();
32int OK_func();
33int Time24_func(int input);
34int Heartbeat_func(int input);
35int Backlight_func(int input);
36int Server_screen_func(int input);
37int Contrast_func(int input);
38int Backlight_Brightness_func(int input);
39int Backlight_Off_Brightness_func(int input);
40int Backlight_Off_func();
41int Backlight_On_func();
42int Backlight_Open_func();
43
44
45menu_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
54menu_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
70menu_item screens_menu[] = {
71  { "SCREENS", TYPE_TITL,          0},  // Title
72  { "Server Scr",TYPE_CHEK,      (void *)Server_screen_func},
73  { 0,             0,              0},
74};
75
76menu_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
84menu_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.
102int Shutdown_func()
103{
104   exit_program(0);
105   
106   return MENU_KILL;
107}
108
109// Shuts down the system, if possible
110int 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
130int 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
149int Close_func()
150{
151   return MENU_CLOSE;
152}
153
154int OK_func()
155{
156   return MENU_OK;
157}
158
159
160int 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
175int 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
186int 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
246int 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
258int 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
276void server_menu()
277{
278   debug("server_menu()\n");
279   
280   do_menu(main_menu);
281 
282}
283
284int 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
301int 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
318int 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
326int 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
334int Backlight_Open_func()
335{
336   backlight = BACKLIGHT_OPEN;
337   return MENU_OK;
338}
339
Note: See TracBrowser for help on using the repository browser.