1111RF_CH = const (0x05 )
1212RF_SETUP = const (0x06 )
1313STATUS = const (0x07 )
14- OBSERVE_TX = const (0x08 )
1514RX_ADDR_P0 = const (0x0a )
1615TX_ADDR = const (0x10 )
1716RX_PW_P0 = const (0x11 )
@@ -73,7 +72,7 @@ def __init__(self, spi, cs, ce, channel=46, payload_size=16):
7372 # set address width to 5 bytes and check for device present
7473 self .reg_write (SETUP_AW , 0b11 )
7574 if self .reg_read (SETUP_AW ) != 0b11 :
76- raise OSError ("nRF24l01 + Hardware not responding" )
75+ raise OSError ("nRF24L01 + Hardware not responding" )
7776
7877 # disable dynamic payloads
7978 self .reg_write (DYNPD , 0 )
@@ -195,26 +194,21 @@ def recv(self):
195194
196195 return buf
197196
198- # blocking wait for tx complete
197+ # blocking wait for tx complete
199198 def send (self , buf , timeout = 500 ):
200- send_nonblock = self .send_nonblocking (buf )
199+ send_nonblock = self .send_start (buf )
201200 start = pyb .millis ()
202201 result = None
203- while result is None and ( pyb .elapsed_millis (start ) < timeout ) :
204- result = next ( send_nonblock ) # 1 == success 2 == fail
202+ while result is None and pyb .elapsed_millis (start ) < timeout :
203+ result = self . send_done ( ) # 1 == success, 2 == fail
205204 if result == 2 :
206205 raise OSError ("send failed" )
207206
208- def send_nonblocking (self , buf ):
209- '''
210- Support for nonblocking transmission. Returns a generator instance.
211- First use sends the data and returns None. Subsequently tests TX status
212- returning not ready None, ready 1, error 2.
213- '''
207+ # non-blocking tx
208+ def send_start (self , buf ):
214209 # power up
215210 self .reg_write (CONFIG , (self .reg_read (CONFIG ) | PWR_UP ) & ~ PRIM_RX )
216211 pyb .udelay (150 )
217-
218212 # send the data
219213 self .cs .low ()
220214 self .spi .send (W_TX_PAYLOAD )
@@ -227,12 +221,13 @@ def send_nonblocking(self, buf):
227221 self .ce .high ()
228222 pyb .udelay (15 ) # needs to be >10us
229223 self .ce .low ()
230- yield None # Not ready
231224
232- while not (self .reg_read (STATUS ) & (TX_DS | MAX_RT )):
233- yield None # Not ready
234- # Either ready or failed: get and clear status flags, power down
225+ # returns None if send still in progress, 1 for success, 2 for fail
226+ def send_done (self ):
227+ if not (self .reg_read (STATUS ) & (TX_DS | MAX_RT )):
228+ return None # tx not finished
229+
230+ # either finished or failed: get and clear status flags, power down
235231 status = self .reg_write (STATUS , RX_DR | TX_DS | MAX_RT )
236232 self .reg_write (CONFIG , self .reg_read (CONFIG ) & ~ PWR_UP )
237- yield 1 if status & TX_DS else 2
238-
233+ return 1 if status & TX_DS else 2
0 commit comments