diff --git a/circuitpython_nrf24l01/rf24.py b/circuitpython_nrf24l01/rf24.py index dcf5bd3..019efe4 100644 --- a/circuitpython_nrf24l01/rf24.py +++ b/circuitpython_nrf24l01/rf24.py @@ -486,6 +486,7 @@ def dynamic_payloads(self, enable): elif isinstance(enable, int): self._dyn_pl = 0x3F & enable 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) @@ -501,7 +502,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.dynamic_payloads = self._dyn_pl | (bool(enable) << pipe_number) else: raise IndexError("pipe_number must be in range [0, 5]") @@ -541,6 +542,7 @@ def set_payload_length(self, length, pipe_number=None): def get_payload_length(self, pipe_number=0): """Returns an `int` describing the current setting of a specified data pipe's expected static payload length.""" + self._pl_len[pipe_number] = self._reg_read(RX_PL_LENG + pipe_number) return self._pl_len[pipe_number] @property @@ -602,12 +604,13 @@ def auto_ack(self, enable): self._aa = 0x3F & enable elif isinstance(enable, (list, tuple)): for i, val in enumerate(enable): + self._aa = self._reg_read(AUTO_ACK) 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 bool(self._aa & 1) != bool(self._aa & 0x3E): - self._aa &= 1 + if bool(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): @@ -616,7 +619,7 @@ 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.auto_ack = self._aa | (bool(enable) << pipe_number) else: raise IndexError("pipe_number must be in range [0, 5]") @@ -625,6 +628,7 @@ def get_auto_ack(self, pipe_number=0): """Returns a `bool` describing the automatic acknowledgement feature setting about a specific data pipe.""" if 0 <= pipe_number <= 5: + self._aa = self._reg_read(AUTO_ACK) return bool(self._aa & (1 << pipe_number)) raise IndexError("pipe_number must be in range [0, 5]")