@@ -184,10 +184,13 @@ class ModulinoPixels : public Module {
184
184
bool begin () {
185
185
Module::begin ();
186
186
}
187
- void set (int idx, ModulinoColor rgb, uint8_t brightness = 128 ) {
187
+ void set (int idx, ModulinoColor rgb, uint8_t brightness = 5 ) {
188
+ if (brightness > 0x1F ) {
189
+ brightness = 0x1F ;
190
+ }
188
191
data[idx] = (uint32_t )rgb | brightness | 0xE0 ;
189
192
}
190
- void set (int idx, uint8_t r, uint8_t g, uint8_t b, uint8_t brightness = 128 ) {
193
+ void set (int idx, uint8_t r, uint8_t g, uint8_t b, uint8_t brightness = 5 ) {
191
194
set (idx, ModulinoColor (r,g,b), brightness);
192
195
}
193
196
void clear (int idx) {
@@ -327,16 +330,24 @@ extern ModulinoClass Modulino;
327
330
TODO: These classes need to be ported to Modulino ecosystem, as per the tof_sensor example
328
331
*/
329
332
extern APDS9999 color; // TODO: need to change to APDS9999 https://docs.broadcom.com/doc/APDS-9999-DS
330
- extern LPS22HBClass barometer;
331
333
332
334
class ModulinoMovement : public Module {
333
335
public:
334
336
bool begin () {
335
- imu.begin ();
336
- imu.setContinuousMode ();
337
+ if (_imu == nullptr ) {
338
+ _imu = new BoschSensorClass (*((TwoWire*)getWire ()));
339
+ }
340
+ initialized = _imu->begin ();
341
+ if (initialized) {
342
+ _imu->setContinuousMode ();
343
+ }
344
+ return initialized != 0 ;
337
345
}
338
346
int update () {
339
- return imu.readAcceleration (x, y, z);
347
+ if (initialized) {
348
+ return _imu->readAcceleration (x, y, z);
349
+ }
350
+ return 0 ;
340
351
}
341
352
float getX () {
342
353
return x;
@@ -348,12 +359,39 @@ class ModulinoMovement : public Module {
348
359
return z;
349
360
}
350
361
private:
351
- BoschSensorClass imu = BoschSensorClass(*((TwoWire*)getWire())) ;
362
+ BoschSensorClass* _imu = nullptr ;
352
363
float x,y,z;
364
+ int initialized = 0 ;
353
365
};
354
366
355
367
class ModulinoAir : public Module {
356
-
368
+ public:
369
+ bool begin () {
370
+ if (_barometer == nullptr ) {
371
+ _barometer = new LPS22HBClass (*((TwoWire*)getWire ()));
372
+ }
373
+ initialized = _barometer->begin ();
374
+ if (initialized == 0 ) {
375
+ // unfortunately LPS22HBClass calles Wire.end() on failure, restart it
376
+ getWire ()->begin ();
377
+ }
378
+ return initialized != 0 ;
379
+ }
380
+ float getPressure () {
381
+ if (initialized) {
382
+ return _barometer->readPressure ();
383
+ }
384
+ return 0 ;
385
+ }
386
+ float getTemperature () {
387
+ if (initialized) {
388
+ return _barometer->readTemperature ();
389
+ }
390
+ return 0 ;
391
+ }
392
+ private:
393
+ LPS22HBClass* _barometer = nullptr ;
394
+ int initialized = 0 ;
357
395
};
358
396
359
397
class ModulinoLight : public Module {
0 commit comments