Skip to content

Commit

Permalink
dyn_pl & auto_ack return int; more doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Dec 9, 2020
1 parent f1a570d commit 7938ecc
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 251 deletions.
25 changes: 15 additions & 10 deletions circuitpython_nrf24l01/rf24.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(self, spi, csn, ce, spi_frequency=10000000):
self._retry_setup = 0x53 # ard = 1500; arc = 3
# pre-configure the RF_SETUP register
self._rf_setup = 0x07 # 1 Mbps data_rate, and 0 dbm pa_level
# pre-configure dynamic_payloads & auto_ack for RX operations
# pre-configure dynamic_payloads & auto_ack
self._dyn_pl = 0x3F # 0x3F = enable dynamic_payloads on all pipes
self._aa = 0x3F # 0x3F = enable auto_ack on all pipes
# pre-configure features for TX operations:
Expand Down Expand Up @@ -471,17 +471,21 @@ def is_plus_variant(self):

@property
def dynamic_payloads(self):
"""This `bool` attribute controls the nRF24L01's dynamic payload
"""This `int` attribute controls the nRF24L01's dynamic payload
length feature for each pipe."""
self._dyn_pl = self._reg_read(DYN_PL_LEN)
self._features = self._reg_read(TX_FEATURE)
return bool(self._dyn_pl) and self._features & 4 == 4
if self._features & 4 == 4:
return self._dyn_pl
return 0

@dynamic_payloads.setter
def dynamic_payloads(self, enable):
self._features = self._reg_read(TX_FEATURE)
if isinstance(enable, (bool, int)):
if isinstance(enable, bool):
self._dyn_pl = 0x3F if enable else 0
elif isinstance(enable, int):
self._dyn_pl = 0x3F & enable
elif isinstance(enable, (list, tuple)):
for i, val in enumerate(enable):
if i < 6 and val >= 0: # skip pipe if val is negative
Expand All @@ -499,8 +503,8 @@ def dynamic_payloads(self, enable):

@property
def payload_length(self):
"""This `int` attribute specifies the length (in bytes) of static payloads for each
pipe."""
"""This attribute specifies the length (in bytes) of static payloads for each
pipe using a `list` of integers."""
return self._pl_len

@payload_length.setter
Expand Down Expand Up @@ -547,15 +551,17 @@ def ard(self, delta):

@property
def auto_ack(self):
"""This `bool` attribute controls the nRF24L01's automatic
"""This `int` attribute controls the nRF24L01's automatic
acknowledgment feature during the process of receiving a packet."""
self._aa = self._reg_read(AUTO_ACK)
return bool(self._aa)
return self._aa

@auto_ack.setter
def auto_ack(self, enable):
if isinstance(enable, (bool, int)):
if isinstance(enable, bool):
self._aa = 0x3F if enable else 0
elif isinstance(enable, int):
self._aa = 0x3F & enable
elif isinstance(enable, (list, tuple)):
for i, val in enumerate(enable):
if i < 6 and val >= 0: # skip pipe if val is negative
Expand Down Expand Up @@ -709,7 +715,6 @@ def resend(self, send_only=False):
self.clear_status_flags()
self._reg_write(0xE3)
self.ce_pin.value = 1
time.sleep(0.00001)
self.ce_pin.value = 0
while not self._status & 0x70:
self.update()
Expand Down
3 changes: 1 addition & 2 deletions circuitpython_nrf24l01/rf24_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,12 @@ def update(self):
def resend(self, send_only=False):
result = False
if not self.fifo(True, True):
self.ce_pin.value = 0
if not send_only:
self.flush_rx()
self.clear_status_flags()
self._reg_write(0xE3)
self.ce_pin.value = 0
self.ce_pin.value = 1
time.sleep(0.00001)
self.ce_pin.value = 0
while not self._status & 0x70:
self.update()
Expand Down
Loading

0 comments on commit 7938ecc

Please sign in to comment.