From 210ddf572a590523fcd33c40691c5a6e50f36bb8 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Wed, 14 Aug 2024 16:58:59 +0200 Subject: [PATCH] Fix getShuntVoltage() --- CHANGELOG.md | 7 +++++++ INA219.cpp | 9 ++++++++- INA219.h | 13 +++++++++---- README.md | 12 ++++++++++-- keywords.txt | 1 + library.json | 2 +- library.properties | 2 +- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8c26bd..8d72e13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.4.0] - 2024-08-14 +- fix **float getShuntVoltage()** for negative values, kudos to aguilerabr +- add **int getMaxShuntVoltage()**, depends on GAIN (Table 7). +- removed default for **setGain()** as it was not sensors default. + +---- + ## [0.3.1] - 2024-04-22 - Bump version after Fix #17, Kudos to ChrisRed255 diff --git a/INA219.cpp b/INA219.cpp index d292cef..df5a419 100644 --- a/INA219.cpp +++ b/INA219.cpp @@ -1,6 +1,6 @@ // FILE: INA219.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.1 +// VERSION: 0.4.0 // DATE: 2021-05-18 // PURPOSE: Arduino library for INA219 voltage, current and power sensor // URL: https://github.com/RobTillaart/INA219 @@ -187,6 +187,13 @@ uint8_t INA219::getGain() } +int INA219::getMaxShuntVoltage() +{ + int gain = getGain(); // 1, 2, 4, 8 + return gain * 40; // 40, 80, 160, 320 +} + + //////////////////////////////////////////////////////// // // BUS diff --git a/INA219.h b/INA219.h index 772e6f3..40d919b 100644 --- a/INA219.h +++ b/INA219.h @@ -1,7 +1,7 @@ #pragma once // FILE: INA219.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.1 +// VERSION: 0.4.0 // DATE: 2021-05-18 // PURPOSE: Arduino library for INA219 voltage, current and power sensor // URL: https://github.com/RobTillaart/INA219 @@ -13,7 +13,7 @@ #include "Wire.h" -#define INA219_LIB_VERSION (F("0.3.1")) +#define INA219_LIB_VERSION (F("0.4.0")) class INA219 @@ -54,9 +54,14 @@ class INA219 // voltage = 16, 32 (values below 32 are rounded to 16 or 32) bool setBusVoltageRange(uint8_t voltage = 16); uint8_t getBusVoltageRange(); // returns 16 or 32. - // factor = 1, 2, 4, 8 - bool setGain(uint8_t factor = 1); + // factor = 1, 2, 4, 8 (8 = sensor default) + bool setGain(uint8_t factor); // removed default parameter. uint8_t getGain(); + // MaxShuntVoltagedepends on GAIN, + // See Table 7. Shunt Voltage Register Format + // default = 320. + int getMaxShuntVoltage(); + // configuration BUS // use one of the next three diff --git a/README.md b/README.md index 4cd084c..18d6a97 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ A few important maxima, see datasheet, chapter 7, esp 7.5 +#### 0.4.0 Breaking change + +Version 0.4.0 fixed negative values for **getShuntVoltage()**. +Older versions are obsolete now. + + #### 0.2.0 Breaking change Version 0.2.0 introduced a breaking change. @@ -146,14 +152,16 @@ See section below. Returns false if it could not write settings to device. - **bool setBusVoltageRange(uint8_t voltage = 16)** set to 16 or 32. Values <= 16 map to 16 and values between 16 and 32 map to 32. -Returns false if voltage is above 32.. +Returns false if voltage is above 32. Returns false if it could not write settings to device. - **uint8_t getBusVoltageRange()** returns 16 or 32. (Volts) -- **bool setGain(uint8_t factor = 1)** factor = 1, 2, 4, 8. +- **bool setGain(uint8_t factor)** factor = 1, 2, 4, 8 (default). Determines the shunt voltage range. 40, 80, 160 or 320 mV. Returns false if factor is not a valid value. Returns false if it could not write settings to device. - **uint8_t getGain()** returns set factor. +- **int getMaxShuntVoltage()** returns 40, 80, 160 or 320 (default). +Value in millivolts mV. #### Configuration BUS and SHUNT diff --git a/keywords.txt b/keywords.txt index 3dda43c..ac8fafd 100644 --- a/keywords.txt +++ b/keywords.txt @@ -32,6 +32,7 @@ setBusVoltageRange KEYWORD2 getBusVoltageRange KEYWORD2 setGain KEYWORD2 getGain KEYWORD2 +getMaxShuntVoltage KEYWORD2 setBusResolution KEYWORD2 setBusSamples KEYWORD2 diff --git a/library.json b/library.json index f6faccf..5a50cd0 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/INA219.git" }, - "version": "0.3.1", + "version": "0.4.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 99a7b64..9f1901f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=INA219 -version=0.3.1 +version=0.4.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for INA219 voltage, current and power sensor.