Skip to content

Commit 469fd32

Browse files
use ArduinoLog
1 parent 75c5e84 commit 469fd32

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

MultiPlexer_TCA9548A/MultiPlexer_TCA9548A.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021, Collab
1+
/* Copyright (c) 2021-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -8,10 +8,12 @@
88
#include <MultiPlexer_TCA9548A.h>
99

1010
MultiPlexer_TCA9548A::MultiPlexer_TCA9548A(int i2c_addr) {
11+
_address = i2c_addr;
1112
_mux = new TCA9548A(i2c_addr);
1213
}
1314

1415
void 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
}

MultiPlexer_TCA9548A/MultiPlexer_TCA9548A.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021, Collab
1+
/* Copyright (c) 2021-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -10,20 +10,23 @@
1010
#include <Arduino.h>
1111
#include <Wire.h>
1212
#include <TCA9548A.h>
13+
#include <ArduinoLog.h>
1314

1415
class MultiPlexer_TCA9548A
1516
{
1617
public:
1718
MultiPlexer_TCA9548A(int i2c_addr = 0x70);
1819
void begin();
19-
void scan();
20+
void scan(bool ignoreMultiplexer = true);
21+
void scanAll();
2022
void closeAll();
2123
void openChannel(uint8_t channel_nr);
2224
void closeChannel(uint8_t channel_nr);
2325
void switchChannel(uint8_t channel_nr);
2426

2527
private:
2628
TCA9548A* _mux;
29+
int _address;
2730
};
2831

2932
#endif

0 commit comments

Comments
 (0)