Accept patch in FS#9637 by Keith Perri, fixing a crash when loading a cfg which speci...
[kugel-rb.git] / apps / plugins / lamp.c
blobe355ee4ce378a6fae14267ad4041a4ced63145a5
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 #if defined(HAVE_BACKLIGHT)
31 /* variable button definitions - only targets with a colour display */
32 #if defined(HAVE_LCD_COLOR)
33 #if (CONFIG_KEYPAD == IRIVER_H300_PAD)
34 # define LAMP_LEFT BUTTON_LEFT
35 # define LAMP_RIGHT BUTTON_RIGHT
37 #elif (CONFIG_KEYPAD == IPOD_4G_PAD)
38 # define LAMP_LEFT BUTTON_LEFT
39 # define LAMP_RIGHT BUTTON_RIGHT
40 # define LAMP_NEXT BUTTON_SCROLL_FWD
41 # define LAMP_PREV BUTTON_SCROLL_BACK
43 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
44 # define LAMP_LEFT BUTTON_LEFT
45 # define LAMP_RIGHT BUTTON_RIGHT
47 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
48 # define LAMP_LEFT BUTTON_LEFT
49 # define LAMP_RIGHT BUTTON_RIGHT
51 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
52 # define LAMP_LEFT BUTTON_LEFT
53 # define LAMP_RIGHT BUTTON_RIGHT
55 #elif (CONFIG_KEYPAD == SANSA_E200_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 #else
82 # error Missing key definitions for this keypad
83 #endif
84 #endif
86 #ifdef HAVE_TOUCHSCREEN
87 # ifndef LAMP_LEFT
88 # define LAMP_LEFT BUTTON_MIDLEFT
89 # endif
90 # ifndef LAMP_RIGHT
91 # define LAMP_RIGHT BUTTON_MIDRIGHT
92 # endif
93 # ifndef LAMP_NEXT
94 # define LAMP_NEXT BUTTON_TOPMIDDLE
95 # endif
96 # ifndef LAMP_PREV
97 # define LAMP_PREV BUTTON_BOTTOMMIDDLE
98 # endif
99 #endif
101 static const struct plugin_api* rb; /* global api struct pointer */
103 #ifdef HAVE_LCD_COLOR
104 /* RGB color sets */
105 #define NUM_COLORSETS 2
106 static int colorset[NUM_COLORSETS][3] = { { 255, 255, 255 } , /* white */
107 { 255, 0, 0 } }; /* red */
108 #endif /* HAVE_LCD_COLOR */
110 /* this is the plugin entry point */
111 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
113 (void)parameter;
114 rb = api;
116 #ifdef HAVE_LCD_COLOR
117 int cs = 0;
118 bool quit = false;
119 #endif /* HAVE_LCD_COLOR */
121 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
122 short old_brightness = rb->global_settings->brightness;
123 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
124 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
125 short old_buttonlight_brightness =
126 rb->global_settings->buttonlight_brightness;
127 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
129 #if LCD_DEPTH > 1
130 unsigned bg_color=rb->lcd_get_background();
131 rb->lcd_set_backdrop(NULL);
132 rb->lcd_set_background(LCD_WHITE);
133 #endif
135 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
136 rb->backlight_set_brightness(MAX_BRIGHTNESS_SETTING);
137 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
138 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
139 rb->buttonlight_set_brightness(MAX_BRIGHTNESS_SETTING);
140 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
142 #ifdef HAVE_LCD_INVERT
143 #if defined(MROBE_100) || defined(SANSA_CLIP)
144 /* mrobe-100 has inverted display so invert it for max brightness */
145 /* sansa clip has no real backlight so we need to enable all pixels */
146 rb->lcd_set_invert_display(true);
147 #else
148 rb->lcd_set_invert_display(false);
149 #endif /* MROBE_100 */
150 #endif /* HAVE_LCD_INVERT */
152 backlight_force_on(rb);
153 #ifdef HAVE_BUTTON_LIGHT
154 buttonlight_force_on(rb);
155 #endif /* HAVE_BUTTON_LIGHT */
157 #ifdef HAVE_LCD_COLOR
160 if(cs < 0)
161 cs = NUM_COLORSETS-1;
162 if(cs >= NUM_COLORSETS)
163 cs = 0;
164 rb->lcd_set_background( LCD_RGBPACK( colorset[cs][0],
165 colorset[cs][1],
166 colorset[cs][2] ) );
167 rb->lcd_clear_display();
168 rb->lcd_update();
170 switch(rb->button_get(true))
172 case LAMP_RIGHT:
173 #ifdef LAMP_NEXT
174 case LAMP_NEXT:
175 #endif /* LAMP_NEXT */
176 cs++;
177 break;
179 case LAMP_LEFT:
180 #ifdef LAMP_PREV
181 case LAMP_PREV:
182 #endif /* LAMP_PREV */
183 cs--;
184 break;
186 case (LAMP_RIGHT|BUTTON_REPEAT):
187 case (LAMP_RIGHT|BUTTON_REL):
188 case (LAMP_LEFT|BUTTON_REPEAT):
189 case (LAMP_LEFT|BUTTON_REL):
190 #ifdef LAMP_NEXT
191 case (LAMP_NEXT|BUTTON_REPEAT):
192 case (LAMP_NEXT|BUTTON_REL):
193 #endif /* LAMP_NEXT */
194 #ifdef LAMP_PREV
195 case (LAMP_PREV|BUTTON_REPEAT):
196 case (LAMP_PREV|BUTTON_REL):
197 #endif /* LAMP_PREV */
198 /* eat these... */
199 break;
200 default:
201 quit = true;
203 } while (!quit);
205 #else /* HAVE_LCD_COLOR */
206 rb->lcd_clear_display();
207 rb->lcd_update();
208 /* wait */
209 while(rb->button_get(false) == BUTTON_NONE)
211 rb->yield();
214 #endif /*HAVE_LCD_COLOR */
216 /* restore */
217 backlight_use_settings(rb);
218 #ifdef HAVE_BUTTON_LIGHT
219 buttonlight_use_settings(rb);
220 #endif /* HAVE_BUTTON_LIGHT */
222 #ifdef HAVE_LCD_INVERT
223 rb->lcd_set_invert_display(rb->global_settings->invert);
224 #endif /* HAVE_LCD_INVERT */
226 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
227 rb->backlight_set_brightness(old_brightness);
228 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
229 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
230 rb->buttonlight_set_brightness(old_buttonlight_brightness);
231 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
233 #if LCD_DEPTH > 1
234 rb->lcd_set_background(bg_color);
235 #endif
236 return PLUGIN_OK;
238 #endif