1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

singlethread handling of sdl events

This commit is contained in:
Pavol Rusnak 2016-04-28 21:43:22 +02:00
parent 767a41cffd
commit d7a937f553
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 18 additions and 14 deletions

View File

@ -11,25 +11,23 @@ mp_obj_t touch_start_callback = mp_const_none;
mp_obj_t touch_move_callback = mp_const_none;
mp_obj_t touch_end_callback = mp_const_none;
/*
static void touch_start(mp_int_t x, mp_int_t y) {
void touch_start(mp_int_t x, mp_int_t y) {
if (touch_start_callback != mp_const_none) {
mp_call_function_2(touch_start_callback, MP_OBJ_NEW_SMALL_INT(x), MP_OBJ_NEW_SMALL_INT(y));
}
}
static void touch_move(mp_int_t x, mp_int_t y) {
void touch_move(mp_int_t x, mp_int_t y) {
if (touch_move_callback != mp_const_none) {
mp_call_function_2(touch_move_callback, MP_OBJ_NEW_SMALL_INT(x), MP_OBJ_NEW_SMALL_INT(y));
}
}
static void touch_end(mp_int_t x, mp_int_t y) {
void touch_end(mp_int_t x, mp_int_t y) {
if (touch_end_callback != mp_const_none) {
mp_call_function_2(touch_end_callback, MP_OBJ_NEW_SMALL_INT(x), MP_OBJ_NEW_SMALL_INT(y));
}
}
*/
// class Touch(object):
typedef struct _mp_obj_Touch_t {

View File

@ -6,11 +6,11 @@
*/
#include <SDL2/SDL.h>
#include <stdlib.h>
static SDL_Renderer *RENDERER = 0;
static SDL_Surface *SCREEN = 0;
static SDL_Texture *TEXTURE = 0;
static SDL_Thread *THREAD = 0;
static int DATAODD = 0;
static int POSX, POSY, SX, SY, EX, EY = 0;
static int ROTATION = 0;
@ -34,11 +34,15 @@ static void DATAfunc(uint8_t x) {
}
}
static int HandleEvents(void *ptr)
void touch_start(mp_int_t x, mp_int_t y);
void touch_move(mp_int_t x, mp_int_t y);
void touch_end(mp_int_t x, mp_int_t y);
void upy_idle_func(void)
{
SDL_Event event;
int x, y;
while (SDL_WaitEvent(&event) >= 0) {
while (SDL_PollEvent(&event) > 0) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
@ -48,21 +52,24 @@ static int HandleEvents(void *ptr)
if (x < 0 || y < 0 || x >= RESX || y >= RESY) continue;
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
// touch_start(x, y);
touch_start(x, y);
break;
case SDL_MOUSEMOTION:
if (event.motion.state) {
// touch_move(x, y);
touch_move(x, y);
}
break;
case SDL_MOUSEBUTTONUP:
// touch_end(x, y);
touch_end(x, y);
break;
}
break;
case SDL_QUIT:
exit(3);
break;
}
}
return 0;
return;
}
static void display_init(void)
@ -84,7 +91,6 @@ static void display_init(void)
SDL_RenderClear(RENDERER);
SCREEN = SDL_CreateRGBSurface(0, RESX, RESY, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
TEXTURE = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, RESX, RESY);
THREAD = SDL_CreateThread(HandleEvents, "EventThread", NULL);
}
static void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {

2
vendor/micropython vendored

@ -1 +1 @@
Subproject commit 4e2fda01bf6612823057886c98284ada320c8b22
Subproject commit 57b4be8a5c73dda20746d53a66a98c4b64498be4