77#include  " Arduino_LSM6DSOX.h" 
88#include  < Arduino_LPS22HB.h> 
99#include  < Arduino_HS300x.h> 
10+ #include  < Arduino_ISL28022.h> 
1011// #include <SE05X.h>  // need to provide a way to change Wire object
1112
1213#ifndef  ARDUINO_API_VERSION
@@ -48,6 +49,7 @@ class Module : public Printable {
4849public: 
4950  Module (uint8_t  address = 0xFF , char * name = " "  )
5051    : address(address), name(name) {}
52+   virtual  ~Module () {}  
5153  bool  begin () {
5254    if  (address == 0xFF ) {
5355      address = discover () / 2 ;  //  divide by 2 to match address in fw main.c
@@ -504,4 +506,66 @@ class ModulinoDistance : public Module {
504506  // VL53L4ED_ResultsData_t results;
505507  float  internal = NAN;
506508  _distance_api* api = nullptr ;
509+ };
510+ 
511+ #define  M_AMPERE_SHUNT_R  0.1    // 100 mohm
512+ #define  M_AMPERE_ADDRESS  0x40   // A0 and A1 to GND
513+ 
514+ class  ModulinoAmpere  : public  Module  {
515+ public: 
516+   ModulinoAmpere () : Module(0xFF ," AMPERE"  ), 
517+   _sensor (nullptr ), initialized(false ), isAvailable(false ) {
518+   }
519+   ~ModulinoAmpere () {
520+     if (_sensor != nullptr ) {
521+       delete  _sensor;
522+       _sensor = nullptr ;
523+     }
524+   }
525+   
526+   void  begin (float  shunt_res_ohm, uint8_t  address = M_AMPERE_ADDRESS) {
527+     if  (_sensor == nullptr ) {
528+       _sensor = new  ISL28022Class (shunt_res_ohm, 
529+                                   *((TwoWire*)getWire ()),
530+                                   address);
531+     }
532+     if (_sensor != nullptr ) {
533+       initialized = _sensor->begin ();
534+       if (*_sensor) {
535+         isAvailable = true ;
536+       }
537+     }
538+     __increaseI2CPriority ();
539+   }
540+ 
541+   void  begin () {
542+     begin (M_AMPERE_SHUNT_R,M_AMPERE_ADDRESS);
543+   }
544+   /*  get voltage in Volts*/ 
545+   float  getVoltage () {
546+     if (initialized) { 
547+       bool  ovf = false ;
548+       return  _sensor->getBusVoltage (ovf); }
549+     return  0.0 ;
550+   }
551+   /*  get current in Ampere */ 
552+   float  getCurrent () {
553+     if (initialized) { return  _sensor->getCurrent (); }
554+     return  0.0 ;
555+   }
556+   /*  get power in Watts*/ 
557+   float  getPower () {
558+     if (initialized) { return  _sensor->getPower (); }
559+     return  0.0 ;
560+   }
561+   
562+   /*  sensor is configured and present */ 
563+   bool  available () {
564+     return  isAvailable;
565+   }
566+ 
567+ private: 
568+   ISL28022Class *_sensor;
569+   bool  initialized;
570+   bool  isAvailable;
507571};
0 commit comments