A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
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
14 *
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.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#include "plugin.h"
26#include "lib/helper.h"
27#include "lib/pluginlib_actions.h"
28
29/* this set the context to use with PLA */
30static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
31
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
38*/
39
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# define LAMP_TOGGLE_BUTTON PLA_SELECT
49#else
50# define LAMP_LEFT PLA_LEFT
51# define LAMP_RIGHT PLA_RIGHT
52# define LAMP_UP PLA_UP
53# define LAMP_DOWN PLA_DOWN
54# define LAMP_UP_REPEAT PLA_UP_REPEAT
55# define LAMP_DOWN_REPEAT PLA_DOWN_REPEAT
56# define LAMP_TOGGLE_BUTTON PLA_SELECT
57#endif/* HAVE_SCROLLWHEEL */
58
59
60#define LAMP_EXIT PLA_EXIT
61
62#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
63 || (CONFIG_KEYPAD == IPOD_3G_PAD) \
64 || (CONFIG_KEYPAD == IPOD_4G_PAD)
65#define LAMP_EXIT2 PLA_UP
66#else
67#define LAMP_EXIT2 PLA_CANCEL
68#endif
69
70
71#ifdef HAVE_LCD_COLOR
72/* RGB color sets */
73#define NUM_COLORSETS 9
74static unsigned colorset[NUM_COLORSETS] = {
75 LCD_RGBPACK(255, 255, 255), /* white */
76 LCD_RGBPACK(255, 0, 0), /* red */
77 LCD_RGBPACK(255, 165, 0), /* orange */
78 LCD_RGBPACK(255, 255, 0), /* yellow */
79 LCD_RGBPACK( 0, 255, 0), /* green */
80 LCD_RGBPACK( 0, 0, 255), /* blue */
81 LCD_RGBPACK( 75, 0, 130), /* indigo */
82 LCD_RGBPACK(238, 130, 238), /* violet */
83 LCD_RGBPACK( 0, 0, 0), /* black */
84};
85#endif /* HAVE_LCD_COLOR */
86
87/* this is the plugin entry point */
88enum plugin_status plugin_start(const void* parameter)
89{
90 enum plugin_status status = PLUGIN_OK;
91 long button;
92 bool quit = false;
93 (void)parameter;
94
95#ifdef HAVE_LCD_COLOR
96 int cs = 0;
97 bool update = false;
98#endif /* HAVE_LCD_COLOR */
99#ifdef HAVE_BUTTON_LIGHT
100 bool buttonlight_on = true;
101#endif /* HAVE_BUTTON_LIGHT */
102
103#if LCD_DEPTH > 1
104 unsigned bg_color = rb->lcd_get_background();
105 rb->lcd_set_backdrop(NULL);
106 rb->lcd_set_background(LCD_WHITE);
107#endif
108
109#ifdef HAVE_BACKLIGHT_BRIGHTNESS
110 int current_brightness = MAX_BRIGHTNESS_SETTING;
111 backlight_brightness_set(MAX_BRIGHTNESS_SETTING);
112#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
113
114 buttonlight_brightness_set(MAX_BRIGHTNESS_SETTING);
115
116#ifdef HAVE_LCD_INVERT
117#ifdef HAVE_NEGATIVE_LCD
118 rb->lcd_set_invert_display(true);
119#else
120 rb->lcd_set_invert_display(false);
121#endif /* HAVE_NEGATIVE_LCD */
122#endif /* HAVE_LCD_INVERT */
123
124 backlight_force_on();
125 buttonlight_force_on();
126
127
128 rb->lcd_clear_display();
129 rb->lcd_update();
130
131 do
132 {
133#ifdef HAVE_LCD_COLOR
134 if(update)
135 {
136 if(cs < 0)
137 cs = NUM_COLORSETS-1;
138 if(cs >= NUM_COLORSETS)
139 cs = 0;
140 rb->lcd_set_background(colorset[cs]);
141 rb->lcd_clear_display();
142 rb->lcd_update();
143 update = false;
144 }
145#endif /* HAVE_LCD_COLOR */
146 button = pluginlib_getaction(HZ*30, plugin_contexts,
147 ARRAYLEN(plugin_contexts));
148
149 switch(button)
150 {
151#ifdef HAVE_LCD_COLOR
152 case LAMP_RIGHT:
153#ifdef LAMP_NEXT
154 case LAMP_NEXT:
155#endif /* LAMP_NEXT */
156 cs++;
157 update = true;
158 break;
159
160 case LAMP_LEFT:
161#ifdef LAMP_PREV
162 case LAMP_PREV:
163#endif /* LAMP_PREV */
164 cs--;
165 update = true;
166 break;
167#endif /* HAVE_LCD_COLOR */
168
169#ifdef HAVE_BACKLIGHT_BRIGHTNESS
170 case LAMP_UP:
171 case (LAMP_UP_REPEAT):
172 if (current_brightness < MAX_BRIGHTNESS_SETTING)
173 backlight_brightness_set(++current_brightness);
174 break;
175
176 case LAMP_DOWN:
177 case (LAMP_DOWN_REPEAT):
178 if (current_brightness > MIN_BRIGHTNESS_SETTING)
179 backlight_brightness_set(--current_brightness);
180 break;
181#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
182#ifdef HAVE_BUTTON_LIGHT
183 case LAMP_TOGGLE_BUTTON:
184 if(buttonlight_on)
185 {
186 buttonlight_force_off();
187 buttonlight_on = false;
188 }
189 else
190 {
191 buttonlight_force_on();
192 buttonlight_on = true;
193 }
194 break;
195#endif /* HAVE_BUTTON_LIGHT */
196 case LAMP_EXIT:
197 case LAMP_EXIT2:
198 quit = true;
199 break;
200 case BUTTON_NONE:
201 /* time out */
202 break;
203 default:
204 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
205 {
206 status = PLUGIN_USB_CONNECTED;
207 quit = true;
208 }
209 }
210 rb->reset_poweroff_timer();
211 } while (!quit);
212
213 /* restore */
214 backlight_use_settings();
215
216 buttonlight_use_settings();
217
218#ifdef HAVE_LCD_INVERT
219 rb->lcd_set_invert_display(rb->global_settings->invert);
220#endif /* HAVE_LCD_INVERT */
221
222
223 backlight_brightness_use_setting();
224
225 buttonlight_brightness_use_setting();
226
227#if LCD_DEPTH > 1
228 rb->lcd_set_background(bg_color);
229#endif
230 return status;
231}