Skip to content

Commit cefd778

Browse files
committed
Add SNR property according to datasheet
Format with Black
1 parent 1784cfa commit cefd778

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

adafruit_rfm9x.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@
1212
1313
* Author(s): Tony DiCola, Jerry Needell
1414
"""
15-
import time
1615
import random
17-
from micropython import const
18-
16+
import time
1917

2018
import adafruit_bus_device.spi_device as spidev
21-
19+
from micropython import const
2220

2321
__version__ = "0.0.0-auto.0"
2422
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RFM9x.git"
2523

26-
2724
# Internal constants:
2825
# Register names (FSK Mode even though we use LoRa instead, from table 85)
2926
_RH_RF95_REG_00_FIFO = const(0x00)
@@ -497,6 +494,16 @@ def rssi(self):
497494
raw_rssi -= 164
498495
return raw_rssi
499496

497+
@property
498+
def snr(self):
499+
"""The SNR (in dB) of the last received message."""
500+
# Read SNR 0x19 register and convert to value using formula in datasheet.
501+
# SNR(dB) = PacketSnr [twos complement] / 4
502+
snr_byte = self._read_u8(_RH_RF95_REG_19_PKT_SNR_VALUE)
503+
if snr_byte > 127:
504+
snr_byte = (256 - snr_byte) * -1
505+
return snr_byte / 4
506+
500507
@property
501508
def signal_bandwidth(self):
502509
"""The signal bandwidth used by the radio (try setting to a higher

0 commit comments

Comments
 (0)