@@ -25,7 +25,6 @@ class ModulinoClass {
25
25
_wire->setClock (100000 );
26
26
}
27
27
friend class Module ;
28
- friend class Distance ;
29
28
protected:
30
29
HardwareI2C* _wire;
31
30
};
@@ -40,6 +39,7 @@ class Module : public Printable {
40
39
if (address == 0xFF ) {
41
40
address = discover () / 2 ; // divide by 2 to match address in fw main.c
42
41
}
42
+ return (address != 0xFF );
43
43
}
44
44
virtual uint8_t discover () {
45
45
return 0xFF ;
@@ -183,9 +183,6 @@ class ModulinoPixels : public Module {
183
183
: Module(address, " LEDS" ) {
184
184
memset ((uint8_t *)data, 0xE0 , NUMLEDS * 4 );
185
185
}
186
- bool begin () {
187
- Module::begin ();
188
- }
189
186
void set (int idx, ModulinoColor rgb, uint8_t brightness = 25 ) {
190
187
if (idx < NUMLEDS) {
191
188
uint8_t _brightness = map (brightness, 0 , 100 , 0 , 0x1F );
@@ -270,6 +267,9 @@ class ModulinoMovement : public Module {
270
267
initialized = _imu->begin ();
271
268
return initialized != 0 ;
272
269
}
270
+ operator bool () {
271
+ return (initialized != 0 );
272
+ }
273
273
int update () {
274
274
if (initialized) {
275
275
return _imu->readAcceleration (x, y, z);
@@ -300,6 +300,9 @@ class ModulinoThermo: public Module {
300
300
initialized = _sensor->begin ();
301
301
return initialized;
302
302
}
303
+ operator bool () {
304
+ return (initialized != 0 );
305
+ }
303
306
float getHumidity () {
304
307
if (initialized) {
305
308
return _sensor->readHumidity ();
@@ -330,6 +333,9 @@ class ModulinoPressure : public Module {
330
333
}
331
334
return initialized != 0 ;
332
335
}
336
+ operator bool () {
337
+ return (initialized != 0 );
338
+ }
333
339
float getPressure () {
334
340
if (initialized) {
335
341
return _barometer->readPressure ();
@@ -355,11 +361,23 @@ class ModulinoDistance : public Module {
355
361
public:
356
362
bool begin () {
357
363
tof_sensor = new VL53L4CD ((TwoWire*)getWire (), -1 );
358
- tof_sensor->InitSensor ();
359
- tof_sensor->VL53L4CD_SetRangeTiming (10 , 0 );
360
- tof_sensor->VL53L4CD_StartRanging ();
364
+ auto ret = tof_sensor->InitSensor ();
365
+ if (ret == VL53L4CD_ERROR_NONE) {
366
+ tof_sensor->VL53L4CD_SetRangeTiming (10 , 0 );
367
+ tof_sensor->VL53L4CD_StartRanging ();
368
+ return true ;
369
+ } else {
370
+ tof_sensor = nullptr ;
371
+ return false ;
372
+ }
373
+ }
374
+ operator bool () {
375
+ return (tof_sensor != nullptr );
361
376
}
362
377
float get () {
378
+ if (tof_sensor == nullptr ) {
379
+ return NAN;
380
+ }
363
381
VL53L4CD_Result_t results;
364
382
uint8_t NewDataReady = 0 ;
365
383
uint8_t status;
@@ -371,5 +389,5 @@ class ModulinoDistance : public Module {
371
389
return results.distance_mm ;
372
390
}
373
391
private:
374
- VL53L4CD* tof_sensor; ;
392
+ VL53L4CD* tof_sensor = nullptr ;
375
393
};
0 commit comments