Skip to content

Instantly share code, notes, and snippets.

@LuckyResistor
Created May 6, 2018 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuckyResistor/e55749d4948ac2aa8142f7668f9caa97 to your computer and use it in GitHub Desktop.
Save LuckyResistor/e55749d4948ac2aa8142f7668f9caa97 to your computer and use it in GitHub Desktop.
The implementation example for flags usage.
#include "TCA9548A.hpp"
namespace lr {
// ...
TCA9548A::Status TCA9548A::setChannel(Channel channel)
{
if (_enabledChannels != Channels(channel)) {
_enabledChannels = Channels(channel);
return writeChannelsToChip();
}
return Status::Success;
}
TCA9548A::Status TCA9548A::setChannels(Channels channels)
{
if (_enabledChannels != channels) {
_enabledChannels = channels;
return writeChannelsToChip();
}
return Status::Success;
}
TCA9548A::Status TCA9548A::clearAllChannels()
{
if (_enabledChannels != Channels()) {
_enabledChannels = Channels();
return writeChannelsToChip();
}
return Status::Success;
}
TCA9548A::Status TCA9548A::writeChannelsToChip()
{
const uint8_t data = _enabledChannels;
if (_wireMaster->writeBytes(_address, &data, 1) != WireMaster::Status::Success) {
return Status::Error;
}
return Status::Success;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment