-
Notifications
You must be signed in to change notification settings - Fork 84
Open
Description
I'm trying to create an io_expander for pca9557.py and was looking at the included io_expander samples and I think there are some copy/paste typos.
In api_drivers/common_api_drivers/io_expander/ch422g.py
def _set_level(self, level):
if self._mode == self.OUT:
if level:
# 3. High level && Set 0 to output high
# 4. Low level && Set 0 to output low
states = Pin._output_states & ~self.__bit
else:
# 1. High level && Set 1 to output high
# 2. Low level && Set 1 to output low
states = Pin._output_states | self.__bit
# Write to reg only when different */
if states != Pin._output_states:
self._write_reg(_REG_OUTPUT, states)
Pin._output_states = states
but api_drivers/common_api_drivers/io_expander/{ht8574a.py,ht8574b.py,tca9535.py,tca9554.py} don't output the changed state on the self.__write_reg() call.
In addition the states assignments seem reversed between the ch422g.py and the others ( states & ~self.__bit ) vs ( states | self.__bit) (which may be intentional, I have not looked up the specifics the parts themselves) but it seems incorrect offhand.
def _set_level(self, level):
if self._mode == self.OUT:
if level:
states = Pin._output_states | self.__bit
else:
states = Pin._output_states & ~self.__bit
# 0nly set if there is an actual change
if states != Pin._output_states:
self.__write_reg(Pin._output_states)
Pin._output_states = states
Changed Code
if level:
<< states = Pin._output_states | self.__bit
>> states = Pin._output_states & ~self.__bit
else:
<< states = Pin._output_states & ~self.__bit
>> states = Pin._output_states | self.__bit
# 0nly set if there is an actual change
if states != Pin._output_states:
<< self.__write_reg(Pin._output_states)
>> self.__write_reg(states)
Pin._output_states = states
Metadata
Metadata
Assignees
Labels
No labels