diff options
Diffstat (limited to 'apps/plugins/lamp.c')
-rw-r--r-- | apps/plugins/lamp.c | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/apps/plugins/lamp.c b/apps/plugins/lamp.c index 0074933fd8..4dffcd06bf 100644 --- a/apps/plugins/lamp.c +++ b/apps/plugins/lamp.c | |||
@@ -123,40 +123,36 @@ | |||
123 | #ifdef HAVE_LCD_COLOR | 123 | #ifdef HAVE_LCD_COLOR |
124 | /* RGB color sets */ | 124 | /* RGB color sets */ |
125 | #define NUM_COLORSETS 2 | 125 | #define NUM_COLORSETS 2 |
126 | static int colorset[NUM_COLORSETS][3] = { { 255, 255, 255 } , /* white */ | 126 | static unsigned colorset[NUM_COLORSETS] = { |
127 | { 255, 0, 0 } }; /* red */ | 127 | LCD_RGBPACK(255, 255, 255), /* white */ |
128 | LCD_RGBPACK(255, 0, 0), /* red */ | ||
129 | }; | ||
128 | #endif /* HAVE_LCD_COLOR */ | 130 | #endif /* HAVE_LCD_COLOR */ |
129 | 131 | ||
130 | /* this is the plugin entry point */ | 132 | /* this is the plugin entry point */ |
131 | enum plugin_status plugin_start(const void* parameter) | 133 | enum plugin_status plugin_start(const void* parameter) |
132 | { | 134 | { |
135 | enum plugin_status status = PLUGIN_OK; | ||
133 | long button; | 136 | long button; |
134 | (void)parameter; | 137 | (void)parameter; |
135 | 138 | ||
136 | #ifdef HAVE_LCD_COLOR | 139 | #ifdef HAVE_LCD_COLOR |
137 | int cs = 0; | 140 | int cs = 0; |
138 | bool quit = false; | 141 | bool quit = false; |
142 | bool update = true; | ||
139 | #endif /* HAVE_LCD_COLOR */ | 143 | #endif /* HAVE_LCD_COLOR */ |
140 | 144 | ||
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 */ | ||
148 | |||
149 | #if LCD_DEPTH > 1 | 145 | #if LCD_DEPTH > 1 |
150 | unsigned bg_color=rb->lcd_get_background(); | 146 | unsigned bg_color = rb->lcd_get_background(); |
151 | rb->lcd_set_backdrop(NULL); | 147 | rb->lcd_set_backdrop(NULL); |
152 | rb->lcd_set_background(LCD_WHITE); | 148 | rb->lcd_set_background(LCD_WHITE); |
153 | #endif | 149 | #endif |
154 | 150 | ||
155 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS | 151 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS |
156 | rb->backlight_set_brightness(MAX_BRIGHTNESS_SETTING); | 152 | backlight_brightness_set(MAX_BRIGHTNESS_SETTING); |
157 | #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ | 153 | #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ |
158 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS | 154 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS |
159 | rb->buttonlight_set_brightness(MAX_BRIGHTNESS_SETTING); | 155 | buttonlight_brightness_set(MAX_BRIGHTNESS_SETTING); |
160 | #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ | 156 | #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ |
161 | 157 | ||
162 | #ifdef HAVE_LCD_INVERT | 158 | #ifdef HAVE_LCD_INVERT |
@@ -175,23 +171,26 @@ enum plugin_status plugin_start(const void* parameter) | |||
175 | #ifdef HAVE_LCD_COLOR | 171 | #ifdef HAVE_LCD_COLOR |
176 | do | 172 | do |
177 | { | 173 | { |
178 | if(cs < 0) | 174 | if(update) |
179 | cs = NUM_COLORSETS-1; | 175 | { |
180 | if(cs >= NUM_COLORSETS) | 176 | if(cs < 0) |
181 | cs = 0; | 177 | cs = NUM_COLORSETS-1; |
182 | rb->lcd_set_background( LCD_RGBPACK( colorset[cs][0], | 178 | if(cs >= NUM_COLORSETS) |
183 | colorset[cs][1], | 179 | cs = 0; |
184 | colorset[cs][2] ) ); | 180 | rb->lcd_set_background(colorset[cs]); |
185 | rb->lcd_clear_display(); | 181 | rb->lcd_clear_display(); |
186 | rb->lcd_update(); | 182 | rb->lcd_update(); |
187 | 183 | update = false; | |
188 | switch((button = rb->button_get(true))) | 184 | } |
185 | |||
186 | switch((button = rb->button_get_w_tmo(HZ*30))) | ||
189 | { | 187 | { |
190 | case LAMP_RIGHT: | 188 | case LAMP_RIGHT: |
191 | #ifdef LAMP_NEXT | 189 | #ifdef LAMP_NEXT |
192 | case LAMP_NEXT: | 190 | case LAMP_NEXT: |
193 | #endif /* LAMP_NEXT */ | 191 | #endif /* LAMP_NEXT */ |
194 | cs++; | 192 | cs++; |
193 | update = true; | ||
195 | break; | 194 | break; |
196 | 195 | ||
197 | case LAMP_LEFT: | 196 | case LAMP_LEFT: |
@@ -199,25 +198,24 @@ enum plugin_status plugin_start(const void* parameter) | |||
199 | case LAMP_PREV: | 198 | case LAMP_PREV: |
200 | #endif /* LAMP_PREV */ | 199 | #endif /* LAMP_PREV */ |
201 | cs--; | 200 | cs--; |
201 | update = true; | ||
202 | break; | 202 | break; |
203 | 203 | ||
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: | 204 | default: |
219 | quit = true; | 205 | if(button) |
206 | { | ||
207 | if(rb->default_event_handler(button) == SYS_USB_CONNECTED) | ||
208 | { | ||
209 | status = PLUGIN_USB_CONNECTED; | ||
210 | quit = true; | ||
211 | } | ||
212 | if(!(button & (BUTTON_REL|BUTTON_REPEAT)) | ||
213 | && !IS_SYSEVENT(button)) | ||
214 | quit = true; | ||
215 | } | ||
216 | break; | ||
220 | } | 217 | } |
218 | rb->reset_poweroff_timer(); | ||
221 | } while (!quit); | 219 | } while (!quit); |
222 | 220 | ||
223 | #else /* HAVE_LCD_COLOR */ | 221 | #else /* HAVE_LCD_COLOR */ |
@@ -226,10 +224,18 @@ enum plugin_status plugin_start(const void* parameter) | |||
226 | /* wait */ | 224 | /* wait */ |
227 | do | 225 | do |
228 | { | 226 | { |
229 | button = rb->button_get(false); | 227 | button = rb->button_get_w_tmo(HZ*30); |
230 | if (button && !IS_SYSEVENT(button)) | 228 | if(button) |
231 | break; | 229 | { |
232 | rb->yield(); | 230 | if(rb->default_event_handler(button) == SYS_USB_CONNECTED) |
231 | { | ||
232 | status = PLUGIN_USB_CONNECTED; | ||
233 | break; | ||
234 | } | ||
235 | if(!IS_SYSEVENT(button)) | ||
236 | break; | ||
237 | } | ||
238 | rb->reset_poweroff_timer(); | ||
233 | } while (1); | 239 | } while (1); |
234 | 240 | ||
235 | #endif /*HAVE_LCD_COLOR */ | 241 | #endif /*HAVE_LCD_COLOR */ |
@@ -245,15 +251,14 @@ enum plugin_status plugin_start(const void* parameter) | |||
245 | #endif /* HAVE_LCD_INVERT */ | 251 | #endif /* HAVE_LCD_INVERT */ |
246 | 252 | ||
247 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS | 253 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS |
248 | rb->backlight_set_brightness(old_brightness); | 254 | backlight_brightness_use_setting(); |
249 | #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ | 255 | #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ |
250 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS | 256 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS |
251 | rb->buttonlight_set_brightness(old_buttonlight_brightness); | 257 | buttonlight_brightness_use_setting(); |
252 | #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ | 258 | #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ |
253 | 259 | ||
254 | #if LCD_DEPTH > 1 | 260 | #if LCD_DEPTH > 1 |
255 | rb->lcd_set_background(bg_color); | 261 | rb->lcd_set_background(bg_color); |
256 | #endif | 262 | #endif |
257 | return PLUGIN_OK; | 263 | return status; |
258 | } | 264 | } |
259 | |||