@@ -184,10 +184,13 @@ class ModulinoPixels : public Module {
184184 bool begin () {
185185 Module::begin ();
186186 }
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+ }
188191 data[idx] = (uint32_t )rgb | brightness | 0xE0 ;
189192 }
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 ) {
191194 set (idx, ModulinoColor (r,g,b), brightness);
192195 }
193196 void clear (int idx) {
@@ -327,16 +330,24 @@ extern ModulinoClass Modulino;
327330 TODO: These classes need to be ported to Modulino ecosystem, as per the tof_sensor example
328331*/
329332extern APDS9999 color; // TODO: need to change to APDS9999 https://docs.broadcom.com/doc/APDS-9999-DS
330- extern LPS22HBClass barometer;
331333
332334class ModulinoMovement : public Module {
333335public:
334336 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 ;
337345 }
338346 int update () {
339- return imu.readAcceleration (x, y, z);
347+ if (initialized) {
348+ return _imu->readAcceleration (x, y, z);
349+ }
350+ return 0 ;
340351 }
341352 float getX () {
342353 return x;
@@ -348,12 +359,39 @@ class ModulinoMovement : public Module {
348359 return z;
349360 }
350361private:
351- BoschSensorClass imu = BoschSensorClass(*((TwoWire*)getWire())) ;
362+ BoschSensorClass* _imu = nullptr ;
352363 float x,y,z;
364+ int initialized = 0 ;
353365};
354366
355367class 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 ;
357395};
358396
359397class ModulinoLight : public Module {
0 commit comments