Prepare new maemo release
[maemo-rb.git] / apps / plugins / remote_control.c
bloba5ad4423a1a156ac04cf0494db7bf18586d5a4ae
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"
28 #define PLUGIN_CONTINUE 10
30 static inline void remote_control_setcolors(void);
32 /*****************************************************************************
33 * remote_control_setcolors() set the foreground and background colors.
34 ******************************************************************************/
35 static inline void remote_control_setcolors(void)
37 #ifdef HAVE_LCD_COLOR
38 rb->lcd_set_background(LCD_RGBPACK(181, 181, 222));
39 rb->lcd_set_foreground(LCD_BLACK);
40 #endif
43 static int menu_desktop(void)
45 int selection = 0;
47 MENUITEM_STRINGLIST(menu, "Desktop", NULL, "Escape", "Windows", "F10",
48 "Page Up", "Page Down");
49 while(1)
51 int id = HID_GENERIC_DESKTOP_UNDEFINED;
53 switch (rb->do_menu(&menu, &selection, NULL, false))
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;
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 switch (rb->do_menu(&menu, &selection, NULL, false))
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;
123 if (id != HID_GENERIC_DESKTOP_UNDEFINED)
124 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id);
128 static int menu_media_player(void)
130 int selection = 0;
132 MENUITEM_STRINGLIST(menu, "Media Player", NULL, "Play", "Stop", "Next",
133 "Previous", "Volume Up", "Volume Down", "Mute");
134 while(1)
136 int id = HID_CONSUMER_USAGE_UNASSIGNED;
138 switch (rb->do_menu(&menu, &selection, NULL, false))
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;
169 if (id != HID_CONSUMER_USAGE_UNASSIGNED)
170 rb->usb_hid_send(HID_USAGE_PAGE_CONSUMER, id);
174 /*****************************************************************************
175 * plugin entry point.
176 ******************************************************************************/
177 enum plugin_status plugin_start(const void* parameter)
179 enum plugin_status rc = PLUGIN_CONTINUE;
180 int selection = 0;
182 (void)parameter;
184 rb->lcd_clear_display();
186 #if LCD_DEPTH > 1
187 rb->lcd_set_backdrop(NULL);
188 #endif
189 rb->lcd_setfont(FONT_SYSFIXED);
191 remote_control_setcolors();
193 MENUITEM_STRINGLIST(menu, "Remote Control", NULL, "Desktop", "Presentation",
194 "Media Player", "Quit");
195 while(rc == PLUGIN_CONTINUE)
197 switch (rb->do_menu(&menu, &selection, NULL, false))
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;
219 rb->lcd_setfont(FONT_UI);
221 return rc;