diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/gui/usb_screen.c | 41 | ||||
-rw-r--r-- | apps/lang/english.lang | 17 | ||||
-rw-r--r-- | apps/menus/settings_menu.c | 2 | ||||
-rw-r--r-- | apps/misc.c | 12 | ||||
-rw-r--r-- | apps/misc.h | 7 | ||||
-rw-r--r-- | apps/screens.c | 12 | ||||
-rw-r--r-- | apps/settings.h | 1 | ||||
-rw-r--r-- | apps/settings_list.c | 2 | ||||
-rw-r--r-- | apps/usb_keymaps.c | 62 |
9 files changed, 101 insertions, 55 deletions
diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c index f2c25554df..50188274d2 100644 --- a/apps/gui/usb_screen.c +++ b/apps/gui/usb_screen.c @@ -49,6 +49,7 @@ #ifdef USB_ENABLE_HID int usb_keypad_mode; +static bool usb_hid; #endif #ifndef SIMULATOR @@ -64,7 +65,7 @@ static int handle_usb_events(void) { int button; #ifdef USB_ENABLE_HID - if (usb_core_driver_enabled(USB_DRIVER_HID)) + if (usb_hid) { button = get_hid_usb_action(); @@ -157,20 +158,24 @@ static void usb_screen_fix_viewports(struct screen *screen, logo->height = logo_height; #ifdef USB_ENABLE_HID - struct viewport *title = &usb_screen_vps->title; - int char_height, nb_lines; + if (usb_hid) + { + struct viewport *title = &usb_screen_vps->title; + int char_height, nb_lines; - /* nb_lines only returns the number of fully visible lines, small screens - or really large fonts could cause problems with the calculation below. - */ - nb_lines = viewport_get_nb_lines(parent); - if (nb_lines == 0) - nb_lines++; + /* nb_lines only returns the number of fully visible lines, small + * screens or really large fonts could cause problems with the + * calculation below. + */ + nb_lines = viewport_get_nb_lines(parent); + if (nb_lines == 0) + nb_lines++; - char_height = parent->height/nb_lines; + char_height = parent->height/nb_lines; - *title = *parent; - title->y = logo->y + logo->height + char_height; + *title = *parent; + title->y = logo->y + logo->height + char_height; + } #endif } #endif @@ -209,9 +214,12 @@ static void usb_screens_draw(struct usb_screen_vps_t *usb_screen_vps_ar) screen->transparent_bitmap(usblogo, 0, 0, logo->width, logo->height); #ifdef USB_ENABLE_HID - screen->set_viewport(&usb_screen_vps->title); - usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER; - screen->puts_scroll(0, 0, str(keypad_mode_name_get())); + if (usb_hid) + { + screen->set_viewport(&usb_screen_vps->title); + usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER; + screen->puts_scroll(0, 0, str(keypad_mode_name_get())); + } #endif /* USB_ENABLE_HID */ } screen->set_viewport(parent); @@ -252,6 +260,7 @@ void gui_usb_screen_run(void) #endif #ifdef USB_ENABLE_HID + usb_hid = global_settings.usb_hid; usb_keypad_mode = global_settings.usb_keypad_mode; #endif @@ -283,7 +292,7 @@ void gui_usb_screen_run(void) const struct viewport* vp = NULL; #if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID) - vp = &usb_screen_vps_ar[i].title; + vp = usb_hid ? &usb_screen_vps_ar[i].title : NULL; #elif !defined(HAVE_LCD_BITMAP) vp = &usb_screen_vps_ar[i].parent; #endif diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 16fc022af6..d7dba2f3c0 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -13165,3 +13165,20 @@ remote: "Remote Custom Statusbar" </voice> </phrase> +<phrase> + id: LANG_USB_HID + desc: in settings_menu + user: core + <source> + *: none + usb_hid: "USB HID" + </source> + <dest> + *: none + usb_hid: "USB HID" + </dest> + <voice> + *: none + usb_hid: "USB Human Interface Device" + </voice> +</phrase> diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 71a6089e68..c11bf0eb3d 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -253,6 +253,7 @@ MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL); #endif MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); #ifdef USB_ENABLE_HID +MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL); MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL); #endif @@ -304,6 +305,7 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), &touchpad_sensitivity, #endif #ifdef USB_ENABLE_HID + &usb_hid, &usb_keypad_mode, #endif ); diff --git a/apps/misc.c b/apps/misc.c index 47ebf58080..5af57feb11 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -1047,4 +1047,16 @@ err: va_end(ap); return 0; } + +/* only used in USB HID and set_time screen */ +#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0) +int clamp_value_wrap(int value, int max, int min) +{ + if (value > max) + return min; + if (value < min) + return max; + return value; +} +#endif #endif diff --git a/apps/misc.h b/apps/misc.h index a8ed6029a3..857d9ab4da 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -92,6 +92,7 @@ bool dir_exists(const char *path); */ char *strip_extension(char* buffer, int buffer_size, const char *filename); +#ifdef HAVE_LCD_BITMAP /* A simplified scanf */ /* * Checks whether the value at position 'position' was really read @@ -103,4 +104,10 @@ char *strip_extension(char* buffer, int buffer_size, const char *filename); const char* parse_list(const char *fmt, uint32_t *set_vals, const char sep, const char* str, ...); +/* only used in USB HID and set_time screen */ +#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0) +int clamp_value_wrap(int value, int max, int min); +#endif +#endif + #endif /* MISC_H */ diff --git a/apps/screens.c b/apps/screens.c index ab721a8654..5f84830c00 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -60,18 +60,6 @@ #include "dsp.h" #endif -/* only used in set_time screen */ -#if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) -static int clamp_value_wrap(int value, int max, int min) -{ - if (value > max) - return min; - if (value < min) - return max; - return value; -} -#endif - #if (CONFIG_STORAGE & STORAGE_MMC) int mmc_remove_request(void) { diff --git a/apps/settings.h b/apps/settings.h index d1179ed5bc..c9ff3f9dd3 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -781,6 +781,7 @@ struct user_settings /* new stuff to be added at the end */ #ifdef USB_ENABLE_HID + bool usb_hid; int usb_keypad_mode; #endif diff --git a/apps/settings_list.c b/apps/settings_list.c index 5bfce331cd..5a0e05d7d2 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -31,6 +31,7 @@ #include "backlight.h" #include "settings.h" #include "settings_list.h" +#include "usb.h" #include "sound.h" #include "dsp.h" #include "mpeg.h" @@ -1623,6 +1624,7 @@ const struct settings_list settings[] = { #endif #ifdef USB_ENABLE_HID + OFFON_SETTING(0, usb_hid, LANG_USB_HID, true, "usb hid", usb_set_hid), CHOICE_SETTING(0, usb_keypad_mode, LANG_USB_KEYPAD_MODE, 0, "usb keypad mode", "multimedia,presentation,browser" #ifdef HAVE_USB_HID_MOUSE diff --git a/apps/usb_keymaps.c b/apps/usb_keymaps.c index f787de692f..f04fa54c3d 100644 --- a/apps/usb_keymaps.c +++ b/apps/usb_keymaps.c @@ -23,6 +23,7 @@ #ifdef USB_ENABLE_HID #include "action.h" #include "lang.h" +#include "misc.h" #include "usbstack/usb_hid.h" //#define LOGF_ENABLE #include "logf.h" @@ -174,40 +175,47 @@ extern int usb_keypad_mode; int get_hid_usb_action(void) { - int action; + int action, step; const hid_key_mapping_t *key_mapping = hid_key_mappings[usb_keypad_mode]; + step = -1; action = get_action(key_mapping->context, HZ/4); - /* Skip key mappings in a cyclic way */ - if (action == ACTION_USB_HID_MODE_SWITCH_NEXT) - { - /* TODO: Use clamp_value_wrap() */ - usb_keypad_mode = (usb_keypad_mode + 1) % NUM_KEY_MAPPINGS; - } - else if (action == ACTION_USB_HID_MODE_SWITCH_PREV) - { - /* TODO: Use clamp_value_wrap() */ - usb_keypad_mode = (usb_keypad_mode - 1) % NUM_KEY_MAPPINGS; - } - else if (action > ACTION_USB_HID_FIRST && action < ACTION_USB_HID_LAST) + switch (action) { - const mapping_t *mapping; - const hid_key_mapping_t *key_mapping = - hid_key_mappings[usb_keypad_mode]; - - for (mapping = key_mapping->mapping; mapping->action; mapping++) - { - if (action == mapping->action) + case ACTION_USB_HID_MODE_SWITCH_NEXT: + step = 1; + case ACTION_USB_HID_MODE_SWITCH_PREV: + /* Switch key mappings in a cyclic way */ + usb_keypad_mode = clamp_value_wrap(usb_keypad_mode + step, + NUM_KEY_MAPPINGS - 1, 0); + break; + default: { - logf("Action %d", action); - usb_hid_send(key_mapping->usage_page, mapping->id); - break; - } - } + const mapping_t *mapping; + const hid_key_mapping_t *key_mapping = + hid_key_mappings[usb_keypad_mode]; + + if (action <= ACTION_USB_HID_FIRST || + action >= ACTION_USB_HID_LAST) + { + break; + } + + for (mapping = key_mapping->mapping; mapping->action; mapping++) + { + if (action == mapping->action) + { + logf("Action %d", action); + usb_hid_send(key_mapping->usage_page, mapping->id); + break; + } + } #ifdef DEBUG - if (!mapping->action) - logf("Action %d not found", action); + if (!mapping->action) + logf("Action %d not found", action); #endif + break; + } } return action; |