Add keyboard implementation for linux

replace/e9a4f02fe35ac925cc878535078834518afd5f33
Fred 2020-10-30 22:58:15 +01:00 zatwierdzone przez Niccolò Izzo
rodzic ce0e901d78
commit 3d1f255d46
2 zmienionych plików z 57 dodań i 0 usunięć

Wyświetl plik

@ -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',

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include "keyboard.h"
#include <SDL2/SDL.h>
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;
}
}