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) 2009 Tomer Shalev
11*
12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include "plugin.h"
23
24#include "lib/pluginlib_actions.h"
25
26
27
28#define PLUGIN_CONTINUE 10
29
30static inline void remote_control_setcolors(void);
31
32/*****************************************************************************
33* remote_control_setcolors() set the foreground and background colors.
34******************************************************************************/
35static inline void remote_control_setcolors(void)
36{
37#ifdef HAVE_LCD_COLOR
38 rb->lcd_set_background(LCD_RGBPACK(181, 181, 222));
39 rb->lcd_set_foreground(LCD_BLACK);
40#endif
41}
42
43static int menu_desktop(void)
44{
45 int selection = 0;
46
47 MENUITEM_STRINGLIST(menu, "Desktop", NULL, "Escape", "Windows", "F10",
48 "Page Up", "Page Down");
49 while(1)
50 {
51 int id = HID_GENERIC_DESKTOP_UNDEFINED;
52
53 switch (rb->do_menu(&menu, &selection, NULL, false))
54 {
55 case 0: /* Escape */
56 id = HID_KEYBOARD_ESCAPE;
57 break;
58 case 1: /* Windows */
59 /* Not sure whether this is the right key */
60 id = HID_KEYBOARD_LEFT_GUI;
61 break;
62 case 2: /* F10 */
63 id = HID_KEYBOARD_F10;
64 break;
65 case 3: /* Page Up */
66 id = HID_KEYBOARD_PAGE_UP;
67 break;
68 case 4: /* Page Down */
69 id = HID_KEYBOARD_PAGE_DOWN;
70 break;
71 case MENU_ATTACHED_USB:
72 return PLUGIN_USB_CONNECTED;
73 case GO_TO_PREVIOUS:
74 return PLUGIN_CONTINUE;
75 default:
76 break;
77 }
78
79 if (id != HID_GENERIC_DESKTOP_UNDEFINED)
80 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id);
81 }
82}
83
84static int menu_presentation(void)
85{
86 int selection = 0;
87
88 MENUITEM_STRINGLIST(menu, "Presentation", NULL, "Next Slide", "Prev Slide",
89 "Start Slideshow", "Leave Slideshow", "Black Screen",
90 "White Screen");
91 while(1)
92 {
93 int id = HID_GENERIC_DESKTOP_UNDEFINED;
94
95 switch (rb->do_menu(&menu, &selection, NULL, false))
96 {
97 case 0: /* Next Slide */
98 id = HID_KEYBOARD_N;
99 break;
100 case 1: /* Prev Slide */
101 id = HID_KEYBOARD_P;
102 break;
103 case 2: /* Start Slideshow */
104 id = HID_KEYBOARD_F5;
105 break;
106 case 3: /* Leave Slideshow */
107 id = HID_KEYBOARD_ESCAPE;
108 break;
109 case 4: /* Black Screen */
110 id = HID_KEYBOARD_DOT;
111 break;
112 case 5: /* White Screen */
113 id = HID_KEYBOARD_COMMA;
114 break;
115 case MENU_ATTACHED_USB:
116 return PLUGIN_USB_CONNECTED;
117 case GO_TO_PREVIOUS:
118 return PLUGIN_CONTINUE;
119 default:
120 break;
121 }
122
123 if (id != HID_GENERIC_DESKTOP_UNDEFINED)
124 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id);
125 }
126}
127
128static int menu_media_player(void)
129{
130 int selection = 0;
131
132 MENUITEM_STRINGLIST(menu, "Media Player", NULL, "Play", "Stop", "Next",
133 "Previous", "Volume Up", "Volume Down", "Mute");
134 while(1)
135 {
136 int id = HID_CONSUMER_USAGE_UNASSIGNED;
137
138 switch (rb->do_menu(&menu, &selection, NULL, false))
139 {
140 case 0: /* Play */
141 id = HID_CONSUMER_USAGE_PLAY_PAUSE;
142 break;
143 case 1: /* Stop */
144 id = HID_CONSUMER_USAGE_STOP;
145 break;
146 case 2: /* Next */
147 id = HID_CONSUMER_USAGE_SCAN_NEXT_TRACK;
148 break;
149 case 3: /* Previous */
150 id = HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK;
151 break;
152 case 4: /* Volume Up */
153 id = HID_CONSUMER_USAGE_VOLUME_INCREMENT;
154 break;
155 case 5: /* Volume Down */
156 id = HID_CONSUMER_USAGE_VOLUME_DECREMENT;
157 break;
158 case 6: /* Mute */
159 id = HID_CONSUMER_USAGE_MUTE;
160 break;
161 case MENU_ATTACHED_USB:
162 return PLUGIN_USB_CONNECTED;
163 case GO_TO_PREVIOUS:
164 return PLUGIN_CONTINUE;
165 default:
166 break;
167 }
168
169 if (id != HID_CONSUMER_USAGE_UNASSIGNED)
170 rb->usb_hid_send(HID_USAGE_PAGE_CONSUMER, id);
171 }
172}
173
174/*****************************************************************************
175* plugin entry point.
176******************************************************************************/
177enum plugin_status plugin_start(const void* parameter)
178{
179 enum plugin_status rc = PLUGIN_CONTINUE;
180 int selection = 0;
181
182 (void)parameter;
183
184 rb->lcd_clear_display();
185
186#if LCD_DEPTH > 1
187 rb->lcd_set_backdrop(NULL);
188#endif
189 rb->lcd_setfont(FONT_SYSFIXED);
190
191 remote_control_setcolors();
192
193 MENUITEM_STRINGLIST(menu, "Remote Control", NULL, "Desktop", "Presentation",
194 "Media Player", "Quit");
195 while(rc == PLUGIN_CONTINUE)
196 {
197 switch (rb->do_menu(&menu, &selection, NULL, false))
198 {
199 case 0: /* Desktop */
200 rc = menu_desktop();
201 break;
202 case 1: /* Presentation */
203 rc = menu_presentation();
204 break;
205 case 2: /* Media Player */
206 rc = menu_media_player();
207 break;
208 case 3: /* Quit */
209 case GO_TO_PREVIOUS:
210 rc = PLUGIN_OK;
211 break;
212 case MENU_ATTACHED_USB:
213 rc = PLUGIN_USB_CONNECTED;
214 break;
215 default:
216 break;
217 }
218 }
219 rb->lcd_setfont(FONT_UI);
220
221 return rc;
222}
223