Merge pull request #6 from jerryneedell/jerryn_read_fifo

fix read_fifo to always define packet before return, Correct typo in dosctring
This commit is contained in:
foamyguy 2024-12-13 09:09:16 -06:00 committed by GitHub
commit 903e66538a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 7 deletions

View file

@ -639,10 +639,11 @@ class RFM69(RFMSPI):
# 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

View file

@ -23,7 +23,7 @@ try:
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 @@ class RFM9x(RFMSPI):
# 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)

View file

@ -563,10 +563,11 @@ class RFM9xFSK(RFMSPI):
# 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

View file

@ -430,7 +430,7 @@ class RFMSPI:
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 @@ class RFMSPI:
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