diff options
author | Frank Gevaerts <frank@gevaerts.be> | 2009-07-18 12:58:29 +0000 |
---|---|---|
committer | Frank Gevaerts <frank@gevaerts.be> | 2009-07-18 12:58:29 +0000 |
commit | e409fba7f85e9ddf51e2d6a3342dbca6f667e280 (patch) | |
tree | 63d0e5689658f3a439459611a31462b1cba9fa55 /apps/plugins/remote_control.c | |
parent | 06bb5ea004dacfa81e3c8e192ad2c1f95d2ad18e (diff) |
Flyspray: FS#10326
Author: Tomer Shalev
Adds a USB HID sample application, a plugin tha allows to send HID commands while connected in non-storage mode.
This also removes the HID stuff in the debug menu. Testing is now easily doable from the plugin
Also general HID updates
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21953 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/remote_control.c')
-rw-r--r-- | apps/plugins/remote_control.c | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/apps/plugins/remote_control.c b/apps/plugins/remote_control.c new file mode 100644 index 0000000000..8e05c67283 --- /dev/null +++ b/apps/plugins/remote_control.c @@ -0,0 +1,231 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2009 Tomer Shalev +* +* 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/pluginlib_actions.h" + +PLUGIN_HEADER + +static void remote_control_setcolors(void); + +/***************************************************************************** +* remote_control_setcolors() set the foreground and background colors. +******************************************************************************/ +static inline void remote_control_setcolors(void) +{ +#ifdef HAVE_LCD_COLOR + rb->lcd_set_background(LCD_RGBPACK(181, 181, 222)); + rb->lcd_set_foreground(LCD_BLACK); +#endif +} + +static int menu_desktop(void) +{ + int selection = 0; + + MENUITEM_STRINGLIST(menu, "Desktop", NULL, "Escape", "Windows", "F10", + "Page Up", "Page Down"); + while(1) + { + int id = HID_GENERIC_DESKTOP_UNDEFINED; + + selection = rb->do_menu(&menu, &selection, NULL, false); + + switch (selection) + { + case 0: /* Escape */ + id = HID_KEYBOARD_ESCAPE; + break; + case 1: /* Windows */ + /* Not sure whether this is the right key */ + id = HID_KEYBOARD_LEFT_GUI; + break; + case 2: /* F10 */ + id = HID_KEYBOARD_F10; + break; + case 3: /* Page Up */ + id = HID_KEYBOARD_PAGE_UP; + break; + case 4: /* Page Down */ + id = HID_KEYBOARD_PAGE_DOWN; + break; + case MENU_ATTACHED_USB: + return PLUGIN_USB_CONNECTED; + case GO_TO_PREVIOUS: + return 0; + default: + break; + } + + if (id != HID_GENERIC_DESKTOP_UNDEFINED) + rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id); + } +} + +static int menu_presentation(void) +{ + int selection = 0; + + MENUITEM_STRINGLIST(menu, "Presentation", NULL, "Next Slide", "Prev Slide", + "Start Slideshow", "Leave Slideshow", "Black Screen", + "White Screen"); + while(1) + { + int id = HID_GENERIC_DESKTOP_UNDEFINED; + + selection = rb->do_menu(&menu, &selection, NULL, false); + + switch (selection) + { + case 0: /* Next Slide */ + id = HID_KEYBOARD_N; + break; + case 1: /* Prev Slide */ + id = HID_KEYBOARD_P; + break; + case 2: /* Start Slideshow */ + id = HID_KEYBOARD_F5; + break; + case 3: /* Leave Slideshow */ + id = HID_KEYBOARD_ESCAPE; + break; + case 4: /* Black Screen */ + id = HID_KEYBOARD_DOT; + break; + case 5: /* White Screen */ + id = HID_KEYBOARD_COMMA; + break; + case MENU_ATTACHED_USB: + return PLUGIN_USB_CONNECTED; + case GO_TO_PREVIOUS: + return 0; + default: + break; + } + + if (id != HID_GENERIC_DESKTOP_UNDEFINED) + rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id); + } +} + +static int menu_media_player(void) +{ + int selection = 0; + + MENUITEM_STRINGLIST(menu, "Media Player", NULL, "Play", "Stop", "Next", + "Previous", "Volume Up", "Volume Down", "Mute"); + while(1) + { + int id = HID_CONSUMER_USAGE_UNASSIGNED; + + selection = rb->do_menu(&menu, &selection, NULL, false); + + switch (selection) + { + case 0: /* Play */ + id = HID_CONSUMER_USAGE_PLAY_PAUSE; + break; + case 1: /* Stop */ + id = HID_CONSUMER_USAGE_STOP; + break; + case 2: /* Next */ + id = HID_CONSUMER_USAGE_SCAN_NEXT_TRACK; + break; + case 3: /* Previous */ + id = HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK; + break; + case 4: /* Volume Up */ + id = HID_CONSUMER_USAGE_VOLUME_INCREMENT; + break; + case 5: /* Volume Down */ + id = HID_CONSUMER_USAGE_VOLUME_DECREMENT; + break; + case 6: /* Mute */ + id = HID_CONSUMER_USAGE_MUTE; + break; + case MENU_ATTACHED_USB: + return PLUGIN_USB_CONNECTED; + case GO_TO_PREVIOUS: + return 0; + default: + break; + } + + if (id != HID_CONSUMER_USAGE_UNASSIGNED) + rb->usb_hid_send(HID_USAGE_PAGE_CONSUMER, id); + } +} + +/***************************************************************************** +* plugin entry point. +******************************************************************************/ +enum plugin_status plugin_start(const void* parameter) +{ + enum plugin_status rc = PLUGIN_USB_CONNECTED; + int selection = 0; + + (void)parameter; + + rb->lcd_clear_display(); + +#if LCD_DEPTH > 1 + rb->lcd_set_backdrop(NULL); +#endif + rb->lcd_setfont(FONT_SYSFIXED); + + remote_control_setcolors(); + + MENUITEM_STRINGLIST(menu, "Remote Control", NULL, "Desktop", "Presentation", + "Media Player", "Quit"); + while(1) + { + selection = rb->do_menu(&menu, &selection, NULL, false); + switch (selection) + { + case 0: /* Desktop */ + if (menu_desktop() == PLUGIN_USB_CONNECTED) + goto Exit; + break; + case 1: /* Presentation */ + if (menu_presentation() == PLUGIN_USB_CONNECTED) + goto Exit; + break; + case 2: /* Media Player */ + if (menu_media_player() == PLUGIN_USB_CONNECTED) + goto Exit; + break; + case 3: /* Quit */ + case GO_TO_PREVIOUS: + rc = PLUGIN_OK; + goto Exit; + case MENU_ATTACHED_USB: + goto Exit; + default: + break; + } + } +Exit: + rb->lcd_setfont(FONT_UI); + + return rc; +} + |