Bump plugin API version. This should have been done in r24587. Also, because the...
[kugel-rb.git] / apps / plugins / lamp.c
blob690676e054e2b7f58786a024ac06cbf6050ad964
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 == COWON_D2_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 == PHILIPS_SA9200_PAD
86 # define LAMP_LEFT BUTTON_PREV
87 # define LAMP_RIGHT BUTTON_NEXT
89 #elif CONFIG_KEYPAD == ONDAVX747_PAD
90 # define LAMP_LEFT BUTTON_VOL_DOWN
91 # define LAMP_RIGHT BUTTON_VOL_UP
93 #elif CONFIG_KEYPAD == ONDAVX777_PAD
95 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
96 # define LAMP_LEFT BUTTON_LEFT
97 # define LAMP_RIGHT BUTTON_RIGHT
99 #else
100 # error Missing key definitions for this keypad
101 #endif
102 #endif
104 #ifdef HAVE_TOUCHSCREEN
105 # ifndef LAMP_LEFT
106 # define LAMP_LEFT BUTTON_MIDLEFT
107 # endif
108 # ifndef LAMP_RIGHT
109 # define LAMP_RIGHT BUTTON_MIDRIGHT
110 # endif
111 # ifndef LAMP_NEXT
112 # define LAMP_NEXT BUTTON_TOPMIDDLE
113 # endif
114 # ifndef LAMP_PREV
115 # define LAMP_PREV BUTTON_BOTTOMMIDDLE
116 # endif
117 #endif
119 #ifdef HAVE_LCD_COLOR
120 /* RGB color sets */
121 #define NUM_COLORSETS 2
122 static int colorset[NUM_COLORSETS][3] = { { 255, 255, 255 } , /* white */
123 { 255, 0, 0 } }; /* red */
124 #endif /* HAVE_LCD_COLOR */
126 /* this is the plugin entry point */
127 enum plugin_status plugin_start(const void* parameter)
129 long button;
130 (void)parameter;
132 #ifdef HAVE_LCD_COLOR
133 int cs = 0;
134 bool quit = false;
135 #endif /* HAVE_LCD_COLOR */
137 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
138 short old_brightness = rb->global_settings->brightness;
139 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
140 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
141 short old_buttonlight_brightness =
142 rb->global_settings->buttonlight_brightness;
143 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
145 #if LCD_DEPTH > 1
146 unsigned bg_color=rb->lcd_get_background();
147 rb->lcd_set_backdrop(NULL);
148 rb->lcd_set_background(LCD_WHITE);
149 #endif
151 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
152 rb->backlight_set_brightness(MAX_BRIGHTNESS_SETTING);
153 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
154 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
155 rb->buttonlight_set_brightness(MAX_BRIGHTNESS_SETTING);
156 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
158 #ifdef HAVE_LCD_INVERT
159 #if defined(MROBE_100) || defined(SANSA_CLIP)
160 /* mrobe-100 has inverted display so invert it for max brightness */
161 /* sansa clip has no real backlight so we need to enable all pixels */
162 rb->lcd_set_invert_display(true);
163 #else
164 rb->lcd_set_invert_display(false);
165 #endif /* MROBE_100 */
166 #endif /* HAVE_LCD_INVERT */
168 backlight_force_on();
169 #ifdef HAVE_BUTTON_LIGHT
170 buttonlight_force_on();
171 #endif /* HAVE_BUTTON_LIGHT */
173 #ifdef HAVE_LCD_COLOR
176 if(cs < 0)
177 cs = NUM_COLORSETS-1;
178 if(cs >= NUM_COLORSETS)
179 cs = 0;
180 rb->lcd_set_background( LCD_RGBPACK( colorset[cs][0],
181 colorset[cs][1],
182 colorset[cs][2] ) );
183 rb->lcd_clear_display();
184 rb->lcd_update();
186 switch((button = rb->button_get(true)))
188 case LAMP_RIGHT:
189 #ifdef LAMP_NEXT
190 case LAMP_NEXT:
191 #endif /* LAMP_NEXT */
192 cs++;
193 break;
195 case LAMP_LEFT:
196 #ifdef LAMP_PREV
197 case LAMP_PREV:
198 #endif /* LAMP_PREV */
199 cs--;
200 break;
202 case (LAMP_RIGHT|BUTTON_REPEAT):
203 case (LAMP_RIGHT|BUTTON_REL):
204 case (LAMP_LEFT|BUTTON_REPEAT):
205 case (LAMP_LEFT|BUTTON_REL):
206 #ifdef LAMP_NEXT
207 case (LAMP_NEXT|BUTTON_REPEAT):
208 case (LAMP_NEXT|BUTTON_REL):
209 #endif /* LAMP_NEXT */
210 #ifdef LAMP_PREV
211 case (LAMP_PREV|BUTTON_REPEAT):
212 case (LAMP_PREV|BUTTON_REL):
213 #endif /* LAMP_PREV */
214 /* eat these... */
215 break;
216 default:
217 quit = true;
219 } while (!quit);
221 #else /* HAVE_LCD_COLOR */
222 rb->lcd_clear_display();
223 rb->lcd_update();
224 /* wait */
227 button = rb->button_get(false);
228 if (button && !IS_SYSEVENT(button))
229 break;
230 rb->yield();
231 } while (1);
233 #endif /*HAVE_LCD_COLOR */
235 /* restore */
236 backlight_use_settings();
237 #ifdef HAVE_BUTTON_LIGHT
238 buttonlight_use_settings();
239 #endif /* HAVE_BUTTON_LIGHT */
241 #ifdef HAVE_LCD_INVERT
242 rb->lcd_set_invert_display(rb->global_settings->invert);
243 #endif /* HAVE_LCD_INVERT */
245 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
246 rb->backlight_set_brightness(old_brightness);
247 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
248 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
249 rb->buttonlight_set_brightness(old_buttonlight_brightness);
250 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
252 #if LCD_DEPTH > 1
253 rb->lcd_set_background(bg_color);
254 #endif
255 return PLUGIN_OK;