From 3d1f255d4650f2cab5e0fcbbe93540d728986fc2 Mon Sep 17 00:00:00 2001 From: Fred Date: Fri, 30 Oct 2020 22:58:15 +0100 Subject: [PATCH] Add keyboard implementation for linux --- meson.build | 1 + platform/drivers/keyboard/keyboard_linux.c | 56 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 platform/drivers/keyboard/keyboard_linux.c diff --git a/meson.build b/meson.build index d30441f8..fc5c192f 100644 --- a/meson.build +++ b/meson.build @@ -61,6 +61,7 @@ linux_src = src + ['openrtx/src/main.c', 'openrtx/src/state.c', 'openrtx/src/ui.c', 'platform/drivers/display/display_libSDL.c', + 'platform/drivers/keyboard/keyboard_linux.c', 'platform/mcu/x86_64/drivers/gpio.c', 'platform/mcu/x86_64/drivers/delays.c', 'platform/targets/linux/platform.c', diff --git a/platform/drivers/keyboard/keyboard_linux.c b/platform/drivers/keyboard/keyboard_linux.c new file mode 100644 index 00000000..3ee6bba2 --- /dev/null +++ b/platform/drivers/keyboard/keyboard_linux.c @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN * + * Frederik Saraci IU2NRO * + * Silvano Seva IU2KWO * + * * + * 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 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include +#include "keyboard.h" +#include + +uint32_t kbd_getKeys() { + SDL_Event event; + uint32_t keys = 0; + while ((SDL_PollEvent(&event)) != 0) { + if (event.type == SDL_QUIT) + exit(0); + //Ignore all non-keyboard events + if (event.type != SDL_KEYDOWN) return 0; + const uint8_t *state = SDL_GetKeyboardState(NULL); + if (state[SDL_SCANCODE_0]) keys |= KEY_0; + if (state[SDL_SCANCODE_1]) keys |= KEY_1; + if (state[SDL_SCANCODE_2]) keys |= KEY_2; + if (state[SDL_SCANCODE_3]) keys |= KEY_3; + if (state[SDL_SCANCODE_4]) keys |= KEY_4; + if (state[SDL_SCANCODE_5]) keys |= KEY_5; + if (state[SDL_SCANCODE_6]) keys |= KEY_6; + if (state[SDL_SCANCODE_7]) keys |= KEY_7; + if (state[SDL_SCANCODE_8]) keys |= KEY_8; + if (state[SDL_SCANCODE_9]) keys |= KEY_9; + if (state[SDLK_ASTERISK]) keys |= KEY_STAR; + if (state[SDL_SCANCODE_ESCAPE]) keys |= KEY_ESC; + if (state[SDL_SCANCODE_DOWN]) keys |= KEY_DOWN; + if (state[SDL_SCANCODE_UP]) keys |= KEY_UP; + if (state[SDL_SCANCODE_RETURN]) keys |= KEY_ENTER; + if (state[SDL_SCANCODE_NONUSHASH]) keys |= KEY_HASH; + if (state[SDL_SCANCODE_MINUS]) keys |= KEY_F1; + if (state[SDLK_PLUS]) keys |= KEY_MONI; + return keys; + } +} +