Fix red in bootloaders
[maemo-rb.git] / apps / plugins / lamp.c
blobc35973bd850d6a8997899f5e40e81764dd70c9cf
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 PLUGIN_HEADER
30 /* variable button definitions - only targets with a colour display */
31 #if defined(HAVE_LCD_COLOR)
32 #if (CONFIG_KEYPAD == IRIVER_H300_PAD)
33 # define LAMP_LEFT BUTTON_LEFT
34 # define LAMP_RIGHT BUTTON_RIGHT
36 #elif (CONFIG_KEYPAD == IPOD_4G_PAD)
37 # define LAMP_LEFT BUTTON_LEFT
38 # define LAMP_RIGHT BUTTON_RIGHT
39 # define LAMP_NEXT BUTTON_SCROLL_FWD
40 # define LAMP_PREV BUTTON_SCROLL_BACK
42 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
43 # define LAMP_LEFT BUTTON_LEFT
44 # define LAMP_RIGHT BUTTON_RIGHT
46 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
47 # define LAMP_LEFT BUTTON_LEFT
48 # define LAMP_RIGHT BUTTON_RIGHT
50 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
51 # define LAMP_LEFT BUTTON_LEFT
52 # define LAMP_RIGHT BUTTON_RIGHT
54 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
55 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
56 # define LAMP_LEFT BUTTON_LEFT
57 # define LAMP_RIGHT BUTTON_RIGHT
58 # define LAMP_NEXT BUTTON_SCROLL_FWD
59 # define LAMP_PREV BUTTON_SCROLL_BACK
61 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
62 # define LAMP_LEFT BUTTON_LEFT
63 # define LAMP_RIGHT BUTTON_RIGHT
65 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
66 # define LAMP_LEFT BUTTON_LEFT
67 # define LAMP_RIGHT BUTTON_RIGHT
68 # define LAMP_NEXT BUTTON_SCROLL_UP
69 # define LAMP_PREV BUTTON_SCROLL_DOWN
71 #elif CONFIG_KEYPAD == MROBE500_PAD
72 # define LAMP_LEFT BUTTON_LEFT
73 # define LAMP_RIGHT BUTTON_RIGHT
75 #elif CONFIG_KEYPAD == COWOND2_PAD
77 #elif CONFIG_KEYPAD == IAUDIO67_PAD
78 # define LAMP_LEFT BUTTON_LEFT
79 # define LAMP_RIGHT BUTTON_RIGHT
81 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
82 # define LAMP_LEFT BUTTON_LEFT
83 # define LAMP_RIGHT BUTTON_RIGHT
85 #elif CONFIG_KEYPAD == ONDAVX747_PAD
86 # define LAMP_LEFT BUTTON_VOL_DOWN
87 # define LAMP_RIGHT BUTTON_VOL_UP
89 #else
90 # error Missing key definitions for this keypad
91 #endif
92 #endif
94 #ifdef HAVE_TOUCHSCREEN
95 # ifndef LAMP_LEFT
96 # define LAMP_LEFT BUTTON_MIDLEFT
97 # endif
98 # ifndef LAMP_RIGHT
99 # define LAMP_RIGHT BUTTON_MIDRIGHT
100 # endif
101 # ifndef LAMP_NEXT
102 # define LAMP_NEXT BUTTON_TOPMIDDLE
103 # endif
104 # ifndef LAMP_PREV
105 # define LAMP_PREV BUTTON_BOTTOMMIDDLE
106 # endif
107 #endif
109 #ifdef HAVE_LCD_COLOR
110 /* RGB color sets */
111 #define NUM_COLORSETS 2
112 static int colorset[NUM_COLORSETS][3] = { { 255, 255, 255 } , /* white */
113 { 255, 0, 0 } }; /* red */
114 #endif /* HAVE_LCD_COLOR */
116 /* this is the plugin entry point */
117 enum plugin_status plugin_start(const void* parameter)
119 long button;
120 (void)parameter;
122 #ifdef HAVE_LCD_COLOR
123 int cs = 0;
124 bool quit = false;
125 #endif /* HAVE_LCD_COLOR */
127 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
128 short old_brightness = rb->global_settings->brightness;
129 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
130 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
131 short old_buttonlight_brightness =
132 rb->global_settings->buttonlight_brightness;
133 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
135 #if LCD_DEPTH > 1
136 unsigned bg_color=rb->lcd_get_background();
137 rb->lcd_set_backdrop(NULL);
138 rb->lcd_set_background(LCD_WHITE);
139 #endif
141 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
142 rb->backlight_set_brightness(MAX_BRIGHTNESS_SETTING);
143 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
144 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
145 rb->buttonlight_set_brightness(MAX_BRIGHTNESS_SETTING);
146 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
148 #ifdef HAVE_LCD_INVERT
149 #if defined(MROBE_100) || defined(SANSA_CLIP)
150 /* mrobe-100 has inverted display so invert it for max brightness */
151 /* sansa clip has no real backlight so we need to enable all pixels */
152 rb->lcd_set_invert_display(true);
153 #else
154 rb->lcd_set_invert_display(false);
155 #endif /* MROBE_100 */
156 #endif /* HAVE_LCD_INVERT */
158 backlight_force_on();
159 #ifdef HAVE_BUTTON_LIGHT
160 buttonlight_force_on();
161 #endif /* HAVE_BUTTON_LIGHT */
163 #ifdef HAVE_LCD_COLOR
166 if(cs < 0)
167 cs = NUM_COLORSETS-1;
168 if(cs >= NUM_COLORSETS)
169 cs = 0;
170 rb->lcd_set_background( LCD_RGBPACK( colorset[cs][0],
171 colorset[cs][1],
172 colorset[cs][2] ) );
173 rb->lcd_clear_display();
174 rb->lcd_update();
176 switch((button = rb->button_get(true)))
178 case LAMP_RIGHT:
179 #ifdef LAMP_NEXT
180 case LAMP_NEXT:
181 #endif /* LAMP_NEXT */
182 cs++;
183 break;
185 case LAMP_LEFT:
186 #ifdef LAMP_PREV
187 case LAMP_PREV:
188 #endif /* LAMP_PREV */
189 cs--;
190 break;
192 case (LAMP_RIGHT|BUTTON_REPEAT):
193 case (LAMP_RIGHT|BUTTON_REL):
194 case (LAMP_LEFT|BUTTON_REPEAT):
195 case (LAMP_LEFT|BUTTON_REL):
196 #ifdef LAMP_NEXT
197 case (LAMP_NEXT|BUTTON_REPEAT):
198 case (LAMP_NEXT|BUTTON_REL):
199 #endif /* LAMP_NEXT */
200 #ifdef LAMP_PREV
201 case (LAMP_PREV|BUTTON_REPEAT):
202 case (LAMP_PREV|BUTTON_REL):
203 #endif /* LAMP_PREV */
204 /* eat these... */
205 break;
206 default:
207 quit = true;
209 } while (!quit);
211 #else /* HAVE_LCD_COLOR */
212 rb->lcd_clear_display();
213 rb->lcd_update();
214 /* wait */
217 button = rb->button_get(false);
218 if (button && !IS_SYSEVENT(button))
219 break;
220 rb->yield();
221 } while (1);
223 #endif /*HAVE_LCD_COLOR */
225 /* restore */
226 backlight_use_settings();
227 #ifdef HAVE_BUTTON_LIGHT
228 buttonlight_use_settings();
229 #endif /* HAVE_BUTTON_LIGHT */
231 #ifdef HAVE_LCD_INVERT
232 rb->lcd_set_invert_display(rb->global_settings->invert);
233 #endif /* HAVE_LCD_INVERT */
235 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
236 rb->backlight_set_brightness(old_brightness);
237 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
238 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
239 rb->buttonlight_set_brightness(old_buttonlight_brightness);
240 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
242 #if LCD_DEPTH > 1
243 rb->lcd_set_background(bg_color);
244 #endif
245 return PLUGIN_OK;