Skip to content

Commit 36f54f1

Browse files
committed
throw error on transmit timeout - fix typos - use timeout insteat of timeout_s
1 parent fa35c30 commit 36f54f1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

adafruit_rfm9x.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ def tx_power(self):
499499
power devices. Only integer power levels are actually set (i.e. 12.5
500500
will result in a value of 12 dBm).
501501
The actual maximum setting for high_power=True is 20dBm but for values > 20
502-
the PA_BOOST will be enabled resultiung in ad additonla gain of 3dBm.
503-
Theactual setting is reduced by 3dBm.
502+
the PA_BOOST will be enabled resultiung in an additonal gain of 3dBm.
503+
The actual setting is reduced by 3dBm.
504504
The reported value will reflect the reduced setting.
505505
"""
506506
if self.high_power:
@@ -534,7 +534,7 @@ def rssi(self):
534534
# Remember in LoRa mode the payload register changes function to RSSI!
535535
return self._read_u8(_RH_RF95_REG_1A_PKT_RSSI_VALUE) - 137
536536

537-
def send(self, data, timeout_s=2.):
537+
def send(self, data, timeout=2.):
538538
"""Send a string of data using the transmitter. You can only send 252
539539
bytes at a time (limited by chip's FIFO size and appended headers). Note
540540
this appends a 4 byte header to be compatible with the RadioHead library.
@@ -566,14 +566,16 @@ def send(self, data, timeout_s=2.):
566566
start = time.monotonic()
567567
timed_out = False
568568
while not timed_out and not self.tx_done:
569-
if (time.monotonic() - start) >= timeout_s:
569+
if (time.monotonic() - start) >= timeout:
570570
timed_out = True
571571
# Go back to idle mode after transmit.
572572
self.idle()
573573
# Clear interrupts.
574574
self._write_u8(_RH_RF95_REG_12_IRQ_FLAGS, 0xFF)
575+
if timed_out:
576+
raise RuntimeError('Timeout during packet send')
575577

576-
def receive(self, timeout_s=0.5, keep_listening=True):
578+
def receive(self, timeout=0.5, keep_listening=True):
577579
"""Wait to receive a packet from the receiver. Will wait for up to
578580
timeout_s amount of seconds for a packet to be received and decoded. If
579581
a packet is found the payload bytes are returned, otherwise None is
@@ -593,7 +595,7 @@ def receive(self, timeout_s=0.5, keep_listening=True):
593595
start = time.monotonic()
594596
timed_out = False
595597
while not timed_out and not self.rx_done:
596-
if (time.monotonic() - start) >= timeout_s:
598+
if (time.monotonic() - start) >= timeout:
597599
timed_out = True
598600
# Payload ready is set, a packet is in the FIFO.
599601
packet = None

examples/rfm9x_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
while True:
4848
packet = rfm9x.receive()
4949
# Optionally change the receive timeout from its default of 0.5 seconds:
50-
#packet = rfm9x.receive(timeout_s=5.0)
50+
#packet = rfm9x.receive(timeout=5.0)
5151
# If no packet was received during the timeout then None is returned.
5252
if packet is None:
5353
print('Received nothing! Listening again...')

0 commit comments

Comments
 (0)