From e409fba7f85e9ddf51e2d6a3342dbca6f667e280 Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Sat, 18 Jul 2009 12:58:29 +0000 Subject: 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 --- apps/debug_menu.c | 60 ----------- apps/plugin.c | 8 ++ apps/plugin.h | 10 +- apps/plugins/CATEGORIES | 1 + apps/plugins/SOURCES | 3 + apps/plugins/remote_control.c | 231 ++++++++++++++++++++++++++++++++++++++++++ apps/screens.c | 20 ++-- 7 files changed, 262 insertions(+), 71 deletions(-) create mode 100644 apps/plugins/remote_control.c (limited to 'apps') diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 648a7e6cae..6a40d4b54a 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -112,13 +112,6 @@ #include "as3514.h" #endif -#ifdef HAVE_USBSTACK -#include "usb_core.h" -#ifdef USB_ENABLE_HID -#include "usbstack/usb_hid.h" -#endif -#endif - /*---------------------------------------------------*/ /* SPECIAL DEBUG STUFF */ /*---------------------------------------------------*/ @@ -2635,50 +2628,6 @@ static bool toggle_usb_serial(void) } #endif -#ifdef USB_ENABLE_HID -static bool hid_send_cmd(consumer_usage_page_t cmd, char *msg) -{ - (void)msg; - - if (!usb_core_driver_enabled(USB_DRIVER_HID)) { - splashf(HZ, "Send failed. Driver is disabled"); - return false; - } - - usb_hid_send_consumer_usage(cmd); - logf("Sent %s command", msg); - - return false; -} -static bool usb_hid_send_play_pause(void) -{ - return hid_send_cmd(PLAY_PAUSE, "Play/Pause"); -} -static bool usb_hid_send_stop(void) -{ - return hid_send_cmd(STOP, "Stop"); -} -static bool usb_hid_send_scan_previous_track(void) -{ - return hid_send_cmd(SCAN_PREVIOUS_TRACK, "Scan previous track"); -} -static bool usb_hid_send_scan_next_track(void) -{ - return hid_send_cmd(SCAN_NEXT_TRACK, "Scan next track"); -} -static bool usb_hid_send_mute(void) -{ - return hid_send_cmd(MUTE, "Mute"); -} -static bool usb_hid_send_volume_decrement(void) -{ - return hid_send_cmd(VOLUME_DECREMENT, "Vol Down"); -} -static bool usb_hid_send_volume_increment(void) -{ - return hid_send_cmd(VOLUME_INCREMENT, "Vol Up"); -} -#endif #endif #if CONFIG_USBOTG == USBOTG_ISP1583 @@ -2819,15 +2768,6 @@ static const struct the_menu_item menuitems[] = { #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL) {"USB Serial driver (logf)", toggle_usb_serial }, #endif -#if defined(USB_ENABLE_HID) - {"USB HID play/pause", usb_hid_send_play_pause }, - {"USB HID stop", usb_hid_send_stop }, - {"USB HID prev track", usb_hid_send_scan_previous_track }, - {"USB HID next track", usb_hid_send_scan_next_track }, - {"USB HID mute", usb_hid_send_mute }, - {"USB HID vol down", usb_hid_send_volume_decrement }, - {"USB HID vol up", usb_hid_send_volume_increment }, -#endif #endif /* HAVE_USBSTACK */ #ifdef CPU_BOOST_LOGGING {"cpu_boost log",cpu_boost_log}, diff --git a/apps/plugin.c b/apps/plugin.c index 84200bbf05..35b4179949 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -51,6 +51,10 @@ #include "bidi.h" #endif +#if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID) +#include "usbstack/usb_hid.h" +#endif + #ifdef SIMULATOR #define PREFIX(_x_) sim_ ## _x_ #else @@ -660,6 +664,10 @@ static const struct plugin_api rockbox_api = { appsversion, /* new stuff at the end, sort into place next time the API gets incompatible */ + +#if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID) + usb_hid_send, +#endif }; int plugin_load(const char* plugin, const void* parameter) diff --git a/apps/plugin.h b/apps/plugin.h index a946f42a14..3809486d0a 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -105,6 +105,10 @@ void* plugin_get_buffer(size_t *buffer_size); #include "yesno.h" +#if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID) +#include "usbstack/usb_hid_usage_tables.h" +#endif + #ifdef PLUGIN #if defined(DEBUG) || defined(SIMULATOR) @@ -129,7 +133,7 @@ void* plugin_get_buffer(size_t *buffer_size); #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 164 +#define PLUGIN_API_VERSION 165 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any @@ -828,6 +832,10 @@ struct plugin_api { const char *appsversion; /* new stuff at the end, sort into place next time the API gets incompatible */ + +#if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID) + void (*usb_hid_send)(usage_page_t usage_page, int id); +#endif }; /* plugin header */ diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES index ab441f53a7..5d6570a9a4 100644 --- a/apps/plugins/CATEGORIES +++ b/apps/plugins/CATEGORIES @@ -63,6 +63,7 @@ pong,games ppmviewer,viewers properties,viewers random_folder_advance_config,apps +remote_control,apps reversi,games robotfindskitten,games rockblox,games diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 92d1ae6ef6..95ffb1c9de 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -165,3 +165,6 @@ md5sum.c lua.c #endif +#if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID) +remote_control.c +#endif 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; +} + diff --git a/apps/screens.c b/apps/screens.c index 829aa191e1..a19614dcd9 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -116,36 +116,36 @@ static int handle_usb_events(void) if (hid_enabled) { - consumer_usage_page_t cmd = UNASSIGNED; + int id = HID_CONSUMER_USAGE_UNASSIGNED; button = get_action(CONTEXT_USB_HID, HZ/4); switch (button) { case ACTION_USB_HID_PLAY: - cmd = PLAY_PAUSE; + id = HID_CONSUMER_USAGE_PLAY_PAUSE; break; case ACTION_USB_HID_STOP: - cmd = STOP; + id = HID_CONSUMER_USAGE_STOP; break; case ACTION_USB_HID_SKIPPREV: - cmd = SCAN_PREVIOUS_TRACK; + id = HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK; break; case ACTION_USB_HID_SKIPNEXT: - cmd = SCAN_NEXT_TRACK; + id = HID_CONSUMER_USAGE_SCAN_NEXT_TRACK; break; case ACTION_USB_HID_VOLDOWN: - cmd = VOLUME_DECREMENT; + id = HID_CONSUMER_USAGE_VOLUME_DECREMENT; break; case ACTION_USB_HID_VOLUP: - cmd = VOLUME_INCREMENT; + id = HID_CONSUMER_USAGE_VOLUME_INCREMENT; break; case ACTION_USB_HID_MUTE: - cmd = MUTE; + id = HID_CONSUMER_USAGE_MUTE; break; } - if (cmd != UNASSIGNED) - usb_hid_send_consumer_usage(cmd); + if (id != HID_CONSUMER_USAGE_UNASSIGNED) + usb_hid_send(HID_USAGE_PAGE_CONSUMER, id); } else #endif -- cgit v1.2.3