Another small bookmark.c revision, no functional change, saves bin size
[kugel-rb.git] / apps / plugins / lamp.c
blob8c2dff52540fed63c50af6033cc98580dae35ab5
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 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
100 # define LAMP_LEFT BUTTON_PREV
101 # define LAMP_RIGHT BUTTON_NEXT
103 #else
104 # error Missing key definitions for this keypad
105 #endif
106 #endif
108 #ifdef HAVE_TOUCHSCREEN
109 # ifndef LAMP_LEFT
110 # define LAMP_LEFT BUTTON_MIDLEFT
111 # endif
112 # ifndef LAMP_RIGHT
113 # define LAMP_RIGHT BUTTON_MIDRIGHT
114 # endif
115 # ifndef LAMP_NEXT
116 # define LAMP_NEXT BUTTON_TOPMIDDLE
117 # endif
118 # ifndef LAMP_PREV
119 # define LAMP_PREV BUTTON_BOTTOMMIDDLE
120 # endif
121 #endif
123 #ifdef HAVE_LCD_COLOR
124 /* RGB color sets */
125 #define NUM_COLORSETS 2
126 static int colorset[NUM_COLORSETS][3] = { { 255, 255, 255 } , /* white */
127 { 255, 0, 0 } }; /* red */
128 #endif /* HAVE_LCD_COLOR */
130 /* this is the plugin entry point */
131 enum plugin_status plugin_start(const void* parameter)
133 long button;
134 (void)parameter;
136 #ifdef HAVE_LCD_COLOR
137 int cs = 0;
138 bool quit = false;
139 #endif /* HAVE_LCD_COLOR */
141 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
142 short old_brightness = rb->global_settings->brightness;
143 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
144 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
145 short old_buttonlight_brightness =
146 rb->global_settings->buttonlight_brightness;
147 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
149 #if LCD_DEPTH > 1
150 unsigned bg_color=rb->lcd_get_background();
151 rb->lcd_set_backdrop(NULL);
152 rb->lcd_set_background(LCD_WHITE);
153 #endif
155 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
156 rb->backlight_set_brightness(MAX_BRIGHTNESS_SETTING);
157 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
158 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
159 rb->buttonlight_set_brightness(MAX_BRIGHTNESS_SETTING);
160 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
162 #ifdef HAVE_LCD_INVERT
163 #ifdef HAVE_NEGATIVE_LCD
164 rb->lcd_set_invert_display(true);
165 #else
166 rb->lcd_set_invert_display(false);
167 #endif /* HAVE_NEGATIVE_LCD */
168 #endif /* HAVE_LCD_INVERT */
170 backlight_force_on();
171 #ifdef HAVE_BUTTON_LIGHT
172 buttonlight_force_on();
173 #endif /* HAVE_BUTTON_LIGHT */
175 #ifdef HAVE_LCD_COLOR
178 if(cs < 0)
179 cs = NUM_COLORSETS-1;
180 if(cs >= NUM_COLORSETS)
181 cs = 0;
182 rb->lcd_set_background( LCD_RGBPACK( colorset[cs][0],
183 colorset[cs][1],
184 colorset[cs][2] ) );
185 rb->lcd_clear_display();
186 rb->lcd_update();
188 switch((button = rb->button_get(true)))
190 case LAMP_RIGHT:
191 #ifdef LAMP_NEXT
192 case LAMP_NEXT:
193 #endif /* LAMP_NEXT */
194 cs++;
195 break;
197 case LAMP_LEFT:
198 #ifdef LAMP_PREV
199 case LAMP_PREV:
200 #endif /* LAMP_PREV */
201 cs--;
202 break;
204 case (LAMP_RIGHT|BUTTON_REPEAT):
205 case (LAMP_RIGHT|BUTTON_REL):
206 case (LAMP_LEFT|BUTTON_REPEAT):
207 case (LAMP_LEFT|BUTTON_REL):
208 #ifdef LAMP_NEXT
209 case (LAMP_NEXT|BUTTON_REPEAT):
210 case (LAMP_NEXT|BUTTON_REL):
211 #endif /* LAMP_NEXT */
212 #ifdef LAMP_PREV
213 case (LAMP_PREV|BUTTON_REPEAT):
214 case (LAMP_PREV|BUTTON_REL):
215 #endif /* LAMP_PREV */
216 /* eat these... */
217 break;
218 default:
219 quit = true;
221 } while (!quit);
223 #else /* HAVE_LCD_COLOR */
224 rb->lcd_clear_display();
225 rb->lcd_update();
226 /* wait */
229 button = rb->button_get(false);
230 if (button && !IS_SYSEVENT(button))
231 break;
232 rb->yield();
233 } while (1);
235 #endif /*HAVE_LCD_COLOR */
237 /* restore */
238 backlight_use_settings();
239 #ifdef HAVE_BUTTON_LIGHT
240 buttonlight_use_settings();
241 #endif /* HAVE_BUTTON_LIGHT */
243 #ifdef HAVE_LCD_INVERT
244 rb->lcd_set_invert_display(rb->global_settings->invert);
245 #endif /* HAVE_LCD_INVERT */
247 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
248 rb->backlight_set_brightness(old_brightness);
249 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
250 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
251 rb->buttonlight_set_brightness(old_buttonlight_brightness);
252 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
254 #if LCD_DEPTH > 1
255 rb->lcd_set_background(bg_color);
256 #endif
257 return PLUGIN_OK;