11// FILE: INA219.h
22// AUTHOR: Rob Tillaart
3- // VERSION: 0.1.2
3+ // VERSION: 0.1.3
44// DATE: 2021-05-18
55// PURPOSE: Arduino library for INA219 voltage, current and power sensor
66// URL: https://github.com/RobTillaart/INA219
7- //
8- // HISTORY: see changelog.md
97
108
119#include " INA219.h"
@@ -90,7 +88,7 @@ float INA219::getBusVoltage()
9088{
9189 uint16_t value = _readRegister (INA219_BUS_VOLTAGE);
9290 uint8_t flags = value & 0x03 ;
93- // overflow handling
91+ // math overflow handling
9492 if (flags & 0x01 ) return -100 ;
9593 float voltage = (value >> 3 ) * 4e-3 ; // fixed 4 mV
9694 return voltage;
@@ -112,6 +110,20 @@ float INA219::getCurrent()
112110}
113111
114112
113+ bool INA219::getMathOverflowFlag ()
114+ {
115+ uint16_t value = _readRegister (INA219_BUS_VOLTAGE);
116+ return ((value & 0x0001 ) == 0x0001 );
117+ }
118+
119+
120+ bool INA219::getConversionFlag ()
121+ {
122+ uint16_t value = _readRegister (INA219_BUS_VOLTAGE);
123+ return ((value & 0x0002 ) == 0x0002 );
124+ }
125+
126+
115127// //////////////////////////////////////////////////////
116128//
117129// CONFIGURATION
@@ -178,7 +190,7 @@ uint8_t INA219::getGain()
178190
179191bool INA219::setBusADC (uint8_t mask)
180192{
181- if (mask > 0x000F ) return false ;
193+ if (mask > 0x0F ) return false ;
182194
183195 // TODO improve this one. datasheet.
184196 // two functions
@@ -204,7 +216,7 @@ uint8_t INA219::getBusADC()
204216
205217bool INA219::setShuntADC (uint8_t mask)
206218{
207- if (mask > 0x000F ) return false ;
219+ if (mask > 0x0F ) return false ;
208220
209221 // TODO improve this one. datasheet.
210222 // two functions
@@ -227,7 +239,7 @@ uint8_t INA219::getShuntADC()
227239
228240bool INA219::setMode (uint8_t mode)
229241{
230- if (mode > 8 ) return false ;
242+ if (mode > 7 ) return false ;
231243 uint16_t config = _readRegister (INA219_CONFIGURATION);
232244 config &= ~INA219_CONF_MODE;
233245 config |= mode;
@@ -250,7 +262,7 @@ uint8_t INA219::getMode()
250262//
251263bool INA219::setMaxCurrentShunt (float maxCurrent, float shunt)
252264{
253- #define printdebug true
265+ // #define printdebug
254266 uint16_t calib = 0 ;
255267
256268 if (maxCurrent < 0.001 ) return false ;
@@ -288,7 +300,7 @@ bool INA219::setMaxCurrentShunt(float maxCurrent, float shunt)
288300
289301// //////////////////////////////////////////////////////
290302//
291- // PRIVATE
303+ // PRIVATE
292304//
293305
294306uint16_t INA219::_readRegister (uint8_t reg)
@@ -315,5 +327,5 @@ uint16_t INA219::_writeRegister(uint8_t reg, uint16_t value)
315327}
316328
317329
318- // -- END OF FILE --
330+ // -- END OF FILE --
319331
0 commit comments