1- /* Copyright (c) 2021, Collab
1+ /* Copyright (c) 2021-2023 , Collab
22 * All rights reserved
33*/
44/*
88#include < MultiPlexer_TCA9548A.h>
99
1010MultiPlexer_TCA9548A::MultiPlexer_TCA9548A (int i2c_addr) {
11+ _address = i2c_addr;
1112 _mux = new TCA9548A (i2c_addr);
1213}
1314
1415void MultiPlexer_TCA9548A::begin () {
16+ // XXX: don't hardcode Wire instance
1517 _mux->begin (Wire1);
1618
1719 // set a base state which we know (also the default state on power on)
@@ -35,32 +37,39 @@ void MultiPlexer_TCA9548A::closeAll() {
3537 _mux->closeAll ();
3638}
3739
38- void MultiPlexer_TCA9548A::scan () {
40+ void MultiPlexer_TCA9548A::scan (bool ignoreMultiplexer ) {
3941 byte error, address;
40- int nDevices;
41- int delayTime = 5000 ;
42- nDevices = 0 ;
42+ int nDevices = 0 ;
43+
4344 for (address = 1 ; address < 127 ; address++) {
4445 Wire1.beginTransmission (address);
4546 error = Wire1.endTransmission ();
4647 if (error == 0 ) {
47- Serial.print (F (" I2C device found at address 0x" ));
48- if (address < 16 ) {
49- Serial.print (F (" 0" ));
48+ if (!(ignoreMultiplexer && address == _address)) {
49+ if (address < 16 ) {
50+ Log.info (F (" TCA9548A - I2C device found at address 0x0%x" CR), address);
51+ } else {
52+ Log.info (F (" TCA9548A - I2C device found at address 0x%x" CR), address);
53+ }
54+ nDevices++;
5055 }
51- Serial.println (address, HEX);
52- nDevices++;
53- }
54- else if (error == 4 ) {
55- Serial.print (F (" Unknow error at address 0x" ));
56+ } else if (error == 4 ) {
5657 if (address < 16 ) {
57- Serial.print (F (" 0" ));
58+ Log.info (F (" TCA9548A - Unknown error at address 0x0%x" CR), address);
59+ } else {
60+ Log.info (F (" TCA9548A - Unknown error at address 0x%x" CR), address);
5861 }
59- Serial.println (address, HEX);
6062 }
6163 }
64+
6265 if (nDevices == 0 ) {
63- Serial.println (F (" No I2C devices found\n " ));
66+ Log.warning (F (" TCA9548A - No I2C devices found" CR));
67+ }
68+ }
69+
70+ void MultiPlexer_TCA9548A::scanAll () {
71+ // see https://github.com/WifWaf/TCA9548A/issues/6
72+ for (int channel = 0 ; channel < 8 ; channel++) {
73+
6474 }
65- delay (delayTime);
6675}
0 commit comments