mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-24 07:18:09 +00:00
fix(core): prevent overloading app with touch events
[no changelog]
This commit is contained in:
parent
1be6208a02
commit
b178c10e8b
@ -31,6 +31,7 @@
|
|||||||
#define POLL_WRITE (0x0100)
|
#define POLL_WRITE (0x0100)
|
||||||
|
|
||||||
extern bool usb_connected_previously;
|
extern bool usb_connected_previously;
|
||||||
|
extern uint32_t last_touch_sample_time;
|
||||||
|
|
||||||
/// package: trezorio.__init__
|
/// package: trezorio.__init__
|
||||||
|
|
||||||
@ -84,8 +85,15 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
}
|
}
|
||||||
#if defined USE_TOUCH
|
#if defined USE_TOUCH
|
||||||
else if (iface == TOUCH_IFACE) {
|
else if (iface == TOUCH_IFACE) {
|
||||||
|
|
||||||
const uint32_t evt = touch_read();
|
const uint32_t evt = touch_read();
|
||||||
|
|
||||||
if (evt) {
|
if (evt) {
|
||||||
|
// ignore TOUCH_MOVE events if they are too frequent
|
||||||
|
if ((evt & TOUCH_MOVE) == 0 ||
|
||||||
|
(hal_ticks_ms() - last_touch_sample_time > 10)) {
|
||||||
|
last_touch_sample_time = hal_ticks_ms();
|
||||||
|
|
||||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||||
const uint32_t etype = (evt >> 24) & 0xFFU; // event type
|
const uint32_t etype = (evt >> 24) & 0xFFU; // event type
|
||||||
const uint32_t ex = (evt >> 12) & 0xFFFU; // x position
|
const uint32_t ex = (evt >> 12) & 0xFFFU; // x position
|
||||||
@ -117,6 +125,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
|
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
|
||||||
return mp_const_true;
|
return mp_const_true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (iface == USB_DATA_IFACE) {
|
} else if (iface == USB_DATA_IFACE) {
|
||||||
bool usb_connected = usb_configured() == sectrue ? true : false;
|
bool usb_connected = usb_configured() == sectrue ? true : false;
|
||||||
if (usb_connected != usb_connected_previously) {
|
if (usb_connected != usb_connected_previously) {
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
// Whether USB data pins were connected on last check (USB configured)
|
// Whether USB data pins were connected on last check (USB configured)
|
||||||
bool usb_connected_previously = true;
|
bool usb_connected_previously = true;
|
||||||
|
|
||||||
|
uint32_t last_touch_sample_time = 0;
|
||||||
|
|
||||||
#define CHECK_PARAM_RANGE(value, minimum, maximum) \
|
#define CHECK_PARAM_RANGE(value, minimum, maximum) \
|
||||||
if (value < minimum || value > maximum) { \
|
if (value < minimum || value > maximum) { \
|
||||||
mp_raise_ValueError(#value " is out of range"); \
|
mp_raise_ValueError(#value " is out of range"); \
|
||||||
|
@ -266,7 +266,12 @@ uint32_t touch_read(void) {
|
|||||||
touching = 1;
|
touching = 1;
|
||||||
return TOUCH_START | xy;
|
return TOUCH_START | xy;
|
||||||
} else if ((number_of_touch_points == 1) && (event_flag == EVENT_CONTACT)) {
|
} else if ((number_of_touch_points == 1) && (event_flag == EVENT_CONTACT)) {
|
||||||
|
if (touching) {
|
||||||
return TOUCH_MOVE | xy;
|
return TOUCH_MOVE | xy;
|
||||||
|
} else {
|
||||||
|
touching = 1;
|
||||||
|
return TOUCH_START | xy;
|
||||||
|
}
|
||||||
} else if ((number_of_touch_points == 0) && (event_flag == EVENT_LIFT_UP)) {
|
} else if ((number_of_touch_points == 0) && (event_flag == EVENT_LIFT_UP)) {
|
||||||
touching = 0;
|
touching = 0;
|
||||||
return TOUCH_END | xy;
|
return TOUCH_END | xy;
|
||||||
|
@ -211,7 +211,6 @@ uint32_t touch_read(void) {
|
|||||||
if (ev_type != 0) {
|
if (ev_type != 0) {
|
||||||
_touch_x = ev_x;
|
_touch_x = ev_x;
|
||||||
_touch_y = ev_y;
|
_touch_y = ev_y;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ev_type | touch_pack_xy(ev_x, ev_y);
|
return ev_type | touch_pack_xy(ev_x, ev_y);
|
||||||
|
Loading…
Reference in New Issue
Block a user