Skip to content

Commit

Permalink
input: Improve keyboard mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryzee119 committed Jul 24, 2022
1 parent 865dff8 commit 8ff2ddf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ set(LVGL_DIR "${PROJECT_DIR}/lib/lvgl")
set(LV_CONF_PATH ${PROJECT_DIR}/lv_conf.h CACHE STRING "" FORCE)

add_definitions(-DLVGL_USE_CUSTOM_CONTROLLER_MAP)
add_definitions(-DLVGL_USE_CUSTOM_KEYBOARD_MAP)
add_definitions(-DLV_LVGL_H_INCLUDE_SIMPLE)
add_definitions(-DLV_CONF_PATH=${LV_CONF_PATH})
add_definitions(-DJPEG_DECODER_QUEUE_SIZE=1024)
add_definitions(-DQRURL=\"https://github.com/Ryzee119/LithiumX\")
#add_definitions(-DDBG) #Show fps and memory usage info
add_definitions(-DSHOW_FPS_MEM) #Show fps and memory usage info

add_compile_options(-Wall -O3)
file(GLOB PROJECT_FILES
Expand Down
1 change: 1 addition & 0 deletions Makefile.nxdk
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CFLAGS += \
-DWIN32 \
-DSDL_DISABLE_JOYSTICK_INIT_DELAY \
-DLVGL_USE_CUSTOM_CONTROLLER_MAP \
-DLVGL_USE_CUSTOM_KEYBOARD_MAP \
-DDEBUG_CONSOLE \
-DBUILD_VERSION=\"$(GIT_COMMIT_HASH)\" \
-DQRURL=\"https://github.com/Ryzee119/LithiumX\" \
Expand Down
7 changes: 5 additions & 2 deletions src/lvgl_drivers/lv_sdl_indev.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static keyboard_map_t lvgl_keyboard_map[] =
{.sdl_map = SDLK_UP, .lvgl_map = LV_KEY_UP},
{.sdl_map = SDLK_DOWN, .lvgl_map = LV_KEY_DOWN},
{.sdl_map = SDLK_LEFT, .lvgl_map = LV_KEY_LEFT},
{.sdl_map = SDLK_RIGHT, .lvgl_map = LV_KEY_RIGHT}};
{.sdl_map = SDLK_RIGHT, .lvgl_map = LV_KEY_RIGHT}
{.sdl_map = 0, .lvgl_map = 0});
#else
extern keyboard_map_t lvgl_keyboard_map[];
#endif
Expand Down Expand Up @@ -223,13 +224,15 @@ static void keypad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
// Handle keyboard button events
if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP)
{
for (size_t i = 0; i < (sizeof(lvgl_keyboard_map) / sizeof(keyboard_map_t)); i++)
int i = 0;
while (lvgl_keyboard_map[i].sdl_map !=0)
{
if (lvgl_keyboard_map[i].sdl_map == e.key.keysym.sym)
{
data->key = lvgl_keyboard_map[i].lvgl_map;
data->state = (e.type == SDL_KEYUP) ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
}
i++;
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ gamecontroller_map_t lvgl_gamecontroller_map[] =
{.sdl_map = SDL_CONTROLLER_BUTTON_DPAD_LEFT, .lvgl_map = LV_KEY_LEFT},
{.sdl_map = SDL_CONTROLLER_BUTTON_DPAD_RIGHT, .lvgl_map = LV_KEY_RIGHT}
};

keyboard_map_t lvgl_keyboard_map[] =
{
{.sdl_map = SDLK_ESCAPE, .lvgl_map = DASH_SETTINGS_PAGE},
{.sdl_map = SDLK_BACKSPACE, .lvgl_map = LV_KEY_ESC},
{.sdl_map = SDLK_RETURN, .lvgl_map = LV_KEY_ENTER},
{.sdl_map = SDLK_PAGEDOWN, .lvgl_map = DASH_PREV_PAGE},
{.sdl_map = SDLK_PAGEUP, .lvgl_map = DASH_NEXT_PAGE},
{.sdl_map = SDLK_UP, .lvgl_map = LV_KEY_UP},
{.sdl_map = SDLK_DOWN, .lvgl_map = LV_KEY_DOWN},
{.sdl_map = SDLK_LEFT, .lvgl_map = LV_KEY_LEFT},
{.sdl_map = SDLK_RIGHT, .lvgl_map = LV_KEY_RIGHT}
};
/* clang-format on */

// LVGL isn't thread safe but we can use threads if we put locks around lv_task_handler
Expand Down

0 comments on commit 8ff2ddf

Please sign in to comment.