brewco/keyboard.c

changeset 468
e8203e891b0e
parent 451
2247970de278
equal deleted inserted replaced
467:f4d75ef899f4 468:e8203e891b0e
31 * 10 Milliseconds counts for a key to be short or long pressed. 31 * 10 Milliseconds counts for a key to be short or long pressed.
32 */ 32 */
33 #define PRESS_NORMAL 5 33 #define PRESS_NORMAL 5
34 #define PRESS_LONG 200 34 #define PRESS_LONG 200
35 35
36 /*
37 * LCD timeout in seconds
38 */
39 #define LCD_SLEEP 120
40
41 /*
42 * Menu timeout in seconds
43 */
44 #define MENU_TIMEOUT 60
45
46 36
47 37
48 extern int my_shutdown; 38 extern int my_shutdown;
49 extern int debug; 39 extern int debug;
50 extern int setupmenu; 40 extern int setupmenu;
56 int Key_Return = FALSE; 46 int Key_Return = FALSE;
57 int Key_Up = FALSE; 47 int Key_Up = FALSE;
58 int Key_Down = FALSE; 48 int Key_Down = FALSE;
59 49
60 int previous_key = KEY_NONE; 50 int previous_key = KEY_NONE;
61 int menutimer = 0;
62 51
63 52
64 int keypressed(void); 53 int keypressed(void);
65 54
66 55
126 PI_THREAD (my_keyboard_loop) 115 PI_THREAD (my_keyboard_loop)
127 #else 116 #else
128 void *my_keyboard_loop(void *threadid) 117 void *my_keyboard_loop(void *threadid)
129 #endif 118 #endif
130 { 119 {
131 int Return = 0, Enter = 0, Up = 0, Down = 0, Backlight = LCD_SLEEP, AnyKey = FALSE; 120 int Return = 0, Enter = 0, Up = 0, Down = 0;
132 time_t Last = (time_t)0, Now; 121 time_t Last = (time_t)0, Now;
133 122
134 #ifdef HAVE_WIRINGPI_H 123 #ifdef HAVE_WIRINGPI_H
135 pinMode(PANEL_RETURN, INPUT); 124 pinMode(PANEL_RETURN, INPUT);
136 pinMode(PANEL_ENTER, INPUT); 125 pinMode(PANEL_ENTER, INPUT);
199 Down++; 188 Down++;
200 if (Down > PRESS_NORMAL) 189 if (Down > PRESS_NORMAL)
201 Key_Down = TRUE; 190 Key_Down = TRUE;
202 } 191 }
203 192
204 if (Key_Enter || Key_Return || Key_Up || Key_Down) {
205 AnyKey = TRUE;
206 /*
207 * Any key is pressed.
208 */
209 #ifdef HAVE_WIRINGPI_H
210 piLock(LOCK_LCD);
211 #endif
212 setBacklight(1);
213 #ifdef HAVE_WIRINGPI_H
214 piUnlock(LOCK_LCD);
215 #endif
216 Backlight = LCD_SLEEP;
217 menutimer = 0;
218 } else {
219 /*
220 * No key pressed.
221 */
222 AnyKey = FALSE;
223 }
224
225 Now = time(NULL); 193 Now = time(NULL);
226 if (Now != Last) { 194 if (Now != Last) {
227 Last = Now; 195 Last = Now;
228
229 if (AnyKey == FALSE) {
230 if (Backlight == 1) {
231 #ifdef HAVE_WIRINGPI_H
232 piLock(LOCK_LCD);
233 #endif
234 setBacklight(0);
235 #ifdef HAVE_WIRINGPI_H
236 piUnlock(LOCK_LCD);
237 #endif
238 }
239 if (Backlight > 0) {
240 Backlight--;
241 }
242 }
243 } 196 }
244 197
245 /* 198 /*
246 * Loop 10 milliseconds 199 * Loop 10 milliseconds
247 */ 200 */

mercurial