Skip to content

Commit

Permalink
refresh internal data when calling setter/getters
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Jan 29, 2021
1 parent 75750a5 commit 3dd69f6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions circuitpython_nrf24l01/rf24.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def dynamic_payloads(self, enable):
if isinstance(enable, (bool, int)):
self._dyn_pl = 0x3F if enable else 0
elif isinstance(enable, (list, tuple)):
self._dyn_pl = self._reg_read(DYN_PL_LEN)
for i, val in enumerate(enable):
if i < 6 and val >= 0: # skip pipe if val is negative
self._dyn_pl = (self._dyn_pl & ~(1 << i)) | (bool(val) << i)
Expand All @@ -500,7 +501,7 @@ def set_dynamic_payloads(self, enable, pipe_number=None):
if pipe_number is None:
self.dynamic_payloads = bool(enable)
elif 0 <= pipe_number <= 5:
self._dyn_pl &= ~(1 << pipe_number)
self._dyn_pl = self._reg_read(DYN_PL_LEN) & ~(1 << pipe_number)
self._dyn_pl |= (bool(enable) << pipe_number)
if self._dyn_pl:
self._features = (self._features & 3) | (bool(self._dyn_pl) << 2)
Expand Down Expand Up @@ -604,11 +605,14 @@ def auto_ack(self, enable):
if isinstance(enable, (bool, int)):
self._aa = 0x3F if enable else 0
elif isinstance(enable, (list, tuple)):
self._aa = self._reg_read(AUTO_ACK)
for i, val in enumerate(enable):
if i < 6 and val >= 0: # skip pipe if val is negative
self._aa = (self._aa & ~(1 << i)) | (bool(val) << i)
else:
raise ValueError("auto_ack: {} is not a valid input" % enable)
if self._aa & 1 != bool(self._aa & 0x3E) and self._aa & 0x3E:
self._aa |= 1
self._reg_write(AUTO_ACK, self._aa)

def set_auto_ack(self, enable, pipe_number=None):
Expand All @@ -617,8 +621,10 @@ def set_auto_ack(self, enable, pipe_number=None):
if pipe_number is None:
self.auto_ack = bool(enable)
elif 0 <= pipe_number <= 5:
self._aa &= ~(1 << pipe_number)
self._aa = self._reg_read(AUTO_ACK) & ~(1 << pipe_number)
self._aa |= (bool(enable) << pipe_number)
if pipe_number:
self._aa += 1
self._reg_write(AUTO_ACK, self._aa)
else:
raise IndexError("pipe_number must be in range [0, 5]")
Expand Down Expand Up @@ -671,7 +677,7 @@ def read_ack(self):

@property
def allow_ask_no_ack(self):
"""Allow or disallow the use of ``ask_no_ack`` parameter to `send()` &
"""Enable or disable the use of ``ask_no_ack`` parameter to `send()` &
`write()`."""
self._features = self._reg_read(TX_FEATURE)
return bool(self._features & 1)
Expand Down

0 comments on commit 3dd69f6

Please sign in to comment.