Gigabeat S: Do simple direct keypad scanning rather than triggering a separate scan...
[kugel-rb.git] / apps / plugins / lamp.c
blob3400107407250d353d7774f1e723cc2cd54e8672
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Vuong Minh Hiep (vmh)
11 * Copyright (C) 2008 Thomas Martitz (kugel.)
12 * Copyright (C) 2008 Alexander Papst
13 * Copyright (C) 2008 Peter D'Hoye
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
25 #include "plugin.h"
26 #include "lib/helper.h"
28 /* variable button definitions.
29 - only targets with a colour display
30 LAMP_LEFT / LAMP_RIGHT: change the color
31 LAMP_NEXT / LAMP_PREV: (optional) change the color
32 - only targets which can set brightness
33 LAMP_UP / LAMP_DOWN: change the brightness
35 #if defined(HAVE_LCD_COLOR) || defined(HAVE_BACKLIGHT_BRIGHTNESS)
36 #if (CONFIG_KEYPAD == IRIVER_H300_PAD)
37 # define LAMP_LEFT BUTTON_LEFT
38 # define LAMP_RIGHT BUTTON_RIGHT
39 # define LAMP_UP BUTTON_UP
40 # define LAMP_DOWN BUTTON_DOWN
42 #elif (CONFIG_KEYPAD == IPOD_4G_PAD)
43 # define LAMP_LEFT BUTTON_LEFT
44 # define LAMP_RIGHT BUTTON_RIGHT
45 # define LAMP_UP BUTTON_SCROLL_FWD
46 # define LAMP_DOWN BUTTON_SCROLL_BACK
48 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
49 # define LAMP_LEFT BUTTON_LEFT
50 # define LAMP_RIGHT BUTTON_RIGHT
51 # define LAMP_UP BUTTON_UP
52 # define LAMP_DOWN BUTTON_DOWN
54 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
55 # define LAMP_LEFT BUTTON_LEFT
56 # define LAMP_RIGHT BUTTON_RIGHT
57 # define LAMP_UP BUTTON_UP
58 # define LAMP_DOWN BUTTON_DOWN
60 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
61 # define LAMP_LEFT BUTTON_LEFT
62 # define LAMP_RIGHT BUTTON_RIGHT
63 # define LAMP_UP BUTTON_UP
64 # define LAMP_DOWN BUTTON_DOWN
66 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
67 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
68 # define LAMP_LEFT BUTTON_LEFT
69 # define LAMP_RIGHT BUTTON_RIGHT
70 # define LAMP_UP BUTTON_SCROLL_FWD
71 # define LAMP_DOWN BUTTON_SCROLL_BACK
73 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
74 # define LAMP_LEFT BUTTON_LEFT
75 # define LAMP_RIGHT BUTTON_RIGHT
76 # define LAMP_UP BUTTON_UP
77 # define LAMP_DOWN BUTTON_DOWN
79 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
80 # define LAMP_LEFT BUTTON_LEFT
81 # define LAMP_RIGHT BUTTON_RIGHT
82 # define LAMP_NEXT BUTTON_SCROLL_UP
83 # define LAMP_PREV BUTTON_SCROLL_DOWN
85 #elif CONFIG_KEYPAD == MROBE500_PAD
86 # define LAMP_LEFT BUTTON_LEFT
87 # define LAMP_RIGHT BUTTON_RIGHT
89 #elif CONFIG_KEYPAD == COWON_D2_PAD
91 #elif CONFIG_KEYPAD == IAUDIO67_PAD
92 # define LAMP_LEFT BUTTON_LEFT
93 # define LAMP_RIGHT BUTTON_RIGHT
95 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
96 # define LAMP_LEFT BUTTON_LEFT
97 # define LAMP_RIGHT BUTTON_RIGHT
98 # define LAMP_UP BUTTON_UP
99 # define LAMP_DOWN BUTTON_DOWN
101 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
102 # define LAMP_LEFT BUTTON_LEFT
103 # define LAMP_RIGHT BUTTON_RIGHT
104 # define LAMP_UP BUTTON_UP
105 # define LAMP_DOWN BUTTON_DOWN
107 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
108 # define LAMP_LEFT BUTTON_PREV
109 # define LAMP_RIGHT BUTTON_NEXT
110 # define LAMP_UP BUTTON_UP
111 # define LAMP_DOWN BUTTON_DOWN
113 #elif CONFIG_KEYPAD == ONDAVX747_PAD
114 # define LAMP_LEFT BUTTON_VOL_DOWN
115 # define LAMP_RIGHT BUTTON_VOL_UP
117 #elif CONFIG_KEYPAD == ONDAVX777_PAD
119 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
120 # define LAMP_LEFT BUTTON_LEFT
121 # define LAMP_RIGHT BUTTON_RIGHT
123 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
124 # define LAMP_LEFT BUTTON_PREV
125 # define LAMP_RIGHT BUTTON_NEXT
126 # define LAMP_UP BUTTON_UP
127 # define LAMP_DOWN BUTTON_DOWN
129 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
130 # define LAMP_UP BUTTON_REW
131 # define LAMP_DOWN BUTTON_FF
133 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
134 # define LAMP_UP BUTTON_UP
135 # define LAMP_DOWN BUTTON_DOWN
137 #else
138 # error Missing key definitions for this keypad
139 #endif
140 #endif /* HAVE_LCD_COLOR || HAVE_BACKLIGHT_BRIGHTNESS */
142 #ifdef HAVE_TOUCHSCREEN
143 # ifndef LAMP_LEFT
144 # define LAMP_LEFT BUTTON_MIDLEFT
145 # endif
146 # ifndef LAMP_RIGHT
147 # define LAMP_RIGHT BUTTON_MIDRIGHT
148 # endif
149 # ifndef LAMP_UP
150 # define LAMP_UP BUTTON_TOPMIDDLE
151 # endif
152 # ifndef LAMP_DOWN
153 # define LAMP_DOWN BUTTON_BOTTOMMIDDLE
154 # endif
155 #endif
157 #ifdef HAVE_LCD_COLOR
158 /* RGB color sets */
159 #define NUM_COLORSETS 2
160 static unsigned colorset[NUM_COLORSETS] = {
161 LCD_RGBPACK(255, 255, 255), /* white */
162 LCD_RGBPACK(255, 0, 0), /* red */
164 #endif /* HAVE_LCD_COLOR */
166 /* this is the plugin entry point */
167 enum plugin_status plugin_start(const void* parameter)
169 enum plugin_status status = PLUGIN_OK;
170 long button;
171 bool quit = false;
172 (void)parameter;
174 #ifdef HAVE_LCD_COLOR
175 int cs = 0;
176 bool update = false;
177 #endif /* HAVE_LCD_COLOR */
179 #if LCD_DEPTH > 1
180 unsigned bg_color = rb->lcd_get_background();
181 rb->lcd_set_backdrop(NULL);
182 rb->lcd_set_background(LCD_WHITE);
183 #endif
185 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
186 int current_brightness = MAX_BRIGHTNESS_SETTING;
187 backlight_brightness_set(MAX_BRIGHTNESS_SETTING);
188 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
189 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
190 buttonlight_brightness_set(MAX_BRIGHTNESS_SETTING);
191 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
193 #ifdef HAVE_LCD_INVERT
194 #ifdef HAVE_NEGATIVE_LCD
195 rb->lcd_set_invert_display(true);
196 #else
197 rb->lcd_set_invert_display(false);
198 #endif /* HAVE_NEGATIVE_LCD */
199 #endif /* HAVE_LCD_INVERT */
201 backlight_force_on();
202 #ifdef HAVE_BUTTON_LIGHT
203 buttonlight_force_on();
204 #endif /* HAVE_BUTTON_LIGHT */
206 rb->lcd_clear_display();
207 rb->lcd_update();
211 #ifdef HAVE_LCD_COLOR
212 if(update)
214 if(cs < 0)
215 cs = NUM_COLORSETS-1;
216 if(cs >= NUM_COLORSETS)
217 cs = 0;
218 rb->lcd_set_background(colorset[cs]);
219 rb->lcd_clear_display();
220 rb->lcd_update();
221 update = false;
223 #endif /* HAVE_LCD_COLOR */
225 switch((button = rb->button_get_w_tmo(HZ*30)))
227 #ifdef HAVE_LCD_COLOR
228 case LAMP_RIGHT:
229 #ifdef LAMP_NEXT
230 case LAMP_NEXT:
231 #endif /* LAMP_NEXT */
232 cs++;
233 update = true;
234 break;
236 case LAMP_LEFT:
237 #ifdef LAMP_PREV
238 case LAMP_PREV:
239 #endif /* LAMP_PREV */
240 cs--;
241 update = true;
242 break;
243 #endif /* HAVE_LCD_COLOR */
245 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
246 case LAMP_UP:
247 case (LAMP_UP|BUTTON_REPEAT):
248 if (current_brightness < MAX_BRIGHTNESS_SETTING)
249 backlight_brightness_set(++current_brightness);
250 break;
252 case LAMP_DOWN:
253 case (LAMP_DOWN|BUTTON_REPEAT):
254 if (current_brightness > MIN_BRIGHTNESS_SETTING)
255 backlight_brightness_set(--current_brightness);
256 break;
257 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
258 case BUTTON_NONE:
259 /* time out */
260 break;
262 default:
263 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
265 status = PLUGIN_USB_CONNECTED;
266 quit = true;
268 if(!(button & (BUTTON_REL|BUTTON_REPEAT))
269 && !IS_SYSEVENT(button))
270 quit = true;
271 break;
273 rb->reset_poweroff_timer();
274 } while (!quit);
276 /* restore */
277 backlight_use_settings();
278 #ifdef HAVE_BUTTON_LIGHT
279 buttonlight_use_settings();
280 #endif /* HAVE_BUTTON_LIGHT */
282 #ifdef HAVE_LCD_INVERT
283 rb->lcd_set_invert_display(rb->global_settings->invert);
284 #endif /* HAVE_LCD_INVERT */
286 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
287 backlight_brightness_use_setting();
288 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
289 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
290 buttonlight_brightness_use_setting();
291 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
293 #if LCD_DEPTH > 1
294 rb->lcd_set_background(bg_color);
295 #endif
296 return status;