@@ -253,12 +253,9 @@ def __set__(self, obj, val):
253
253
crc_auto_clear_off = _RegisterBits (_REG_PACKET_CONFIG1 , offset = 3 , bits = 1 )
254
254
address_filter = _RegisterBits (_REG_PACKET_CONFIG1 , offset = 1 , bits = 2 )
255
255
mode_ready = _RegisterBits (_REG_IRQ_FLAGS1 , offset = 7 )
256
- rx_ready = _RegisterBits (_REG_IRQ_FLAGS1 , offset = 6 )
257
- tx_ready = _RegisterBits (_REG_IRQ_FLAGS1 , offset = 5 )
258
256
dio_0_mapping = _RegisterBits (_REG_DIO_MAPPING1 , offset = 6 , bits = 2 )
259
- packet_sent = _RegisterBits (_REG_IRQ_FLAGS2 , offset = 3 )
260
- payload_ready = _RegisterBits (_REG_IRQ_FLAGS2 , offset = 2 )
261
257
258
+ # pylint: disable=too-many-statements
262
259
def __init__ (
263
260
self ,
264
261
spi ,
@@ -300,8 +297,26 @@ def __init__(
300
297
self .preamble_length = preamble_length # Set the preamble length.
301
298
self .frequency_mhz = frequency # Set frequency.
302
299
self .encryption_key = encryption_key # Set encryption key.
303
- # set radio configuration parameters
304
- self ._configure_radio ()
300
+ # Configure modulation for RadioHead library GFSK_Rb250Fd250 mode
301
+ # by default. Users with advanced knowledge can manually reconfigure
302
+ # for any other mode (consulting the datasheet is absolutely
303
+ # necessary!).
304
+ self .data_mode = 0b00 # Packet mode
305
+ self .modulation_type = 0b00 # FSK modulation
306
+ self .modulation_shaping = 0b01 # Gaussian filter, BT=1.0
307
+ self .bitrate = 250000 # 250kbs
308
+ self .frequency_deviation = 250000 # 250khz
309
+ self .rx_bw_dcc_freq = 0b111 # RxBw register = 0xE0
310
+ self .rx_bw_mantissa = 0b00
311
+ self .rx_bw_exponent = 0b000
312
+ self .afc_bw_dcc_freq = 0b111 # AfcBw register = 0xE0
313
+ self .afc_bw_mantissa = 0b00
314
+ self .afc_bw_exponent = 0b000
315
+ self .packet_format = 1 # Variable length.
316
+ self .dc_free = 0b10 # Whitening
317
+ # Set transmit power to 13 dBm, a safe value any module supports.
318
+ self .tx_power = 13
319
+
305
320
# initialize last RSSI reading
306
321
self .last_rssi = 0.0
307
322
"""The RSSI of the last received packet. Stored when the packet was received.
@@ -353,30 +368,8 @@ def __init__(
353
368
Lower 4 bits may be used to pass information.
354
369
Fourth byte of the RadioHead header.
355
370
"""
371
+ # pylint: enable=too-many-statements
356
372
357
- def _configure_radio (self ):
358
- # Configure modulation for RadioHead library GFSK_Rb250Fd250 mode
359
- # by default. Users with advanced knowledge can manually reconfigure
360
- # for any other mode (consulting the datasheet is absolutely
361
- # necessary!).
362
- self .data_mode = 0b00 # Packet mode
363
- self .modulation_type = 0b00 # FSK modulation
364
- self .modulation_shaping = 0b01 # Gaussian filter, BT=1.0
365
- self .bitrate = 250000 # 250kbs
366
- self .frequency_deviation = 250000 # 250khz
367
- self .rx_bw_dcc_freq = 0b111 # RxBw register = 0xE0
368
- self .rx_bw_mantissa = 0b00
369
- self .rx_bw_exponent = 0b000
370
- self .afc_bw_dcc_freq = 0b111 # AfcBw register = 0xE0
371
- self .afc_bw_mantissa = 0b00
372
- self .afc_bw_exponent = 0b000
373
- self .packet_format = 1 # Variable length.
374
- self .dc_free = 0b10 # Whitening
375
- self .crc_on = 1 # CRC enabled
376
- self .crc_auto_clear = 0 # Clear FIFO on CRC fail
377
- self .address_filtering = 0b00 # No address filtering
378
- # Set transmit power to 13 dBm, a safe value any module supports.
379
- self .tx_power = 13
380
373
381
374
# pylint: disable=no-member
382
375
# Reconsider this disable when it can be tested.
@@ -722,6 +715,14 @@ def frequency_deviation(self, val):
722
715
self ._write_u8 (_REG_FDEV_MSB , fdev >> 8 )
723
716
self ._write_u8 (_REG_FDEV_LSB , fdev & 0xFF )
724
717
718
+ def packet_sent (self ):
719
+ """Transmit status"""
720
+ return (self ._read_u8 (_REG_IRQ_FLAGS2 ) & 0x8 ) >> 3
721
+
722
+ def payload_ready (self ):
723
+ """Receive status"""
724
+ return (self ._read_u8 (_REG_IRQ_FLAGS2 ) & 0x4 ) >> 2
725
+
725
726
def send (
726
727
self ,
727
728
data ,
@@ -781,7 +782,7 @@ def send(
781
782
# best that can be done right now without interrupts).
782
783
start = time .monotonic ()
783
784
timed_out = False
784
- while not timed_out and not self .packet_sent :
785
+ while not timed_out and not self .packet_sent () :
785
786
if (time .monotonic () - start ) >= self .xmit_timeout :
786
787
timed_out = True
787
788
# Listen again if requested.
@@ -858,7 +859,7 @@ def receive(
858
859
self .listen ()
859
860
start = time .monotonic ()
860
861
timed_out = False
861
- while not timed_out and not self .payload_ready :
862
+ while not timed_out and not self .payload_ready () :
862
863
if (time .monotonic () - start ) >= timeout :
863
864
timed_out = True
864
865
# Payload ready is set, a packet is in the FIFO.
@@ -893,10 +894,9 @@ def receive(
893
894
# delay before sending Ack to give receiver a chance to get ready
894
895
if self .ack_delay is not None :
895
896
time .sleep (self .ack_delay )
896
- # send ACK packet to sender
897
- data = bytes ("!" , "UTF-8" )
897
+ # send ACK packet to sender (data is b'!')
898
898
self .send (
899
- data ,
899
+ b"!" ,
900
900
destination = packet [1 ],
901
901
node = packet [0 ],
902
902
identifier = packet [2 ],
0 commit comments