Skip to content

Commit 95204e4

Browse files
committed
micropython/lora: Improve asynchronous support
This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 9a1b254 commit 95204e4

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

‎micropython/lora/async_modem.py‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
import uasyncio
77

88

9-
def _clear_irqflag(thread_safe_flag): # TODO: implement ThreadSafeFlag.clear() in MP
10-
if thread_safe_flag:
11-
thread_safe_flag._flag = 0
12-
13-
149
class AsyncModem:
1510
def __init__(self, modem):
1611
self._modem = modem
@@ -20,28 +15,28 @@ def __init__(self, modem):
2015
def configure(self, lora_cfg, rx_calibrate=False):
2116
return self._modem.configure(lora_cfg, rx_calibrate)
2217

23-
async def receive(self, timeout_ms=None, rx_continuous=False):
18+
async def receive(self, timeout_ms=None):
2419
# TODO: check for any pending TX
25-
_clear_irqflag(self._flag)
26-
will_cb = self._modem.start_receive(timeout_ms, rx_continuous)
20+
self._flag.clear()
21+
will_cb = self._modem.start_receive(timeout_ms)
2722
if will_cb:
2823
await self._flag.wait()
24+
assert self._modem.is_receive_completed()
2925
else:
3026
while not self._modem.is_receive_completed():
3127
await uasyncio.sleep_ms(0)
32-
assert self._modem.is_receive_completed() # TODO: remove?
33-
return self._modem.end_receive(timeout_ms, rx_continuous)
28+
return self._modem.end_receive(timeout_ms)
3429

3530
async def transmit(self, message):
36-
_clear_irqflag(self._flag)
37-
will_cb, was_rx = self._modem.start_transmit(message)
31+
self._flag.clear()
32+
will_cb = self._modem.start_transmit(message)
3833
if will_cb:
3934
await self._flag.wait()
40-
assert self._modem.is_transmit_completed() # TODO: remove?
35+
assert self._modem.is_transmit_completed()
4136
else:
4237
while not self._modem.is_transmit_completed():
4338
await uasyncio.sleep_ms(0)
44-
self._modem.end_transmit(was_rx)
39+
self._modem.end_transmit()
4540

4641
def _callback(self):
4742
self._flag.set()

0 commit comments

Comments
 (0)