Prepare new maemo release
[maemo-rb.git] / apps / plugins / lamp.c
blobfa7027ece798a6423af7be82d61de243064d4c06
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"
27 #include "lib/pluginlib_actions.h"
29 /* this set the context to use with PLA */
30 static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
32 /* variable button definitions.
33 - only targets with a colour display
34 LAMP_LEFT / LAMP_RIGHT: change the color
35 LAMP_NEXT / LAMP_PREV: (optional) change the color
36 - only targets which can set brightness
37 LAMP_UP / LAMP_DOWN: change the brightness
40 /* we use PLA */
41 #ifdef HAVE_SCROLLWHEEL
42 # define LAMP_LEFT PLA_LEFT
43 # define LAMP_RIGHT PLA_RIGHT
44 # define LAMP_UP PLA_SCROLL_FWD
45 # define LAMP_DOWN PLA_SCROLL_BACK
46 # define LAMP_UP_REPEAT PLA_SCROLL_FWD_REPEAT
47 # define LAMP_DOWN_REPEAT PLA_SCROLL_BACK_REPEAT
48 #else
49 # define LAMP_LEFT PLA_LEFT
50 # define LAMP_RIGHT PLA_RIGHT
51 # define LAMP_UP PLA_UP
52 # define LAMP_DOWN PLA_DOWN
53 # define LAMP_UP_REPEAT PLA_UP_REPEAT
54 # define LAMP_DOWN_REPEAT PLA_DOWN_REPEAT
55 #endif/* HAVE_SCROLLWHEEL */
58 #define LAMP_EXIT PLA_EXIT
59 #define LAMP_EXIT2 PLA_CANCEL
62 #ifdef HAVE_LCD_COLOR
63 /* RGB color sets */
64 #define NUM_COLORSETS 9
65 static unsigned colorset[NUM_COLORSETS] = {
66 LCD_RGBPACK(255, 255, 255), /* white */
67 LCD_RGBPACK(255, 0, 0), /* red */
68 LCD_RGBPACK(255, 165, 0), /* orange */
69 LCD_RGBPACK(255, 255, 0), /* yellow */
70 LCD_RGBPACK( 0, 255, 0), /* green */
71 LCD_RGBPACK( 0, 0, 255), /* blue */
72 LCD_RGBPACK( 75, 0, 130), /* indigo */
73 LCD_RGBPACK(238, 130, 238), /* violet */
74 LCD_RGBPACK( 0, 0, 0), /* black */
76 #endif /* HAVE_LCD_COLOR */
78 /* this is the plugin entry point */
79 enum plugin_status plugin_start(const void* parameter)
81 enum plugin_status status = PLUGIN_OK;
82 long button;
83 bool quit = false;
84 (void)parameter;
86 #ifdef HAVE_LCD_COLOR
87 int cs = 0;
88 bool update = false;
89 #endif /* HAVE_LCD_COLOR */
91 #if LCD_DEPTH > 1
92 unsigned bg_color = rb->lcd_get_background();
93 rb->lcd_set_backdrop(NULL);
94 rb->lcd_set_background(LCD_WHITE);
95 #endif
97 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
98 int current_brightness = MAX_BRIGHTNESS_SETTING;
99 backlight_brightness_set(MAX_BRIGHTNESS_SETTING);
100 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
101 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
102 buttonlight_brightness_set(MAX_BRIGHTNESS_SETTING);
103 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
105 #ifdef HAVE_LCD_INVERT
106 #ifdef HAVE_NEGATIVE_LCD
107 rb->lcd_set_invert_display(true);
108 #else
109 rb->lcd_set_invert_display(false);
110 #endif /* HAVE_NEGATIVE_LCD */
111 #endif /* HAVE_LCD_INVERT */
113 backlight_force_on();
114 #ifdef HAVE_BUTTON_LIGHT
115 buttonlight_force_on();
116 #endif /* HAVE_BUTTON_LIGHT */
118 rb->lcd_clear_display();
119 rb->lcd_update();
123 #ifdef HAVE_LCD_COLOR
124 if(update)
126 if(cs < 0)
127 cs = NUM_COLORSETS-1;
128 if(cs >= NUM_COLORSETS)
129 cs = 0;
130 rb->lcd_set_background(colorset[cs]);
131 rb->lcd_clear_display();
132 rb->lcd_update();
133 update = false;
135 #endif /* HAVE_LCD_COLOR */
136 button = pluginlib_getaction(HZ*30, plugin_contexts,
137 ARRAYLEN(plugin_contexts));
139 switch(button)
141 #ifdef HAVE_LCD_COLOR
142 case LAMP_RIGHT:
143 #ifdef LAMP_NEXT
144 case LAMP_NEXT:
145 #endif /* LAMP_NEXT */
146 cs++;
147 update = true;
148 break;
150 case LAMP_LEFT:
151 #ifdef LAMP_PREV
152 case LAMP_PREV:
153 #endif /* LAMP_PREV */
154 cs--;
155 update = true;
156 break;
157 #endif /* HAVE_LCD_COLOR */
159 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
160 case LAMP_UP:
161 case (LAMP_UP_REPEAT):
162 if (current_brightness < MAX_BRIGHTNESS_SETTING)
163 backlight_brightness_set(++current_brightness);
164 break;
166 case LAMP_DOWN:
167 case (LAMP_DOWN_REPEAT):
168 if (current_brightness > MIN_BRIGHTNESS_SETTING)
169 backlight_brightness_set(--current_brightness);
170 break;
171 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
172 case LAMP_EXIT:
173 case LAMP_EXIT2:
174 quit = true;
175 break;
176 case BUTTON_NONE:
177 /* time out */
178 break;
179 default:
180 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
182 status = PLUGIN_USB_CONNECTED;
183 quit = true;
186 rb->reset_poweroff_timer();
187 } while (!quit);
189 /* restore */
190 backlight_use_settings();
191 #ifdef HAVE_BUTTON_LIGHT
192 buttonlight_use_settings();
193 #endif /* HAVE_BUTTON_LIGHT */
195 #ifdef HAVE_LCD_INVERT
196 rb->lcd_set_invert_display(rb->global_settings->invert);
197 #endif /* HAVE_LCD_INVERT */
199 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
200 backlight_brightness_use_setting();
201 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
202 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
203 buttonlight_brightness_use_setting();
204 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
206 #if LCD_DEPTH > 1
207 rb->lcd_set_background(bg_color);
208 #endif
209 return status;