The threading model should be set from configure, not config.h.
[maemo-rb.git] / apps / plugins / lamp.c
blob4d4205a093c9f3a388aafe3e25273992ad0b1995
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 2
65 static unsigned colorset[NUM_COLORSETS] = {
66 LCD_RGBPACK(255, 255, 255), /* white */
67 LCD_RGBPACK(255, 0, 0), /* red */
69 #endif /* HAVE_LCD_COLOR */
71 /* this is the plugin entry point */
72 enum plugin_status plugin_start(const void* parameter)
74 enum plugin_status status = PLUGIN_OK;
75 long button;
76 bool quit = false;
77 (void)parameter;
79 #ifdef HAVE_LCD_COLOR
80 int cs = 0;
81 bool update = false;
82 #endif /* HAVE_LCD_COLOR */
84 #if LCD_DEPTH > 1
85 unsigned bg_color = rb->lcd_get_background();
86 rb->lcd_set_backdrop(NULL);
87 rb->lcd_set_background(LCD_WHITE);
88 #endif
90 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
91 int current_brightness = MAX_BRIGHTNESS_SETTING;
92 backlight_brightness_set(MAX_BRIGHTNESS_SETTING);
93 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
94 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
95 buttonlight_brightness_set(MAX_BRIGHTNESS_SETTING);
96 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
98 #ifdef HAVE_LCD_INVERT
99 #ifdef HAVE_NEGATIVE_LCD
100 rb->lcd_set_invert_display(true);
101 #else
102 rb->lcd_set_invert_display(false);
103 #endif /* HAVE_NEGATIVE_LCD */
104 #endif /* HAVE_LCD_INVERT */
106 backlight_force_on();
107 #ifdef HAVE_BUTTON_LIGHT
108 buttonlight_force_on();
109 #endif /* HAVE_BUTTON_LIGHT */
111 rb->lcd_clear_display();
112 rb->lcd_update();
116 #ifdef HAVE_LCD_COLOR
117 if(update)
119 if(cs < 0)
120 cs = NUM_COLORSETS-1;
121 if(cs >= NUM_COLORSETS)
122 cs = 0;
123 rb->lcd_set_background(colorset[cs]);
124 rb->lcd_clear_display();
125 rb->lcd_update();
126 update = false;
128 #endif /* HAVE_LCD_COLOR */
129 button = pluginlib_getaction(HZ*30, plugin_contexts,
130 ARRAYLEN(plugin_contexts));
132 switch(button)
134 #ifdef HAVE_LCD_COLOR
135 case LAMP_RIGHT:
136 #ifdef LAMP_NEXT
137 case LAMP_NEXT:
138 #endif /* LAMP_NEXT */
139 cs++;
140 update = true;
141 break;
143 case LAMP_LEFT:
144 #ifdef LAMP_PREV
145 case LAMP_PREV:
146 #endif /* LAMP_PREV */
147 cs--;
148 update = true;
149 break;
150 #endif /* HAVE_LCD_COLOR */
152 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
153 case LAMP_UP:
154 case (LAMP_UP_REPEAT):
155 if (current_brightness < MAX_BRIGHTNESS_SETTING)
156 backlight_brightness_set(++current_brightness);
157 break;
159 case LAMP_DOWN:
160 case (LAMP_DOWN_REPEAT):
161 if (current_brightness > MIN_BRIGHTNESS_SETTING)
162 backlight_brightness_set(--current_brightness);
163 break;
164 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
165 case LAMP_EXIT:
166 case LAMP_EXIT2:
167 quit = true;
168 break;
169 case BUTTON_NONE:
170 /* time out */
171 break;
172 default:
173 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
175 status = PLUGIN_USB_CONNECTED;
176 quit = true;
179 rb->reset_poweroff_timer();
180 } while (!quit);
182 /* restore */
183 backlight_use_settings();
184 #ifdef HAVE_BUTTON_LIGHT
185 buttonlight_use_settings();
186 #endif /* HAVE_BUTTON_LIGHT */
188 #ifdef HAVE_LCD_INVERT
189 rb->lcd_set_invert_display(rb->global_settings->invert);
190 #endif /* HAVE_LCD_INVERT */
192 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
193 backlight_brightness_use_setting();
194 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
195 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
196 buttonlight_brightness_use_setting();
197 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
199 #if LCD_DEPTH > 1
200 rb->lcd_set_background(bg_color);
201 #endif
202 return status;