kopia lustrzana https://github.com/OpenRTX/OpenRTX
Don't pump SDL events outside from the main thread
rodzic
057b00f656
commit
51acccaec2
|
@ -38,6 +38,10 @@
|
|||
#include <interfaces/gps.h>
|
||||
#include <gps.h>
|
||||
#endif
|
||||
#ifdef PLATFORM_LINUX
|
||||
#include <emulator.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* Mutex for concurrent access to state variable */
|
||||
pthread_mutex_t state_mutex;
|
||||
|
@ -73,6 +77,10 @@ void *ui_task(void *arg)
|
|||
|
||||
while(1)
|
||||
{
|
||||
#ifdef PLATFORM_LINUX
|
||||
emulator_process_sdl_events();
|
||||
#endif
|
||||
|
||||
// Read from the keyboard queue (returns 0 if no message is present)
|
||||
// Copy keyboard_t keys from received void * pointer msg
|
||||
event_t event;
|
||||
|
|
|
@ -197,7 +197,7 @@ uint32_t fetchPixelFromFb(unsigned int x, unsigned int y)
|
|||
|
||||
void display_init()
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0)
|
||||
{
|
||||
printf("SDL video init error!!\n");
|
||||
|
||||
|
|
|
@ -21,43 +21,21 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <interfaces/keyboard.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
extern keyboard_t shellkeyq_get();
|
||||
extern keyboard_t sdl_getKeys();
|
||||
|
||||
void kbd_init()
|
||||
{
|
||||
}
|
||||
|
||||
keyboard_t kbd_getKeys() {
|
||||
keyboard_t keys = 0;
|
||||
SDL_PumpEvents();
|
||||
|
||||
//this pulls in emulated keypresses from the command shell
|
||||
keys |= shellkeyq_get();
|
||||
keys |= sdl_getKeys();
|
||||
|
||||
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_LEFT]) keys |= KEY_LEFT;
|
||||
if (state[SDL_SCANCODE_RIGHT]) keys |= KEY_RIGHT;
|
||||
if (state[SDL_SCANCODE_RETURN]) keys |= KEY_ENTER;
|
||||
if (state[SDL_SCANCODE_NONUSHASH]) keys |= KEY_HASH;
|
||||
if (state[SDL_SCANCODE_N]) keys |= KEY_F1;
|
||||
if (state[SDL_SCANCODE_M]) keys |= KEY_MONI;
|
||||
if (state[SDL_SCANCODE_PAGEUP]) keys |= KNOB_LEFT;
|
||||
if (state[SDL_SCANCODE_PAGEDOWN]) keys |= KNOB_RIGHT;
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <readline/history.h>
|
||||
|
||||
|
||||
radio_state Radio_State = {12, 8.2f, 3, 4, 1, false};
|
||||
radio_state Radio_State = {12, 8.2f, 3, 4, 1, false, false};
|
||||
|
||||
extern int screenshot_display(const char *filename);
|
||||
|
||||
|
@ -525,7 +525,7 @@ void *startCLIMenu()
|
|||
while(ret == SH_CONTINUE);
|
||||
fflush(stdout);
|
||||
write_history(histfile);
|
||||
exit(0);
|
||||
Radio_State.PowerOff = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -539,3 +539,105 @@ void emulator_start()
|
|||
printf("An error occurred starting the emulator thread: %d\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
keyboard_t sdl_keys;
|
||||
keyboard_t sdl_getKeys() { return sdl_keys; }
|
||||
|
||||
bool sdk_key_code_to_key(SDL_KeyCode sym, keyboard_t *key)
|
||||
{
|
||||
switch (sym) {
|
||||
case SDLK_0:
|
||||
*key = KEY_0;
|
||||
return true;
|
||||
case SDLK_1:
|
||||
*key = KEY_1;
|
||||
return true;
|
||||
case SDLK_2:
|
||||
*key = KEY_2;
|
||||
return true;
|
||||
case SDLK_3:
|
||||
*key = KEY_3;
|
||||
return true;
|
||||
case SDLK_4:
|
||||
*key = KEY_4;
|
||||
return true;
|
||||
case SDLK_5:
|
||||
*key = KEY_5;
|
||||
return true;
|
||||
case SDLK_6:
|
||||
*key = KEY_6;
|
||||
return true;
|
||||
case SDLK_7:
|
||||
*key = KEY_7;
|
||||
return true;
|
||||
case SDLK_8:
|
||||
*key = KEY_8;
|
||||
return true;
|
||||
case SDLK_9:
|
||||
*key = KEY_9;
|
||||
return true;
|
||||
case SDLK_ASTERISK:
|
||||
*key = KEY_STAR;
|
||||
return true;
|
||||
case SDLK_ESCAPE:
|
||||
*key = KEY_ESC;
|
||||
return true;
|
||||
case SDLK_LEFT:
|
||||
*key = KEY_LEFT;
|
||||
return true;
|
||||
case SDLK_RIGHT:
|
||||
*key = KEY_RIGHT;
|
||||
return true;
|
||||
case SDLK_RETURN:
|
||||
*key = KEY_ENTER;
|
||||
return true;
|
||||
case SDLK_HASH:
|
||||
*key = KEY_HASH;
|
||||
return true;
|
||||
case SDLK_n:
|
||||
*key = KEY_F1;
|
||||
return true;
|
||||
case SDLK_m:
|
||||
*key = KEY_MONI;
|
||||
return true;
|
||||
case SDLK_PAGEUP:
|
||||
*key = KNOB_LEFT;
|
||||
return true;
|
||||
case SDLK_PAGEDOWN:
|
||||
*key = KNOB_RIGHT;
|
||||
return true;
|
||||
case SDLK_UP:
|
||||
*key = KEY_UP;
|
||||
return true;
|
||||
case SDLK_DOWN:
|
||||
*key = KEY_DOWN;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void emulator_process_sdl_events()
|
||||
{
|
||||
Uint32 now = SDL_GetTicks();
|
||||
|
||||
SDL_Event ev = { 0 };
|
||||
keyboard_t key = 0;
|
||||
|
||||
SDL_PollEvent( &ev);
|
||||
|
||||
switch (ev.type) {
|
||||
case SDL_QUIT:
|
||||
Radio_State.PowerOff = true;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (sdk_key_code_to_key(ev.key.keysym.sym, &key))
|
||||
sdl_keys |= key;
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
if (sdk_key_code_to_key(ev.key.keysym.sym, &key))
|
||||
sdl_keys ^= key;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,10 +52,12 @@ typedef struct
|
|||
float volumeLevel;
|
||||
float chSelector;
|
||||
bool PttStatus;
|
||||
bool PowerOff;
|
||||
} radio_state;
|
||||
|
||||
extern radio_state Radio_State;
|
||||
|
||||
void emulator_start();
|
||||
void emulator_process_sdl_events();
|
||||
|
||||
#endif /* EMULATOR_H */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
***************************************************************************/
|
||||
|
||||
#include <interfaces/platform.h>
|
||||
#include <interfaces/graphics.h>
|
||||
#include <interfaces/gpio.h>
|
||||
#include <stdio.h>
|
||||
#include "emulator.h"
|
||||
|
@ -43,6 +44,9 @@ void platform_init()
|
|||
void platform_terminate()
|
||||
{
|
||||
printf("Platform terminate\n");
|
||||
gfx_terminate();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void platform_setBacklightLevel(__attribute__((unused)) uint8_t level)
|
||||
|
@ -89,7 +93,6 @@ int8_t platform_getChSelector()
|
|||
bool platform_getPttStatus()
|
||||
{
|
||||
// Read P key status from SDL
|
||||
SDL_PumpEvents();
|
||||
const uint8_t *state = SDL_GetKeyboardState(NULL);
|
||||
if (state[SDL_SCANCODE_P])
|
||||
return true;
|
||||
|
@ -100,7 +103,7 @@ bool platform_getPttStatus()
|
|||
bool platform_pwrButtonStatus()
|
||||
{
|
||||
/* Suppose radio is always on */
|
||||
return true;
|
||||
return !Radio_State.PowerOff;
|
||||
}
|
||||
|
||||
void platform_ledOn(__attribute__((unused)) led_t led)
|
||||
|
|
Ładowanie…
Reference in New Issue