RobTillaart / TCA9548

Arduino library for TCA9548 8 channel I2C multiplexer and compatibles.
MIT License
20 stars 7 forks source link

TCA9548::disableChannel(uint8_t channel) is not working as expected #20

Closed pghj closed 6 months ago

pghj commented 6 months ago

I think disableChannel was copy-pasted from enableChannel, but the condition !isEnabled(channel) was not inverted by mistake.

RobTillaart commented 6 months ago

Thank you for catching, definitely a (copy paste) BUG. Will fix asap, probably tomorrow.

pghj commented 6 months ago

Thanks for the quick response. It seems to me that the check can just be removed from both methods, because setChannelMask already tests the entire mask for changes.

pghj commented 6 months ago

Oops wrong button.

RobTillaart commented 6 months ago

It seems to me that the check can just be removed from both methods, because setChannelMask already tests the entire mask for changes.

Good idea, would simplify code a bit. Will create a develop branch asap to prepare for a 0.3.0 version.

RobTillaart commented 6 months ago

Propose code would also return false if the writing to the multiplexer failed.

bool TCA9548::enableChannel(uint8_t channel)
{
  if (channel >= _channels) return false;
  return setChannelMask(_mask | (0x01 << channel));
}

bool TCA9548::disableChannel(uint8_t channel)
{
  if (channel >= _channels) return false;
  return setChannelMask(_mask & ~(0x01 << channel));
}
RobTillaart commented 6 months ago

@pghj Develop branch created, build-CI is running. Some more edits were made.

pghj commented 6 months ago

Propose code

Looks good. Can you also make it return the result of setChannelMask when calling selectChannel?

RobTillaart commented 6 months ago

Will check after lunch

RobTillaart commented 6 months ago

Propose code

Looks good. Can you also make it return the result of setChannelMask when calling selectChannel?

done

RobTillaart commented 6 months ago

@pghj Do you have time to test the develop branch, otherwise I will merge it (as I see no issues for now).

RobTillaart commented 6 months ago

@pghj I merged develop and released 0.3.0 .

Again thanks for reporting the issue!