141
141
# the warning to work around the error.
142
142
# pylint: disable=too-many-instance-attributes
143
143
144
+ # disable another pylint nit-pick
145
+ # pylint: disable=too-many-public-methods
146
+
144
147
145
148
def ticks_diff (ticks1 : int , ticks2 : int ) -> int :
146
149
"""Compute the signed difference between two ticks values
@@ -306,9 +309,7 @@ def __init__( # pylint: disable=invalid-name
306
309
# Check the version of the chip.
307
310
version = self ._read_u8 (_REG_VERSION )
308
311
if version != 0x24 :
309
- raise RuntimeError (
310
- "Failed to find RFM69 with expected version, check wiring!"
311
- )
312
+ raise RuntimeError ("Invalid RFM69 version, check wiring!" )
312
313
self .idle () # Enter idle state.
313
314
# Setup the chip in a similar way to the RadioHead RFM69 library.
314
315
# Set FIFO TX condition to not empty and the default FIFO threshold to 15.
@@ -447,12 +448,16 @@ def reset(self) -> None:
447
448
self ._reset .value = False
448
449
time .sleep (0.005 ) # 5 ms
449
450
451
+ def set_boost (self , setting : int ) -> None :
452
+ """Set preamp boost if needed."""
453
+ if self ._tx_power >= 18 :
454
+ self ._write_u8 (_REG_TEST_PA1 , setting )
455
+ self ._write_u8 (_REG_TEST_PA2 , setting )
456
+
450
457
def idle (self ) -> None :
451
458
"""Enter idle standby mode (switching off high power amplifiers if necessary)."""
452
459
# Like RadioHead library, turn off high power boost if enabled.
453
- if self ._tx_power >= 18 :
454
- self ._write_u8 (_REG_TEST_PA1 , _TEST_PA1_NORMAL )
455
- self ._write_u8 (_REG_TEST_PA2 , _TEST_PA2_NORMAL )
460
+ self .set_boost (_TEST_PA1_NORMAL )
456
461
self .operation_mode = STANDBY_MODE
457
462
458
463
def sleep (self ) -> None :
@@ -464,9 +469,7 @@ def listen(self) -> None:
464
469
and retrieve packets as they're available.
465
470
"""
466
471
# Like RadioHead library, turn off high power boost if enabled.
467
- if self ._tx_power >= 18 :
468
- self ._write_u8 (_REG_TEST_PA1 , _TEST_PA1_NORMAL )
469
- self ._write_u8 (_REG_TEST_PA2 , _TEST_PA2_NORMAL )
472
+ self .set_boost (_TEST_PA1_NORMAL )
470
473
# Enable payload ready interrupt for D0 line.
471
474
self .dio_0_mapping = 0b01
472
475
# Enter RX mode (will clear FIFO!).
@@ -478,9 +481,7 @@ def transmit(self) -> None:
478
481
:py:func:`send` instead.
479
482
"""
480
483
# Like RadioHead library, turn on high power boost if enabled.
481
- if self ._tx_power >= 18 :
482
- self ._write_u8 (_REG_TEST_PA1 , _TEST_PA1_BOOST )
483
- self ._write_u8 (_REG_TEST_PA2 , _TEST_PA2_BOOST )
484
+ self .set_boost (_TEST_PA1_BOOST )
484
485
# Enable packet sent interrupt for D0 line.
485
486
self .dio_0_mapping = 0b00
486
487
# Enter TX mode (will clear FIFO!).
@@ -645,42 +646,39 @@ def tx_power(self) -> int:
645
646
pa0 = self .pa_0_on
646
647
pa1 = self .pa_1_on
647
648
pa2 = self .pa_2_on
649
+ current_output_power = self .output_power
648
650
if pa0 and not pa1 and not pa2 :
649
651
# -18 to 13 dBm range
650
- return - 18 + self . output_power
652
+ return - 18 + current_output_power
651
653
if not pa0 and pa1 and not pa2 :
652
654
# -2 to 13 dBm range
653
- return - 18 + self . output_power
655
+ return - 18 + current_output_power
654
656
if not pa0 and pa1 and pa2 and not self .high_power :
655
657
# 2 to 17 dBm range
656
- return - 14 + self . output_power
658
+ return - 14 + current_output_power
657
659
if not pa0 and pa1 and pa2 and self .high_power :
658
660
# 5 to 20 dBm range
659
- return - 11 + self . output_power
660
- raise RuntimeError ("Power amplifiers in unknown state !" )
661
+ return - 11 + current_output_power
662
+ raise RuntimeError ("Power amps state unknown!" )
661
663
662
664
@tx_power .setter
663
665
def tx_power (self , val : float ):
664
666
val = int (val )
665
667
# Determine power amplifier and output power values depending on
666
668
# high power state and requested power.
667
- pa_0_on = 0
668
- pa_1_on = 0
669
- pa_2_on = 0
669
+ pa_0_on = pa_1_on = pa_2_on = 0
670
670
output_power = 0
671
671
if self .high_power :
672
672
# Handle high power mode.
673
673
assert - 2 <= val <= 20
674
+ pa_1_on = 1
674
675
if val <= 13 :
675
- pa_1_on = 1
676
676
output_power = val + 18
677
677
elif 13 < val <= 17 :
678
- pa_1_on = 1
679
678
pa_2_on = 1
680
679
output_power = val + 14
681
680
else : # power >= 18 dBm
682
681
# Note this also needs PA boost enabled separately!
683
- pa_1_on = 1
684
682
pa_2_on = 1
685
683
output_power = val + 11
686
684
else :
0 commit comments