The first version that was demonstrated to get an IPv6 address
[firmerware] / src / driver / util / ledsimu.c
1 /* LED simulation support -- print them in tabbed columns
2  *
3  * This file is part of 0cpm Firmerware.
4  *
5  * 0cpm Firmerware is Copyright (c)2011 Rick van Rein, OpenFortress.
6  *
7  * 0cpm Firmerware is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation, version 3.
10  *
11  * 0cpm Firmerware is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with 0cpm Firmerware.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21
22 /* Descriptions below are all restricted to 7 chars or less, so they
23  * can be printed with a '\t' in between.
24  *
25  * From: Rick van Rein <rick@openfortress.nl>
26  */
27
28
29 #include <stdlib.h>
30 #include <stdarg.h>
31
32 #include <config.h>
33
34 #include <0cpm/led.h>
35 #include <0cpm/cons.h>
36
37
38 char *led_colours_2 [] = { "off", "green" };
39 char *led_colours_3 [] = { "off", "green", "red" };
40
41 struct led_descript {
42         char *name;
43         char **states;
44         char *current;
45 };
46
47 /*
48  * LED descriptive structure, following the structure of led.h
49  */
50 struct led_descript num2descr [] = {
51 #if HAVE_LED_LINEKEYS
52 #  if NUM_LINEKEYS >= 1
53         { "line1", led_colours_3, NULL, },
54 #  endif
55 #  if NUM_LINEKEYS >= 2
56         { "line2", led_colours_3, NULL, },
57 #  endif
58 #  if NUM_LINEKEYS >= 3
59         { "line3", led_colours_3, NULL, },
60 #  endif
61 #  if NUM_LINEKEYS >= 4
62         { "line4", led_colours_3, NULL, },
63 #  endif
64 #  if NUM_LINEKEYS >= 5
65         { "line5", led_colours_3, NULL, },
66 #  endif
67 #  if NUM_LINEKEYS >= 6
68         { "line6", led_colours_3, NULL, },
69 #  endif
70 #  if NUM_LINEKEYS >= 7
71 #       error "Please define additional line LEDs in ledsimu.c"
72 #  endif
73 #endif
74 #if HAVE_LED_GENERIC
75 #       error "Please define generic LEDs in ledsimu.c"
76 #endif
77 #if HAVE_LED_MESSAGE
78         { "vmail", led_colours_2, NULL, },
79 #endif
80 #if HAVE_LED_MUTE
81         { "mute", led_colours_2, NULL, },
82 #endif
83 #if HAVE_LED_HANDSET
84         { "handset", led_colours_2, NULL, },
85 #endif
86 #if HAVE_LED_HEADSET
87         { "headset", led_colours_2, NULL, },
88 #endif
89 #if HAVE_LED_SPEAKERPHONE
90         { "speaker", led_colours_2, NULL, },
91 #endif
92 #if HAVE_LED_BACKLIGHT
93         { "display", led_colours_2, NULL, },
94 #endif
95 };
96
97
98 void bottom_led_set (led_idx_t lednum, led_colour_t col) {
99         int i;
100         struct timeval tv;
101         gettimeofday (&tv, NULL);
102         static headctr = 0;
103         if (headctr++ % 20 == 0) {
104                 for (i = 0; i < LED_IDX_COUNT; i++) {
105                         bottom_printf ("\t%s", num2descr [i].name);
106                 }
107                 bottom_printf ("\n");
108         }
109         bottom_printf ("%3d.%03d", tv.tv_sec, tv.tv_usec / 1000);
110         char capscol [8];
111         char *colnm = num2descr [lednum].states [col];
112         for (i = 0; i < 7; i++) {
113                 if (colnm [i] == 0) {
114                         break;
115                 }
116                 capscol [i] = toupper (colnm [i]);
117         }
118         capscol [i] = '\0';
119         for (i = 0; i < LED_IDX_COUNT; i++) {
120                 if (i == lednum) {
121                         colnm = capscol;
122                 } else if (num2descr [lednum].current != NULL) {
123                         colnm = num2descr [lednum].current;
124                 } else {
125                         colnm = "UNSET";
126                 }
127                 bottom_printf ("\t%s", colnm);
128         }
129         bottom_printf ("\n");
130 }