diff options
-rw-r--r-- | apps/SOURCES | 2 | ||||
-rw-r--r-- | apps/keymaps/keymap-sdl.c | 216 | ||||
-rw-r--r-- | firmware/export/config.h | 1 | ||||
-rw-r--r-- | firmware/export/config/application.h | 7 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/app/button-application.c | 56 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/app/button-target.h | 37 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/button-sdl.c | 18 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/key_to_touch-sdl.c | 9 | ||||
-rw-r--r-- | uisimulator/buttonmap/ipod.c | 6 | ||||
-rw-r--r-- | uisimulator/buttonmap/sansa-e200.c | 6 | ||||
-rw-r--r-- | uisimulator/buttonmap/sansa-fuze.c | 6 |
11 files changed, 335 insertions, 29 deletions
diff --git a/apps/SOURCES b/apps/SOURCES index a00239428c..9bc8859746 100644 --- a/apps/SOURCES +++ b/apps/SOURCES @@ -295,4 +295,6 @@ keymaps/keymap-vibe500.c keymaps/keymap-mpio-hd200.c #elif CONFIG_KEYPAD == ANDROID_PAD keymaps/keymap-android.c +#elif CONFIG_KEYPAD == SDL_PAD +keymaps/keymap-sdl.c #endif diff --git a/apps/keymaps/keymap-sdl.c b/apps/keymaps/keymap-sdl.c new file mode 100644 index 0000000000..ce10c5cf17 --- /dev/null +++ b/apps/keymaps/keymap-sdl.c @@ -0,0 +1,216 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Maurus Cuelenaere + * + * 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. + * + ****************************************************************************/ + +/* Button Code Definitions for Android targets */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "config.h" +#include "action.h" +#include "button.h" +#include "settings.h" + +/* + * The format of the list is as follows + * { Action Code, Button code, Prereq button code } + * if there's no need to check the previous button's value, use BUTTON_NONE + * Insert LAST_ITEM_IN_LIST at the end of each mapping + */ + +static const struct button_mapping button_context_standard[] = { + { ACTION_STD_PREV, BUTTON_SCROLL_BACK, BUTTON_NONE }, + { ACTION_STD_PREVREPEAT, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_STD_NEXT, BUTTON_SCROLL_FWD, BUTTON_NONE }, + { ACTION_STD_NEXTREPEAT, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_STD_PREV, BUTTON_UP, BUTTON_NONE }, + { ACTION_STD_PREVREPEAT, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_STD_NEXT, BUTTON_DOWN, BUTTON_NONE }, + { ACTION_STD_NEXTREPEAT, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_STD_OK, BUTTON_CENTER|BUTTON_REL, BUTTON_CENTER }, + { ACTION_STD_OK, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT }, + { ACTION_STD_CANCEL, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_STD_CANCEL, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT }, + + { ACTION_STD_CONTEXT, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_standard */ + +static const struct button_mapping button_context_wps[] = { + { ACTION_WPS_BROWSE, BUTTON_BACK, BUTTON_NONE }, + { ACTION_WPS_MENU, BUTTON_MENU|BUTTON_REL, BUTTON_MENU }, + { ACTION_WPS_CONTEXT, BUTTON_MENU|BUTTON_REPEAT, BUTTON_MENU }, + + { ACTION_WPS_VOLUP, BUTTON_SCROLL_FWD, BUTTON_NONE }, + { ACTION_WPS_VOLUP, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_WPS_VOLDOWN, BUTTON_SCROLL_BACK, BUTTON_NONE }, + { ACTION_WPS_VOLDOWN, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_wps */ + +static const struct button_mapping button_context_list[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_list */ + +static const struct button_mapping button_context_tree[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST) +}; /* button_context_tree */ + +static const struct button_mapping button_context_listtree_scroll_with_combo[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE), +}; + +static const struct button_mapping button_context_listtree_scroll_without_combo[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE), +}; + +static const struct button_mapping button_context_settings[] = { + { ACTION_SETTINGS_INC, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_SETTINGS_INCREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_SETTINGS_DEC, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_SETTINGS_DECREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_STD_OK, BUTTON_CENTER, BUTTON_NONE }, + { ACTION_STD_CANCEL, BUTTON_BACK, BUTTON_NONE }, + { ACTION_SETTINGS_INC, BUTTON_SCROLL_FWD, BUTTON_NONE }, + { ACTION_SETTINGS_INCREPEAT,BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_SETTINGS_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE }, + { ACTION_SETTINGS_DECREPEAT,BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_settings */ + +static const struct button_mapping button_context_settings_right_is_inc[] = { + { ACTION_SETTINGS_INC, BUTTON_SCROLL_FWD, BUTTON_NONE }, + { ACTION_SETTINGS_INCREPEAT, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_SETTINGS_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE }, + { ACTION_SETTINGS_DECREPEAT, BUTTON_SCROLL_BACK|BUTTON_REPEAT,BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_settingsgraphical */ + +static const struct button_mapping button_context_yesno[] = { + { ACTION_YESNO_ACCEPT, BUTTON_CENTER, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_settings_yesno */ + +static const struct button_mapping button_context_colorchooser[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_SETTINGS), +}; /* button_context_colorchooser */ + +static const struct button_mapping button_context_eq[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_SETTINGS), +}; /* button_context_eq */ + +/** Bookmark Screen **/ +static const struct button_mapping button_context_bmark[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST), +}; /* button_context_bmark */ + +static const struct button_mapping button_context_time[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS), +}; /* button_context_time */ + +static const struct button_mapping button_context_quickscreen[] = { + { ACTION_STD_CANCEL, BUTTON_BACK|BUTTON_REL, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_quickscreen */ + +static const struct button_mapping button_context_pitchscreen[] = { + + { ACTION_PS_INC_SMALL, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_PS_INC_BIG, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_PS_DEC_SMALL, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_PS_DEC_BIG, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_PS_EXIT, BUTTON_BACK, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_pitchcreen */ + +static const struct button_mapping button_context_keyboard[] = { + { ACTION_KBD_PAGE_FLIP, BUTTON_MENU, BUTTON_NONE }, + { ACTION_KBD_CURSOR_LEFT, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_KBD_CURSOR_LEFT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_KBD_CURSOR_RIGHT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_KBD_CURSOR_RIGHT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_keyboard */ + +static const struct button_mapping button_context_radio[] = { + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS) +}; /* button_context_radio */ + +const struct button_mapping* target_get_context_mapping(int context) +{ + switch (context) + { + case CONTEXT_STD: + return button_context_standard; + case CONTEXT_WPS: + return button_context_wps; + + case CONTEXT_LIST: + return button_context_list; + case CONTEXT_MAINMENU: + case CONTEXT_TREE: + if (global_settings.hold_lr_for_scroll_in_list) + return button_context_listtree_scroll_without_combo; + else + return button_context_listtree_scroll_with_combo; + case CONTEXT_CUSTOM|CONTEXT_TREE: + return button_context_tree; + + case CONTEXT_SETTINGS: + return button_context_settings; + case CONTEXT_CUSTOM|CONTEXT_SETTINGS: + case CONTEXT_SETTINGS_RECTRIGGER: + return button_context_settings_right_is_inc; + + case CONTEXT_SETTINGS_COLOURCHOOSER: + return button_context_colorchooser; + case CONTEXT_SETTINGS_EQ: + return button_context_eq; + + case CONTEXT_SETTINGS_TIME: + return button_context_time; + + case CONTEXT_YESNOSCREEN: + return button_context_yesno; + case CONTEXT_FM: + return button_context_radio; + case CONTEXT_BOOKMARKSCREEN: + return button_context_bmark; + case CONTEXT_QUICKSCREEN: + return button_context_quickscreen; + case CONTEXT_PITCHSCREEN: + return button_context_pitchscreen; + case CONTEXT_KEYBOARD: + return button_context_keyboard; + } + return button_context_standard; +} diff --git a/firmware/export/config.h b/firmware/export/config.h index 409c9d9965..83a9ea4feb 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -129,6 +129,7 @@ #define PBELL_VIBE500_PAD 43 #define MPIO_HD200_PAD 44 #define ANDROID_PAD 45 +#define SDL_PAD 46 /* CONFIG_REMOTE_KEYPAD */ #define H100_REMOTE 1 diff --git a/firmware/export/config/application.h b/firmware/export/config/application.h index 6a87d5f62a..6219aa6fad 100644 --- a/firmware/export/config/application.h +++ b/firmware/export/config/application.h @@ -75,10 +75,13 @@ /* Define this if you do software codec */ #define CONFIG_CODEC SWCODEC -#ifdef ANDROID +#if (CONFIG_PLATFORM & PLATFORM_ANDROID) #define CONFIG_KEYPAD ANDROID_PAD +#elif (CONFIG_PLATFORM & PLATFORM_SDL) +#define HAVE_SCROLLWHEEL +#define CONFIG_KEYPAD SDL_PAD #else -#define CONFIG_KEYPAD COWON_D2_PAD +#error unknown platform #endif #if (CONFIG_PLATFORM & PLATFORM_SDL) diff --git a/firmware/target/hosted/sdl/app/button-application.c b/firmware/target/hosted/sdl/app/button-application.c index a27f769718..3f31933951 100644 --- a/firmware/target/hosted/sdl/app/button-application.c +++ b/firmware/target/hosted/sdl/app/button-application.c @@ -20,10 +20,62 @@ ***************************************************9*************************/ +#include <stdio.h> +#include <SDL.h> #include "button.h" +#include "buttonmap.h" int key_to_button(int keyboard_key) { - (void)keyboard_key; - return BUTTON_NONE; + int new_btn = BUTTON_NONE; + switch (keyboard_key) + { + case SDLK_KP7: + new_btn = BUTTON_TOPLEFT; + break; + case SDLK_KP8: + new_btn = BUTTON_TOPMIDDLE; + break; + case SDLK_KP9: + new_btn = BUTTON_TOPRIGHT; + break; + case SDLK_KP4: + case SDLK_LEFT: + new_btn = BUTTON_MIDLEFT; + break; + case SDLK_KP5: + new_btn = BUTTON_CENTER; + break; + case SDLK_KP6: + case SDLK_RIGHT: + new_btn = BUTTON_MIDRIGHT; + break; + case SDLK_KP1: + new_btn = BUTTON_BOTTOMLEFT; + break; + case SDLK_KP2: + case SDLK_DOWN: + new_btn = BUTTON_BOTTOMMIDDLE; + break; + case SDLK_KP3: + new_btn = BUTTON_BOTTOMRIGHT; + break; +#ifdef HAVE_SCROLLWHEEL + case SDL_BUTTON_WHEELUP: + new_btn = BUTTON_SCROLL_BACK; + break; + case SDL_BUTTON_WHEELDOWN: + new_btn = BUTTON_SCROLL_FWD; + break; +#endif + case SDL_BUTTON_RIGHT: + new_btn = BUTTON_MIDLEFT; + break; + case SDL_BUTTON_MIDDLE: + new_btn = BUTTON_MIDRIGHT; + break; + default: + break; + } + return new_btn; } diff --git a/firmware/target/hosted/sdl/app/button-target.h b/firmware/target/hosted/sdl/app/button-target.h index 54ae3a2fae..5295315e2e 100644 --- a/firmware/target/hosted/sdl/app/button-target.h +++ b/firmware/target/hosted/sdl/app/button-target.h @@ -34,27 +34,26 @@ void button_init_device(void); int button_read_device(int *data); /* Main unit's buttons */ -#define BUTTON_POWER 0x00000001 -#define BUTTON_PLUS 0x00000002 -#define BUTTON_MINUS 0x00000004 -#define BUTTON_MENU 0x00000008 - -/* Compatibility hacks for flipping. Needs a somewhat better fix. */ -#define BUTTON_LEFT BUTTON_MIDLEFT -#define BUTTON_RIGHT BUTTON_MIDRIGHT -#define BUTTON_UP BUTTON_TOPMIDDLE -#define BUTTON_DOWN BUTTON_BOTTOMMIDDLE +#define BUTTON_UP 0x00000001 +#define BUTTON_DOWN 0x00000002 +#define BUTTON_LEFT 0x00000004 +#define BUTTON_RIGHT 0x00000008 +#define BUTTON_SELECT 0x00000010 +#define BUTTON_MENU 0x00000020 +#define BUTTON_BACK 0x00000040 +#define BUTTON_SCROLL_FWD 0x00000100 +#define BUTTON_SCROLL_BACK 0x00000200 /* Touch Screen Area Buttons */ -#define BUTTON_TOPLEFT 0x00000010 -#define BUTTON_TOPMIDDLE 0x00000020 -#define BUTTON_TOPRIGHT 0x00000040 -#define BUTTON_MIDLEFT 0x00000080 -#define BUTTON_CENTER 0x00000100 -#define BUTTON_MIDRIGHT 0x00000200 -#define BUTTON_BOTTOMLEFT 0x00000400 -#define BUTTON_BOTTOMMIDDLE 0x00000800 -#define BUTTON_BOTTOMRIGHT 0x00001000 +#define BUTTON_TOPLEFT 0x00001000 +#define BUTTON_TOPMIDDLE 0x00002000 +#define BUTTON_TOPRIGHT 0x00004000 +#define BUTTON_MIDLEFT 0x00008000 +#define BUTTON_CENTER 0x00010000 +#define BUTTON_MIDRIGHT 0x00020000 +#define BUTTON_BOTTOMLEFT 0x00040000 +#define BUTTON_BOTTOMMIDDLE 0x00080000 +#define BUTTON_BOTTOMRIGHT 0x00100000 #define BUTTON_MAIN 0x1FFF diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c index ee16e55fd1..519ac8d7c5 100644 --- a/firmware/target/hosted/sdl/button-sdl.c +++ b/firmware/target/hosted/sdl/button-sdl.c @@ -112,9 +112,16 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up) if(button_up) { switch ( event->button ) { +#ifdef HAVE_SCROLLWHEEL + case SDL_BUTTON_WHEELUP: + case SDL_BUTTON_WHEELDOWN: +#endif + case SDL_BUTTON_MIDDLE: + case SDL_BUTTON_RIGHT: + button_event( event->button, false ); + break; /* The scrollwheel button up events are ignored as they are queued immediately */ case SDL_BUTTON_LEFT: - case SDL_BUTTON_MIDDLE: if ( mapping && background ) { printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, y, (int)sqrt( SQUARE(x-(int)event->x) + SQUARE(y-(int)event->y)) @@ -137,14 +144,13 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up) { #ifdef HAVE_SCROLLWHEEL case SDL_BUTTON_WHEELUP: - button_event( SDLK_UP, true ); - break; case SDL_BUTTON_WHEELDOWN: - button_event( SDLK_DOWN, true ); - break; #endif - case SDL_BUTTON_LEFT: case SDL_BUTTON_MIDDLE: + case SDL_BUTTON_RIGHT: + button_event( event->button, true ); + break; + case SDL_BUTTON_LEFT: if ( mapping && background ) { x = event->x; y = event->y; diff --git a/firmware/target/hosted/sdl/key_to_touch-sdl.c b/firmware/target/hosted/sdl/key_to_touch-sdl.c index 90518c7c7e..a63df18ff5 100644 --- a/firmware/target/hosted/sdl/key_to_touch-sdl.c +++ b/firmware/target/hosted/sdl/key_to_touch-sdl.c @@ -51,6 +51,7 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords) } } break; +#ifndef CONFIG_PLATFORM case SDLK_KP7: case SDLK_7: new_btn = BUTTON_TOPLEFT; @@ -58,6 +59,9 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords) case SDLK_KP8: case SDLK_8: case SDLK_UP: +#ifdef HAVE_SCROLLWHEEL + case SDL_BUTTON_WHEELDOWN: +#endif new_btn = BUTTON_TOPMIDDLE; break; case SDLK_KP9: @@ -71,6 +75,7 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords) break; case SDLK_KP5: case SDLK_i: + case SDL_BUTTON_MIDDLE: new_btn = BUTTON_CENTER; break; case SDLK_KP6: @@ -84,6 +89,9 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords) break; case SDLK_KP2: case SDLK_k: +#ifdef HAVE_SCROLLWHEEL + case SDL_BUTTON_WHEELDOWN: +#endif case SDLK_DOWN: new_btn = BUTTON_BOTTOMMIDDLE; break; @@ -91,6 +99,7 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords) case SDLK_l: new_btn = BUTTON_BOTTOMRIGHT; break; +#endif } return new_btn; } diff --git a/uisimulator/buttonmap/ipod.c b/uisimulator/buttonmap/ipod.c index 504b77b8dd..1fc95d8dd1 100644 --- a/uisimulator/buttonmap/ipod.c +++ b/uisimulator/buttonmap/ipod.c @@ -58,6 +58,12 @@ int key_to_button(int keyboard_button) case SDLK_INSERT: new_btn = BUTTON_MENU; break; + case SDL_BUTTON_WHEELUP: + new_btn = BUTTON_SCROLL_BACK; + break; + case SDL_BUTTON_WHEELDOWN: + new_btn = BUTTON_SCROLL_FWD; + break; } return new_btn; } diff --git a/uisimulator/buttonmap/sansa-e200.c b/uisimulator/buttonmap/sansa-e200.c index 66655e26c5..b9a872caa1 100644 --- a/uisimulator/buttonmap/sansa-e200.c +++ b/uisimulator/buttonmap/sansa-e200.c @@ -65,6 +65,12 @@ int key_to_button(int keyboard_button) case SDLK_SPACE: new_btn = BUTTON_SELECT; break; + case SDL_BUTTON_WHEELUP: + new_btn = BUTTON_SCROLL_BACK; + break; + case SDL_BUTTON_WHEELDOWN: + new_btn = BUTTON_SCROLL_FWD; + break; } return new_btn; } diff --git a/uisimulator/buttonmap/sansa-fuze.c b/uisimulator/buttonmap/sansa-fuze.c index 2788af5d51..fcd935946e 100644 --- a/uisimulator/buttonmap/sansa-fuze.c +++ b/uisimulator/buttonmap/sansa-fuze.c @@ -66,6 +66,12 @@ int key_to_button(int keyboard_button) case SDLK_RETURN: new_btn = BUTTON_SELECT; break; + case SDL_BUTTON_WHEELUP: + new_btn = BUTTON_SCROLL_BACK; + break; + case SDL_BUTTON_WHEELDOWN: + new_btn = BUTTON_SCROLL_FWD; + break; } return new_btn; } |