Skip to content

Commit 903e665

Browse files
authored
Merge pull request #6 from jerryneedell/jerryn_read_fifo
fix read_fifo to always define packet before return, Correct typo in dosctring
2 parents 6fcfd14 + 87fe934 commit 903e665

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

adafruit_rfm/rfm69.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,11 @@ def fill_fifo(self, payload: ReadableBuffer) -> None:
639639
# Write payload to transmit fifo
640640
self.write_from(_RF69_REG_00_FIFO, complete_payload)
641641

642-
def read_fifo(self) -> bytearray:
642+
def read_fifo(self) -> Optional[bytearray]:
643643
"""Read the packet from the FIFO."""
644644
# Read the length of the FIFO.
645645
fifo_length = self.read_u8(_RF69_REG_00_FIFO)
646+
packet = None # return None if FIFO empty
646647
if fifo_length > 0: # read and clear the FIFO if anything in it
647648
packet = bytearray(fifo_length)
648649
# read the packet

adafruit_rfm/rfm9x.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from circuitpython_typing import ReadableBuffer
2424

2525
try:
26-
from typing import Literal
26+
from typing import Literal, Optional
2727
except ImportError:
2828
from typing_extensions import Literal
2929

@@ -131,7 +131,7 @@ class RFM9x(RFMSPI):
131131
- preamble_length: The length in bytes of the packet preamble (default 8).
132132
- high_power: Boolean to indicate a high power board (RFM95, etc.). Default
133133
is True for high power.
134-
- baudrate: Baud rate of the SPI connection, default is 10mhz but you might
134+
- baudrate: Baud rate of the SPI connection, default is 5mhz but you might
135135
choose to lower to 1mhz if using long wires or a breadboard.
136136
- agc: Boolean to Enable/Disable Automatic Gain Control - Default=False (AGC off)
137137
- crc: Boolean to Enable/Disable Cyclic Redundancy Check - Default=True (CRC Enabled)
@@ -517,10 +517,11 @@ def fill_fifo(self, payload: ReadableBuffer) -> None:
517517
# Write payload and header length.
518518
self.write_u8(_RF95_REG_22_PAYLOAD_LENGTH, len(payload))
519519

520-
def read_fifo(self) -> bytearray:
520+
def read_fifo(self) -> Optional[bytearray]:
521521
"""Read the data from the FIFO."""
522522
# Read the length of the FIFO.
523523
fifo_length = self.read_u8(_RF95_REG_13_RX_NB_BYTES)
524+
packet = None # return None if FIFO empty
524525
if fifo_length > 0: # read and clear the FIFO if anything in it
525526
packet = bytearray(fifo_length)
526527
current_addr = self.read_u8(_RF95_REG_10_FIFO_RX_CURRENT_ADDR)

adafruit_rfm/rfm9xfsk.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,11 @@ def fill_fifo(self, payload: ReadableBuffer) -> None:
563563
# Write payload to transmit fifo
564564
self.write_from(_RF95_REG_00_FIFO, complete_payload)
565565

566-
def read_fifo(self) -> bytearray:
566+
def read_fifo(self) -> Optional[bytearray]:
567567
"""Read the data from the FIFO."""
568568
# Read the length of the FIFO.
569569
fifo_length = self.read_u8(_RF95_REG_00_FIFO)
570+
packet = None # return None if FIFO empty
570571
if fifo_length > 0: # read and clear the FIFO if anything in it
571572
packet = bytearray(fifo_length)
572573
# read the packet

adafruit_rfm/rfm_common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ async def asyncio_receive( # noqa: PLR0912
430430
self.crc_error_count += 1
431431
else:
432432
packet = self.read_fifo()
433-
if self.radiohead:
433+
if (packet is not None) and self.radiohead:
434434
if len(packet) < 5:
435435
# reject the packet if it is too small to contain the RAdioHead Header
436436
packet = None
@@ -503,7 +503,7 @@ async def asyncio_receive_with_ack( # noqa: PLR0912
503503
self.crc_error_count += 1
504504
else:
505505
packet = self.read_fifo()
506-
if self.radiohead:
506+
if (packet is not None) and self.radiohead:
507507
if len(packet) < 5:
508508
# reject the packet if it is too small to contain the RAdioHead Header
509509
packet = None

0 commit comments

Comments
 (0)