Rearange menu of mpegplayer. Add new menu with "settings" and "quit", and remove...
[kugel-rb.git] / apps / plugins / remote_control.c
blob8e05c672831323dabafcdbb384f0d2640140cf56
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Tomer Shalev
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "plugin.h"
24 #include "lib/pluginlib_actions.h"
26 PLUGIN_HEADER
28 static void remote_control_setcolors(void);
30 /*****************************************************************************
31 * remote_control_setcolors() set the foreground and background colors.
32 ******************************************************************************/
33 static inline void remote_control_setcolors(void)
35 #ifdef HAVE_LCD_COLOR
36 rb->lcd_set_background(LCD_RGBPACK(181, 181, 222));
37 rb->lcd_set_foreground(LCD_BLACK);
38 #endif
41 static int menu_desktop(void)
43 int selection = 0;
45 MENUITEM_STRINGLIST(menu, "Desktop", NULL, "Escape", "Windows", "F10",
46 "Page Up", "Page Down");
47 while(1)
49 int id = HID_GENERIC_DESKTOP_UNDEFINED;
51 selection = rb->do_menu(&menu, &selection, NULL, false);
53 switch (selection)
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 0;
75 default:
76 break;
79 if (id != HID_GENERIC_DESKTOP_UNDEFINED)
80 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id);
84 static int menu_presentation(void)
86 int selection = 0;
88 MENUITEM_STRINGLIST(menu, "Presentation", NULL, "Next Slide", "Prev Slide",
89 "Start Slideshow", "Leave Slideshow", "Black Screen",
90 "White Screen");
91 while(1)
93 int id = HID_GENERIC_DESKTOP_UNDEFINED;
95 selection = rb->do_menu(&menu, &selection, NULL, false);
97 switch (selection)
99 case 0: /* Next Slide */
100 id = HID_KEYBOARD_N;
101 break;
102 case 1: /* Prev Slide */
103 id = HID_KEYBOARD_P;
104 break;
105 case 2: /* Start Slideshow */
106 id = HID_KEYBOARD_F5;
107 break;
108 case 3: /* Leave Slideshow */
109 id = HID_KEYBOARD_ESCAPE;
110 break;
111 case 4: /* Black Screen */
112 id = HID_KEYBOARD_DOT;
113 break;
114 case 5: /* White Screen */
115 id = HID_KEYBOARD_COMMA;
116 break;
117 case MENU_ATTACHED_USB:
118 return PLUGIN_USB_CONNECTED;
119 case GO_TO_PREVIOUS:
120 return 0;
121 default:
122 break;
125 if (id != HID_GENERIC_DESKTOP_UNDEFINED)
126 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id);
130 static int menu_media_player(void)
132 int selection = 0;
134 MENUITEM_STRINGLIST(menu, "Media Player", NULL, "Play", "Stop", "Next",
135 "Previous", "Volume Up", "Volume Down", "Mute");
136 while(1)
138 int id = HID_CONSUMER_USAGE_UNASSIGNED;
140 selection = rb->do_menu(&menu, &selection, NULL, false);
142 switch (selection)
144 case 0: /* Play */
145 id = HID_CONSUMER_USAGE_PLAY_PAUSE;
146 break;
147 case 1: /* Stop */
148 id = HID_CONSUMER_USAGE_STOP;
149 break;
150 case 2: /* Next */
151 id = HID_CONSUMER_USAGE_SCAN_NEXT_TRACK;
152 break;
153 case 3: /* Previous */
154 id = HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK;
155 break;
156 case 4: /* Volume Up */
157 id = HID_CONSUMER_USAGE_VOLUME_INCREMENT;
158 break;
159 case 5: /* Volume Down */
160 id = HID_CONSUMER_USAGE_VOLUME_DECREMENT;
161 break;
162 case 6: /* Mute */
163 id = HID_CONSUMER_USAGE_MUTE;
164 break;
165 case MENU_ATTACHED_USB:
166 return PLUGIN_USB_CONNECTED;
167 case GO_TO_PREVIOUS:
168 return 0;
169 default:
170 break;
173 if (id != HID_CONSUMER_USAGE_UNASSIGNED)
174 rb->usb_hid_send(HID_USAGE_PAGE_CONSUMER, id);
178 /*****************************************************************************
179 * plugin entry point.
180 ******************************************************************************/
181 enum plugin_status plugin_start(const void* parameter)
183 enum plugin_status rc = PLUGIN_USB_CONNECTED;
184 int selection = 0;
186 (void)parameter;
188 rb->lcd_clear_display();
190 #if LCD_DEPTH > 1
191 rb->lcd_set_backdrop(NULL);
192 #endif
193 rb->lcd_setfont(FONT_SYSFIXED);
195 remote_control_setcolors();
197 MENUITEM_STRINGLIST(menu, "Remote Control", NULL, "Desktop", "Presentation",
198 "Media Player", "Quit");
199 while(1)
201 selection = rb->do_menu(&menu, &selection, NULL, false);
202 switch (selection)
204 case 0: /* Desktop */
205 if (menu_desktop() == PLUGIN_USB_CONNECTED)
206 goto Exit;
207 break;
208 case 1: /* Presentation */
209 if (menu_presentation() == PLUGIN_USB_CONNECTED)
210 goto Exit;
211 break;
212 case 2: /* Media Player */
213 if (menu_media_player() == PLUGIN_USB_CONNECTED)
214 goto Exit;
215 break;
216 case 3: /* Quit */
217 case GO_TO_PREVIOUS:
218 rc = PLUGIN_OK;
219 goto Exit;
220 case MENU_ATTACHED_USB:
221 goto Exit;
222 default:
223 break;
226 Exit:
227 rb->lcd_setfont(FONT_UI);
229 return rc;