From 11190fccba6da73c85049ea14237abfaf52cba8a Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 29 Apr 2016 17:29:46 +0200 Subject: [PATCH] remove extraneous motion events from queue --- extmod/modtrezormsg/modtrezormsg.c | 5 ++++- extmod/modtrezorui/modtrezorui-unix.h | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/extmod/modtrezormsg/modtrezormsg.c b/extmod/modtrezormsg/modtrezormsg.c index 6cd3bfe6..8f42e66a 100644 --- a/extmod/modtrezormsg/modtrezormsg.c +++ b/extmod/modtrezormsg/modtrezormsg.c @@ -55,7 +55,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) { if (to < 0) { to = 0; } - while (to >= 0) { + for(;;) { uint32_t e = msg_poll_ui_event(); if (e) { mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); @@ -71,6 +71,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) { memcpy(vstr.buf, m, 64); return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); } + if (to <= 0) { + break; + } mp_hal_delay_us_fast(TICK_RESOLUTION); to -= TICK_RESOLUTION; } diff --git a/extmod/modtrezorui/modtrezorui-unix.h b/extmod/modtrezorui/modtrezorui-unix.h index 73e6fcae..d1edbdb0 100644 --- a/extmod/modtrezorui/modtrezorui-unix.h +++ b/extmod/modtrezorui/modtrezorui-unix.h @@ -38,6 +38,7 @@ uint32_t trezorui_poll_sdl_event(void) { SDL_Event event; int x, y; + SDL_PumpEvents(); if (SDL_PollEvent(&event) > 0) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: @@ -51,6 +52,8 @@ uint32_t trezorui_poll_sdl_event(void) return (0x00 << 24) | (0x01 << 16) | (x << 8) | y; // touch_start break; case SDL_MOUSEMOTION: + // remove other SDL_MOUSEMOTION events from queue + SDL_FlushEvent(SDL_MOUSEMOTION); if (event.motion.state) { return (0x00 << 24) | (0x02 << 16) | (x << 8) | y; // touch_move } @@ -60,6 +63,11 @@ uint32_t trezorui_poll_sdl_event(void) break; } break; + case SDL_KEYUP: + if (event.key.keysym.sym == SDLK_ESCAPE) { + exit(3); + } + break; case SDL_QUIT: exit(3); break;