mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-21 23:18:13 +00:00
replace wait with msg.select
This commit is contained in:
parent
fa52ecfb79
commit
1664a4fc29
@ -47,10 +47,15 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t message) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_send);
|
||||
|
||||
// def Msg.select(self, timeout_ms: int) -> None/tuple/bytes
|
||||
STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_ms) {
|
||||
int to = mp_obj_get_int(timeout_ms);
|
||||
while (--to >= 0) {
|
||||
#define TICK_RESOLUTION 1000
|
||||
|
||||
// def Msg.select(self, timeout_us: int) -> None/tuple/bytes
|
||||
STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
|
||||
int to = mp_obj_get_int(timeout_us);
|
||||
if (to < 0) {
|
||||
to = 0;
|
||||
}
|
||||
while (to >= 0) {
|
||||
uint32_t e = msg_poll_ui_event();
|
||||
if (e) {
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||
@ -66,7 +71,8 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_ms) {
|
||||
memcpy(vstr.buf, m, 64);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
mp_hal_delay_ms(1);
|
||||
mp_hal_delay_us_fast(TICK_RESOLUTION);
|
||||
to -= TICK_RESOLUTION;
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
9
send_udp.py
Executable file
9
send_udp.py
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/python
|
||||
import socket
|
||||
|
||||
UDP_IP = '127.0.0.1'
|
||||
UDP_PORT = 21324
|
||||
MESSAGE = b'Hello, World!'
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
|
@ -2,6 +2,7 @@ import utime
|
||||
import uheapq
|
||||
|
||||
from .utils import type_gen
|
||||
from . import msg
|
||||
|
||||
if __debug__:
|
||||
import logging
|
||||
@ -34,7 +35,10 @@ def wait(delay):
|
||||
log.debug("Sleeping for: %s", delay)
|
||||
|
||||
last_sleep = delay
|
||||
utime.sleep_us(delay)
|
||||
m = msg.select(delay)
|
||||
if m:
|
||||
print('msg:', m)
|
||||
return m
|
||||
|
||||
def run_forever():
|
||||
global q, cnt
|
||||
@ -47,11 +51,12 @@ def run_forever():
|
||||
tnow = utime.ticks_us()
|
||||
delay = t - tnow
|
||||
if delay > 0:
|
||||
wait(delay)
|
||||
m = wait(delay)
|
||||
else:
|
||||
wait(-1)
|
||||
m = wait(0)
|
||||
# Assuming IO completion scheduled some tasks
|
||||
continue
|
||||
|
||||
if callable(cb):
|
||||
ret = cb(*args)
|
||||
if __debug__ and isinstance(ret, type_gen):
|
||||
|
@ -2,8 +2,8 @@ from TrezorMsg import Msg
|
||||
|
||||
_msg = Msg()
|
||||
|
||||
def select(timeout_ms):
|
||||
return _msg.select(timeout_ms)
|
||||
def select(timeout_us):
|
||||
return _msg.select(timeout_us)
|
||||
|
||||
def send(msg):
|
||||
return _msg.send(msg)
|
||||
|
2
vendor/micropython
vendored
2
vendor/micropython
vendored
@ -1 +1 @@
|
||||
Subproject commit da3fe60b7dc12ce393e9a63c9d6ac366b9c81045
|
||||
Subproject commit c4e00834d394bf07e3c347494648c7fe73fee50b
|
Loading…
Reference in New Issue
Block a user