Skip to content

Commit b89cb1f

Browse files
committed
Fix begin() and bool() return values
The bug was due to discover() return being divided by 2
1 parent 585d2fd commit b89cb1f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Modulino.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class Module : public Printable {
3939
if (address == 0xFF) {
4040
address = discover() / 2; // divide by 2 to match address in fw main.c
4141
}
42-
return (address != 0xFF);
42+
return (address < 0x7F);
4343
}
4444
virtual uint8_t discover() {
4545
return 0xFF;
4646
}
4747
operator bool() {
48-
return address != 0xFF;
48+
return address < 0x7F;
4949
}
5050
static HardwareI2C* getWire() {
5151
return Modulino._wire;
@@ -133,6 +133,7 @@ class ModulinoButtons : public Module {
133133
return match[i];
134134
}
135135
}
136+
return 0xFF;
136137
}
137138
private:
138139
bool last_status[3];
@@ -161,6 +162,7 @@ class ModulinoBuzzer : public Module {
161162
return match[i];
162163
}
163164
}
165+
return 0xFF;
164166
}
165167
protected:
166168
std::vector<uint8_t> match = { 0x3C }; // same as fw main.c
@@ -207,6 +209,7 @@ class ModulinoPixels : public Module {
207209
return match[i];
208210
}
209211
}
212+
return 0xFF;
210213
}
211214
private:
212215
static const int NUMLEDS = 8;
@@ -263,6 +266,7 @@ class ModulinoKnob : public Module {
263266
return match[i];
264267
}
265268
}
269+
return 0xFF;
266270
}
267271
private:
268272
bool _pressed = false;
@@ -379,6 +383,11 @@ class ModulinoLight : public Module {
379383
class ModulinoDistance : public Module {
380384
public:
381385
bool begin() {
386+
// try scanning for 0x29 since the library contains a while(true) on begin()
387+
getWire()->beginTransmission(0x29);
388+
if (getWire()->endTransmission() != 0) {
389+
return false;
390+
}
382391
tof_sensor = new VL53L4CD((TwoWire*)getWire(), -1);
383392
auto ret = tof_sensor->InitSensor();
384393
if (ret == VL53L4CD_ERROR_NONE) {

0 commit comments

Comments
 (0)