1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 11:28:14 +00:00

send touch events on iface in modtrezormsg

This commit is contained in:
Jan Pochyla 2016-05-30 16:29:06 +02:00 committed by Pavol Rusnak
parent 421f17bfee
commit b6caad6b9b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 11 additions and 10 deletions

View File

@ -42,7 +42,7 @@ ssize_t msg_recv(uint8_t *iface, uint8_t *buf, size_t len)
socklen_t sl = sizeof(si); socklen_t sl = sizeof(si);
memset(buf, 0, len); memset(buf, 0, len);
iface = 0; // UDP uses always interface 0 iface = 0; // UDP uses always interface 0
size_t r = recvfrom(s, buf, len, MSG_DONTWAIT, (struct sockaddr *)&si, &sl); ssize_t r = recvfrom(s, buf, len, MSG_DONTWAIT, (struct sockaddr *)&si, &sl);
if (r < 0) { if (r < 0) {
return r; return r;
} }

View File

@ -61,7 +61,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_setup(mp_obj_t self, mp_obj_t ifaces) {
assert(attr_cnt == 2); assert(attr_cnt == 2);
uint8_t ep = mp_obj_get_int(attr[0]); uint8_t ep = mp_obj_get_int(attr[0]);
uint16_t up = mp_obj_get_int(attr[1]); uint16_t up = mp_obj_get_int(attr[1]);
printf("iface %d: ep=%d up=%04x\n", i, ep, up); printf("iface %lu: ep=%d up=%04x\n", i, ep, up);
} }
return mp_const_none; return mp_const_none;
} }
@ -81,6 +81,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t iface, mp_obj_t m
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_send); STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_send);
#define TICK_RESOLUTION 1000 #define TICK_RESOLUTION 1000
#define TOUCH_IFACE 256
/// def trezor.msg.select(timeout_us: int) -> tuple /// def trezor.msg.select(timeout_us: int) -> tuple
/// ///
@ -95,10 +96,11 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
for(;;) { for(;;) {
uint32_t e = msg_poll_ui_event(); uint32_t e = msg_poll_ui_event();
if (e) { if (e) {
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(4, NULL));
tuple->items[0] = MP_OBJ_NEW_SMALL_INT((e & 0xFF0000) >> 16); tuple->items[0] = MP_OBJ_NEW_SMALL_INT(TOUCH_IFACE);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT((e & 0xFF00) >> 8); tuple->items[1] = MP_OBJ_NEW_SMALL_INT((e & 0xFF0000) >> 16); // event type
tuple->items[2] = MP_OBJ_NEW_SMALL_INT((e & 0xFF)); tuple->items[2] = MP_OBJ_NEW_SMALL_INT((e & 0xFF00) >> 8); // x position
tuple->items[3] = MP_OBJ_NEW_SMALL_INT((e & 0xFF)); // y position
return MP_OBJ_FROM_PTR(tuple); return MP_OBJ_FROM_PTR(tuple);
} }
uint8_t iface; uint8_t iface;
@ -108,10 +110,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
vstr_t vstr; vstr_t vstr;
vstr_init_len(&vstr, l); vstr_init_len(&vstr, l);
memcpy(vstr.buf, recvbuf, l); memcpy(vstr.buf, recvbuf, l);
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(2, NULL));
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(8); tuple->items[0] = MP_OBJ_NEW_SMALL_INT(iface);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(iface); tuple->items[1] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
tuple->items[2] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
return MP_OBJ_FROM_PTR(tuple); return MP_OBJ_FROM_PTR(tuple);
} }
if (timeout <= 0) { if (timeout <= 0) {