Skip to content

Commit 602e98b

Browse files
committed
still trying to reduce
1 parent 3a25327 commit 602e98b

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

adafruit_rfm9x.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,6 @@ def __set__(self, obj, val):
352352

353353
dio0_mapping = _RegisterBits(_RH_RF95_REG_40_DIO_MAPPING1, offset=6, bits=2)
354354

355-
tx_done = _RegisterBits(_RH_RF95_REG_12_IRQ_FLAGS, offset=3, bits=1)
356-
357-
rx_done = _RegisterBits(_RH_RF95_REG_12_IRQ_FLAGS, offset=6, bits=1)
358-
359355
crc_error = _RegisterBits(_RH_RF95_REG_12_IRQ_FLAGS, offset=5, bits=1)
360356

361357
bw_bins = (7800, 10400, 15600, 20800, 31250, 41700, 62500, 125000, 250000)
@@ -409,8 +405,16 @@ def __init__(
409405
self.frequency_mhz = frequency
410406
# Set preamble length (default 8 bytes to match radiohead).
411407
self.preamble_length = preamble_length
412-
# set radio configuration parameters
413-
self._configure_radio()
408+
# Defaults set modem config to RadioHead compatible Bw125Cr45Sf128 mode.
409+
self.signal_bandwidth = 125000
410+
self.coding_rate = 5
411+
self.spreading_factor = 7
412+
# Default to disable CRC checking on incoming packets.
413+
self.enable_crc = False
414+
# Note no sync word is set for LoRa mode either!
415+
self._write_u8(_RH_RF95_REG_26_MODEM_CONFIG3, 0x00) # Preamble lsb?
416+
# Set transmit power to 13 dBm, a safe value any module supports.
417+
self.tx_power = 13
414418
# initialize last RSSI reading
415419
self.last_rssi = 0.0
416420
"""The RSSI of the last received packet. Stored when the packet was received.
@@ -463,17 +467,6 @@ def __init__(
463467
Fourth byte of the RadioHead header.
464468
"""
465469
self.crc_error_count = 0
466-
def _configure_radio(self):
467-
# Defaults set modem config to RadioHead compatible Bw125Cr45Sf128 mode.
468-
self.signal_bandwidth = 125000
469-
self.coding_rate = 5
470-
self.spreading_factor = 7
471-
# Default to disable CRC checking on incoming packets.
472-
self.enable_crc = False
473-
# Note no sync word is set for LoRa mode either!
474-
self._write_u8(_RH_RF95_REG_26_MODEM_CONFIG3, 0x00) # Preamble lsb?
475-
# Set transmit power to 13 dBm, a safe value any module supports.
476-
self.tx_power = 13
477470

478471
# pylint: disable=no-member
479472
# Reconsider pylint: disable when this can be tested
@@ -721,6 +714,15 @@ def enable_crc(self, val):
721714
self._read_u8(_RH_RF95_REG_1E_MODEM_CONFIG2) & 0xFB,
722715
)
723716

717+
def tx_done(self):
718+
"""Transmit status"""
719+
return (self._read_u8(_RH_RF95_REG_12_IRQ_FLAGS) & 0x4) >> 3
720+
721+
def rx_done(self):
722+
"""Receive status"""
723+
return (self._read_u8(_RH_RF95_REG_12_IRQ_FLAGS) & 0x40) >> 6
724+
725+
724726
def send(
725727
self,
726728
data,
@@ -783,7 +785,7 @@ def send(
783785
# best that can be done right now without interrupts).
784786
start = time.monotonic()
785787
timed_out = False
786-
while not timed_out and not self.tx_done:
788+
while not timed_out and not self.tx_done():
787789
if (time.monotonic() - start) >= self.xmit_timeout:
788790
timed_out = True
789791
# Listen again if necessary and return the result packet.
@@ -864,7 +866,7 @@ def receive(
864866
self.listen()
865867
start = time.monotonic()
866868
timed_out = False
867-
while not timed_out and not self.rx_done:
869+
while not timed_out and not self.rx_done():
868870
if (time.monotonic() - start) >= timeout:
869871
timed_out = True
870872
# Payload ready is set, a packet is in the FIFO.

0 commit comments

Comments
 (0)