ClosedCube_TCA9548A.cpp 876 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <Wire.h>
  2. #include "ClosedCube_TCA9548A.h"
  3. ClosedCube::Wired::TCA9548A::TCA9548A() {
  4. }
  5. ClosedCube::Wired::TCA9548A::TCA9548A(uint8_t address):_address(address) {
  6. }
  7. void ClosedCube::Wired::TCA9548A::address(uint8_t address) {
  8. _address = address;
  9. }
  10. uint8_t ClosedCube::Wired::TCA9548A::getChannel() {
  11. return _currentChannel;
  12. }
  13. uint8_t ClosedCube::Wired::TCA9548A::selectChannel(uint8_t channel) {
  14. uint8_t result = 0xff;
  15. if (channel >= 0 && channel < TCA9548A_MAX_CHANNELS) {
  16. Wire.beginTransmission(_address);
  17. Wire.write( ((uint8_t)1) << (channel));
  18. _currentChannel = channel;
  19. result = Wire.endTransmission();
  20. }
  21. return result;
  22. }
  23. uint8_t ClosedCube::Wired::TCA9548A::nextChannel() {
  24. uint8_t nextChannel = _currentChannel + 1;
  25. if (nextChannel > (TCA9548A_MAX_CHANNELS-1)) {
  26. nextChannel = 0;
  27. }
  28. return selectChannel(nextChannel);
  29. }