Skip to content

Commit 3e64211

Browse files
committed
implment a few size reduction cahnges
1 parent 076915d commit 3e64211

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

adafruit_rfm69.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,9 @@ def __set__(self, obj, val):
253253
crc_auto_clear_off = _RegisterBits(_REG_PACKET_CONFIG1, offset=3, bits=1)
254254
address_filter = _RegisterBits(_REG_PACKET_CONFIG1, offset=1, bits=2)
255255
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)
258256
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)
261257

258+
# pylint: disable=too-many-statements
262259
def __init__(
263260
self,
264261
spi,
@@ -300,8 +297,26 @@ def __init__(
300297
self.preamble_length = preamble_length # Set the preamble length.
301298
self.frequency_mhz = frequency # Set frequency.
302299
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+
305320
# initialize last RSSI reading
306321
self.last_rssi = 0.0
307322
"""The RSSI of the last received packet. Stored when the packet was received.
@@ -353,30 +368,8 @@ def __init__(
353368
Lower 4 bits may be used to pass information.
354369
Fourth byte of the RadioHead header.
355370
"""
371+
# pylint: enable=too-many-statements
356372

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
380373

381374
# pylint: disable=no-member
382375
# Reconsider this disable when it can be tested.
@@ -722,6 +715,14 @@ def frequency_deviation(self, val):
722715
self._write_u8(_REG_FDEV_MSB, fdev >> 8)
723716
self._write_u8(_REG_FDEV_LSB, fdev & 0xFF)
724717

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+
725726
def send(
726727
self,
727728
data,
@@ -781,7 +782,7 @@ def send(
781782
# best that can be done right now without interrupts).
782783
start = time.monotonic()
783784
timed_out = False
784-
while not timed_out and not self.packet_sent:
785+
while not timed_out and not self.packet_sent():
785786
if (time.monotonic() - start) >= self.xmit_timeout:
786787
timed_out = True
787788
# Listen again if requested.
@@ -858,7 +859,7 @@ def receive(
858859
self.listen()
859860
start = time.monotonic()
860861
timed_out = False
861-
while not timed_out and not self.payload_ready:
862+
while not timed_out and not self.payload_ready():
862863
if (time.monotonic() - start) >= timeout:
863864
timed_out = True
864865
# Payload ready is set, a packet is in the FIFO.
@@ -893,10 +894,9 @@ def receive(
893894
# delay before sending Ack to give receiver a chance to get ready
894895
if self.ack_delay is not None:
895896
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'!')
898898
self.send(
899-
data,
899+
b"!",
900900
destination=packet[1],
901901
node=packet[0],
902902
identifier=packet[2],

0 commit comments

Comments
 (0)