7
7
#include " Arduino_LSM6DSOX.h"
8
8
#include < Arduino_LPS22HB.h>
9
9
#include < Arduino_HS300x.h>
10
+ #include < Arduino_ISL28022.h>
10
11
// #include <SE05X.h> // need to provide a way to change Wire object
11
12
12
13
#ifndef ARDUINO_API_VERSION
@@ -48,6 +49,7 @@ class Module : public Printable {
48
49
public:
49
50
Module (uint8_t address = 0xFF , char * name = " " )
50
51
: address(address), name(name) {}
52
+ virtual ~Module () {}
51
53
bool begin () {
52
54
if (address == 0xFF ) {
53
55
address = discover () / 2 ; // divide by 2 to match address in fw main.c
@@ -504,4 +506,66 @@ class ModulinoDistance : public Module {
504
506
// VL53L4ED_ResultsData_t results;
505
507
float internal = NAN;
506
508
_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;
507
571
};
0 commit comments