diff --git a/.readthedocs.yaml b/.readthedocs.yaml index fcb7778..3cd488c 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 build: - os: ubuntu-latest + os: ubuntu-lts-latest tools: python: "3" diff --git a/adafruit_rfm/rfm69.py b/adafruit_rfm/rfm69.py index 4ff3c54..7adb0b1 100644 --- a/adafruit_rfm/rfm69.py +++ b/adafruit_rfm/rfm69.py @@ -639,10 +639,11 @@ def fill_fifo(self, payload: ReadableBuffer) -> None: # Write payload to transmit fifo self.write_from(_RF69_REG_00_FIFO, complete_payload) - def read_fifo(self) -> bytearray: + def read_fifo(self) -> Optional[bytearray]: """Read the packet from the FIFO.""" # Read the length of the FIFO. fifo_length = self.read_u8(_RF69_REG_00_FIFO) + packet = None # return None if FIFO empty if fifo_length > 0: # read and clear the FIFO if anything in it packet = bytearray(fifo_length) # read the packet diff --git a/adafruit_rfm/rfm9x.py b/adafruit_rfm/rfm9x.py index d89000a..2848292 100644 --- a/adafruit_rfm/rfm9x.py +++ b/adafruit_rfm/rfm9x.py @@ -23,7 +23,7 @@ from circuitpython_typing import ReadableBuffer try: - from typing import Literal + from typing import Literal, Optional except ImportError: from typing_extensions import Literal @@ -131,7 +131,7 @@ class RFM9x(RFMSPI): - preamble_length: The length in bytes of the packet preamble (default 8). - high_power: Boolean to indicate a high power board (RFM95, etc.). Default is True for high power. - - baudrate: Baud rate of the SPI connection, default is 10mhz but you might + - baudrate: Baud rate of the SPI connection, default is 5mhz but you might choose to lower to 1mhz if using long wires or a breadboard. - agc: Boolean to Enable/Disable Automatic Gain Control - Default=False (AGC off) - crc: Boolean to Enable/Disable Cyclic Redundancy Check - Default=True (CRC Enabled) @@ -517,10 +517,11 @@ def fill_fifo(self, payload: ReadableBuffer) -> None: # Write payload and header length. self.write_u8(_RF95_REG_22_PAYLOAD_LENGTH, len(payload)) - def read_fifo(self) -> bytearray: + def read_fifo(self) -> Optional[bytearray]: """Read the data from the FIFO.""" # Read the length of the FIFO. fifo_length = self.read_u8(_RF95_REG_13_RX_NB_BYTES) + packet = None # return None if FIFO empty if fifo_length > 0: # read and clear the FIFO if anything in it packet = bytearray(fifo_length) current_addr = self.read_u8(_RF95_REG_10_FIFO_RX_CURRENT_ADDR) diff --git a/adafruit_rfm/rfm9xfsk.py b/adafruit_rfm/rfm9xfsk.py index 4394cde..d10a45b 100644 --- a/adafruit_rfm/rfm9xfsk.py +++ b/adafruit_rfm/rfm9xfsk.py @@ -563,10 +563,11 @@ def fill_fifo(self, payload: ReadableBuffer) -> None: # Write payload to transmit fifo self.write_from(_RF95_REG_00_FIFO, complete_payload) - def read_fifo(self) -> bytearray: + def read_fifo(self) -> Optional[bytearray]: """Read the data from the FIFO.""" # Read the length of the FIFO. fifo_length = self.read_u8(_RF95_REG_00_FIFO) + packet = None # return None if FIFO empty if fifo_length > 0: # read and clear the FIFO if anything in it packet = bytearray(fifo_length) # read the packet diff --git a/adafruit_rfm/rfm_common.py b/adafruit_rfm/rfm_common.py index ed5a55a..3f211f9 100644 --- a/adafruit_rfm/rfm_common.py +++ b/adafruit_rfm/rfm_common.py @@ -430,7 +430,7 @@ async def asyncio_receive( # noqa: PLR0912 self.crc_error_count += 1 else: packet = self.read_fifo() - if self.radiohead: + if (packet is not None) and self.radiohead: if len(packet) < 5: # reject the packet if it is too small to contain the RAdioHead Header packet = None @@ -503,7 +503,7 @@ async def asyncio_receive_with_ack( # noqa: PLR0912 self.crc_error_count += 1 else: packet = self.read_fifo() - if self.radiohead: + if (packet is not None) and self.radiohead: if len(packet) < 5: # reject the packet if it is too small to contain the RAdioHead Header packet = None