summaryrefslogtreecommitdiffstats
path: root/apps/plugins/lamp.c
blob: 1c60cba78fafbe44202ded7b8c679da62de02102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _// __ \_/ ___\|  |/ /| __ \ / __ \  \/  /
 *   Jukebox    |    |   ( (__) )  \___|    ( | \_\ ( (__) )    (
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2007 Vuong Minh Hiep (vmh)
 * Copyright (C) 2008 Thomas Martitz (kugel.)
 * Copyright (C) 2008 Alexander Papst
 * Copyright (C) 2008 Peter D'Hoye
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "plugin.h"
#include "lib/helper.h"

PLUGIN_HEADER

/* variable button definitions - only targets with a colour display */
#if defined(HAVE_LCD_COLOR)
#if (CONFIG_KEYPAD == IRIVER_H300_PAD)
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT
#   define LAMP_NEXT       BUTTON_SCROLL_FWD
#   define LAMP_PREV       BUTTON_SCROLL_BACK

#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
      (CONFIG_KEYPAD == SANSA_FUZE_PAD)
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT
#   define LAMP_NEXT       BUTTON_SCROLL_FWD
#   define LAMP_PREV       BUTTON_SCROLL_BACK

#elif (CONFIG_KEYPAD == SANSA_C200_PAD)
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT
#   define LAMP_NEXT       BUTTON_SCROLL_UP
#   define LAMP_PREV       BUTTON_SCROLL_DOWN

#elif CONFIG_KEYPAD == MROBE500_PAD
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#elif CONFIG_KEYPAD == COWOND2_PAD

#elif CONFIG_KEYPAD == IAUDIO67_PAD
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
#   define LAMP_LEFT       BUTTON_PREV
#   define LAMP_RIGHT      BUTTON_NEXT

#elif CONFIG_KEYPAD == ONDAVX747_PAD
#   define LAMP_LEFT       BUTTON_VOL_DOWN
#   define LAMP_RIGHT      BUTTON_VOL_UP

#elif CONFIG_KEYPAD == ONDAVX777_PAD

#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
#   define LAMP_LEFT       BUTTON_LEFT
#   define LAMP_RIGHT      BUTTON_RIGHT

#else
#   error Missing key definitions for this keypad
#endif
#endif

#ifdef HAVE_TOUCHSCREEN
# ifndef LAMP_LEFT
#   define LAMP_LEFT       BUTTON_MIDLEFT
# endif
# ifndef LAMP_RIGHT
#   define LAMP_RIGHT      BUTTON_MIDRIGHT
# endif
# ifndef LAMP_NEXT
#   define LAMP_NEXT       BUTTON_TOPMIDDLE
# endif
# ifndef LAMP_PREV
#   define LAMP_PREV       BUTTON_BOTTOMMIDDLE
# endif
#endif

#ifdef HAVE_LCD_COLOR
/* RGB color sets */
#define NUM_COLORSETS   2
static int colorset[NUM_COLORSETS][3] = { { 255, 255, 255 } ,    /* white */
                                          { 255,   0,   0 } };   /* red */
#endif /* HAVE_LCD_COLOR */

/* this is the plugin entry point */
enum plugin_status plugin_start(const void* parameter)
{
    long button;
    (void)parameter;

#ifdef HAVE_LCD_COLOR
    int cs = 0;
    bool quit = false;
#endif /* HAVE_LCD_COLOR */

#ifdef HAVE_BACKLIGHT_BRIGHTNESS
    short old_brightness = rb->global_settings->brightness;
#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
    short old_buttonlight_brightness =
            rb->global_settings->buttonlight_brightness;
#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */

#if LCD_DEPTH > 1
    unsigned bg_color=rb->lcd_get_background();
    rb->lcd_set_backdrop(NULL);
    rb->lcd_set_background(LCD_WHITE);
#endif

#ifdef HAVE_BACKLIGHT_BRIGHTNESS
    rb->backlight_set_brightness(MAX_BRIGHTNESS_SETTING);
#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
    rb->buttonlight_set_brightness(MAX_BRIGHTNESS_SETTING);
#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */

#ifdef HAVE_LCD_INVERT
#if defined(MROBE_100) || defined(SANSA_CLIP)
    /* mrobe-100 has inverted display so invert it for max brightness */
    /* sansa clip has no real backlight so we need to enable all pixels */
    rb->lcd_set_invert_display(true);
#else
    rb->lcd_set_invert_display(false);
#endif /* MROBE_100 */
#endif /* HAVE_LCD_INVERT */

    backlight_force_on();
#ifdef HAVE_BUTTON_LIGHT
    buttonlight_force_on();
#endif /* HAVE_BUTTON_LIGHT */

#ifdef HAVE_LCD_COLOR
    do
    {
        if(cs < 0)
            cs = NUM_COLORSETS-1;
        if(cs >= NUM_COLORSETS)
            cs = 0;
        rb->lcd_set_background( LCD_RGBPACK( colorset[cs][0],
                                colorset[cs][1],
                                colorset[cs][2] ) );
        rb->lcd_clear_display();
        rb->lcd_update();

        switch((button = rb->button_get(true)))
        {
            case LAMP_RIGHT:
#ifdef LAMP_NEXT
            case LAMP_NEXT:
#endif /* LAMP_NEXT */
                cs++;
                break;

            case LAMP_LEFT:
#ifdef LAMP_PREV
            case LAMP_PREV:
#endif /* LAMP_PREV */
                cs--;
                break;

            case (LAMP_RIGHT|BUTTON_REPEAT):
            case (LAMP_RIGHT|BUTTON_REL):
            case (LAMP_LEFT|BUTTON_REPEAT):
            case (LAMP_LEFT|BUTTON_REL):
#ifdef LAMP_NEXT
            case (LAMP_NEXT|BUTTON_REPEAT):
            case (LAMP_NEXT|BUTTON_REL):
#endif /* LAMP_NEXT */
#ifdef LAMP_PREV
            case (LAMP_PREV|BUTTON_REPEAT):
            case (LAMP_PREV|BUTTON_REL):
#endif /* LAMP_PREV */
                /* eat these... */
                break;    
            default:
                    quit = true;
        }
    } while (!quit);

#else /* HAVE_LCD_COLOR */
    rb->lcd_clear_display();
    rb->lcd_update();
    /* wait */
    do
    {
        button = rb->button_get(false);
        if (button && !IS_SYSEVENT(button))
            break;
        rb->yield();
    } while (1);

#endif /*HAVE_LCD_COLOR */

    /* restore */
    backlight_use_settings();
#ifdef HAVE_BUTTON_LIGHT
    buttonlight_use_settings();
#endif /* HAVE_BUTTON_LIGHT */

#ifdef HAVE_LCD_INVERT
    rb->lcd_set_invert_display(rb->global_settings->invert);
#endif /* HAVE_LCD_INVERT */

#ifdef HAVE_BACKLIGHT_BRIGHTNESS
    rb->backlight_set_brightness(old_brightness);
#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
    rb->buttonlight_set_brightness(old_buttonlight_brightness);
#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */

#if LCD_DEPTH > 1
    rb->lcd_set_background(bg_color);
#endif
    return PLUGIN_OK;
}