Skip to content

Commit 154d500

Browse files
author
Arnd
authored
Merge pull request #61 from SV-Zanshin/Development_v1.0.12
Development v1.0.12
2 parents 53a904e + 817ff5e commit 154d500

File tree

7 files changed

+78
-64
lines changed

7 files changed

+78
-64
lines changed

.clang-format

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@
33
## ##
44
## Date Developer Description ##
55
## ========== ========== =====================================================##
6-
## 2020-06-30 SV-Zanshin Changed indentation ##
6+
## 2020-07-03 SV-Zanshin Removed several options not present in Travis-CI ##
7+
## 2020-06-28 SV-Zanshin Changed indentation ##
78
## ##
89
################################################################################
910
---
1011
Language: Cpp
1112
AccessModifierOffset: -1
1213
AlignAfterOpenBracket: Align
13-
AlignConsecutiveMacros: true
1414
AlignConsecutiveAssignments: true
1515
AlignConsecutiveDeclarations: true
1616
AlignEscapedNewlines: Left
1717
AlignOperands: true
1818
AlignTrailingComments: true
19-
AllowAllArgumentsOnNextLine: true
20-
AllowAllConstructorInitializersOnNextLine: true
2119
AllowAllParametersOfDeclarationOnNextLine: true
22-
AllowShortBlocksOnASingleLine: Never
20+
AllowShortBlocksOnASingleLine: false
2321
AllowShortCaseLabelsOnASingleLine: false
2422
AllowShortFunctionsOnASingleLine: All
25-
AllowShortLambdasOnASingleLine: All
26-
AllowShortIfStatementsOnASingleLine: WithoutElse
23+
#AllowShortLambdasOnASingleLine: All
24+
AllowShortIfStatementsOnASingleLine: true
2725
AllowShortLoopsOnASingleLine: true
2826
AlwaysBreakAfterDefinitionReturnType: None
2927
AlwaysBreakAfterReturnType: None
@@ -32,7 +30,6 @@ AlwaysBreakTemplateDeclarations: Yes
3230
BinPackArguments: true
3331
BinPackParameters: true
3432
BraceWrapping:
35-
AfterCaseLabel: false
3633
AfterClass: false
3734
AfterControlStatement: false
3835
AfterEnum: false
@@ -58,13 +55,12 @@ BreakConstructorInitializers: BeforeColon
5855
BreakAfterJavaFieldAnnotations: false
5956
BreakStringLiterals: true
6057
ColumnLimit: 100
61-
CommentPragmas: '^\\.+'
58+
CommentPragmas: '^ IWYU pragma:'
6259
CompactNamespaces: false
6360
ConstructorInitializerAllOnOneLineOrOnePerLine: true
6461
ConstructorInitializerIndentWidth: 4
6562
ContinuationIndentWidth: 4
6663
Cpp11BracedListStyle: true
67-
DeriveLineEnding: true
6864
DerivePointerAlignment: true
6965
DisableFormat: false
7066
ExperimentalAutoDetectBinPacking: false
@@ -77,20 +73,14 @@ IncludeBlocks: Regroup
7773
IncludeCategories:
7874
- Regex: '^<ext/.*\.h>'
7975
Priority: 2
80-
SortPriority: 0
8176
- Regex: '^<.*\.h>'
8277
Priority: 1
83-
SortPriority: 0
8478
- Regex: '^<.*'
8579
Priority: 2
86-
SortPriority: 0
8780
- Regex: '.*'
8881
Priority: 3
89-
SortPriority: 0
9082
IncludeIsMainRegex: '([-_](test|unittest))?$'
91-
IncludeIsMainSourceRegex: ''
9283
IndentCaseLabels: true
93-
IndentGotoLabels: true
9484
IndentPPDirectives: None
9585
IndentWidth: 2
9686
IndentWrappedFunctionNames: false
@@ -146,30 +136,21 @@ ReflowComments: true
146136
SortIncludes: true
147137
SortUsingDeclarations: true
148138
SpaceAfterCStyleCast: false
149-
SpaceAfterLogicalNot: false
150139
SpaceAfterTemplateKeyword: true
151140
SpaceBeforeAssignmentOperators: true
152141
SpaceBeforeCpp11BracedList: false
153142
SpaceBeforeCtorInitializerColon: true
154143
SpaceBeforeInheritanceColon: true
155144
SpaceBeforeParens: ControlStatements
156145
SpaceBeforeRangeBasedForLoopColon: true
157-
SpaceInEmptyBlock: false
158146
SpaceInEmptyParentheses: false
159147
SpacesBeforeTrailingComments: 2
160148
SpacesInAngles: false
161-
#SpacesInConditionalStatement: false
162149
SpacesInContainerLiterals: true
163150
SpacesInCStyleCastParentheses: false
164151
SpacesInParentheses: false
165152
SpacesInSquareBrackets: false
166-
SpaceBeforeSquareBrackets: false
167153
Standard: Auto
168-
StatementMacros:
169-
- Q_UNUSED
170-
- QT_REQUIRE_VERSION
171154
TabWidth: 8
172-
UseCRLF: false
173155
UseTab: Never
174156
...
175-

.travis.yml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,68 @@
11
######################################################################################################
22
## Travis-CI control file ##
33
## ##
4-
## Date Developer Comments ##
5-
## ========== =================== ================================================================= ##
6-
## 2020-05-11 Arnd@SV-Zanshin Removed Adafruit libraries which now caused Travis to fail ##
7-
## 2020-05-03 Arnd@SV-Zanshin Commented out Adafruit libraries which now caused Travis to fail ##
8-
## 2019-01-20 Arnd@SV-Zanshin Linked to Adafruit script rather than manually defining all tests ##
9-
## 2019-01-19 Arnd@SV-Zanshin Initial coding ##
4+
## Date Developer Comments ##
5+
## ========== ========== ========================================================================== ##
6+
## 2020-07-12 SV-Zanshin Commented out the "cache:" section, as that was causing the build to fail ##
7+
## 2020-07-03 SV-Zanshin Added elements to call "clang-format" to make sure formatting is correct ##
8+
## 2020-05-11 SV-Zanshin Removed Adafruit libraries which now caused Travis to fail ##
9+
## 2020-05-03 SV-Zanshin Commented out Adafruit libraries which now caused Travis to fail ##
10+
## 2019-01-20 SV-Zanshin Linked to Adafruit script rather than manually defining all tests ##
11+
## 2019-01-19 SV-Zanshin Initial coding ##
1012
## ##
1113
######################################################################################################
1214
language: c
1315
sudo: false
1416

15-
# Blacklist
17+
#########################################################
18+
# Keep the gh-pages from being included in the CI runs ##
19+
#########################################################
1620
branches:
1721
except:
1822
- gh-pages
19-
23+
24+
#cache:
25+
# directories:
26+
# - ~/arduino_ide
27+
# - ~/.arduino15/packages/
28+
2029
git:
2130
depth: false
2231
quiet: true
32+
33+
addons:
34+
apt:
35+
sources:
36+
- llvm-toolchain-trusty-5.0
37+
- key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key'
38+
packages:
39+
- python3-pip
40+
- python3-wheel
41+
- clang-format-5.0
42+
2343
env:
2444
global:
2545
- PRETTYNAME="SV-Zanshin INA2xx Arduino Library"
2646
- DOXYFILE: $TRAVIS_BUILD_DIR/Doxyfile
2747

2848
before_install:
2949
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
50+
- curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/run-clang-format.py > run-clang-format.py
51+
3052

3153
install:
3254

3355
script:
56+
- python run-clang-format.py -r .
3457
- build_main_platforms
3558

3659
notifications:
3760
email:
3861
on_success: change
3962
on_failure: change
4063

64+
###########################################################
65+
# Generate the Doxygen documentation upon successful run ##
66+
###########################################################
4167
after_success:
4268
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)

Doxyfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
######################################################################################################
22
## Doxygen control file for Version 1.8.16 ##
33
## ##
4-
## Date Developer Comments ##
5-
## ========== =================== ================================================================= ##
6-
## 2020-06-06 Arnd@SV-Zanshin Updated to version v1.0.11 ##
7-
## 2020-05-10 Arnd@SV-Zanshin Removed all comments in order to compact this file ##
4+
## Date Developer Comments ##
5+
## ========== ============== ====================================================================== ##
6+
## 2020-06-30 SV-Zanshin Updated to version v1.0.12 ##
7+
## 2020-06-06 SV-Zanshin Updated to version v1.0.11 ##
8+
## 2020-05-10 SV-Zanshin Removed all comments in order to compact this file ##
89
## ##
910
######################################################################################################
1011
DOXYFILE_ENCODING = UTF-8
1112
PROJECT_NAME = INA2xx
12-
PROJECT_NUMBER = "Version 1.0.11"
13+
PROJECT_NUMBER = "Version 1.0.12"
1314
PROJECT_BRIEF = "Arduino Library for INA2xx power measurement devices"
1415
PROJECT_LOGO = images/horizontal_narrow_small.png
1516
OUTPUT_DIRECTORY =

examples/DisplayReadings/DisplayReadings.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void setup() {
9898
#ifdef __AVR_ATmega32U4__ // If a 32U4 processor, then wait 2 seconds to initialize
9999
delay(2000);
100100
#endif
101-
Serial.print("\n\nDisplay INA Readings V1.0.6\n");
101+
Serial.print("\n\nDisplay INA Readings V1.0.7\n");
102102
Serial.print(" - Searching & Initializing INA devices\n");
103103
/************************************************************************************************
104104
** The INA.begin call initializes the device(s) found with an expected ±1 Amps maximum current **

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=INA2xx
2-
version=1.0.11
2+
version=1.0.12
33
author=https://github.com/SV-Zanshin
44
maintainer=https://github.com/SV-Zanshin
55
sentence=Read current and voltage data from multiple INA2xx devices

src/INA.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ void INA_Class::readInafromEEPROM(const uint8_t deviceNumber) {
112112
@param[in] deviceNumber Index to device array */
113113
if (deviceNumber == _currentINA || deviceNumber > _DeviceCount) return; // Skip if correct device
114114
#if defined(__AVR__) || defined(CORE_TEENSY) || defined(ESP32) || defined(ESP8266) || (__STM32F1__)
115-
#ifdef __STM32F1__ // STM32F1 has no built-in EEPROM
116-
uint16_t e = deviceNumber * sizeof(inaEE); // it uses flash memory to emulate
117-
uint16_t *ptr = (uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type
118-
for (uint8_t n = sizeof(inaEE); n; --n) // Implement EEPROM.get template
115+
#ifdef __STM32F1__ // STM32F1 has no built-in EEPROM
116+
uint16_t e = deviceNumber * sizeof(inaEE); // it uses flash memory to emulate
117+
uint16_t *ptr = (uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type
118+
for (uint8_t n = sizeof(inaEE) + _EEPROM_offset; n; --n) // Implement EEPROM.get template
119119
{
120120
EEPROM.read(e++, ptr++); // for ina (inaDet type)
121121
} // of for-next each byte
122122
#else
123-
EEPROM.get(deviceNumber * sizeof(inaEE), inaEE); // Read EEPROM values to structure
123+
EEPROM.get(_EEPROM_offset + (deviceNumber * sizeof(inaEE)), inaEE); // Read EEPROM values
124124
#endif
125125
#else
126126
inaEE = _EEPROMEmulation[deviceNumber];
@@ -135,17 +135,17 @@ void INA_Class::writeInatoEEPROM(const uint8_t deviceNumber) {
135135
@param[in] deviceNumber Index to device array */
136136
inaEE = ina; // only save relevant part of ina to EEPROM
137137
#if defined(__AVR__) || defined(CORE_TEENSY) || defined(ESP32) || defined(ESP8266) || (__STM32F1__)
138-
#ifdef __STM32F1__ // STM32F1 has no built-in EEPROM
139-
uint16_t e = deviceNumber * sizeof(inaEE); // it uses flash memory to emulate
140-
const uint16_t *ptr = (const uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type
141-
for (uint8_t n = sizeof(inaEE); n; --n) // Implement EEPROM.put template
138+
#ifdef __STM32F1__ // STM32F1 has no built-in EEPROM
139+
uint16_t e = deviceNumber * sizeof(inaEE); // it uses flash memory to emulate
140+
const uint16_t *ptr = (const uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type
141+
for (uint8_t n = sizeof(inaEE) + _EEPROM_offset; n; --n) // Implement EEPROM.put template
142142
{
143143
EEPROM.update(e++, *ptr++); // for ina (inaDet type)
144144
} // for-next
145145
#else
146-
EEPROM.put(deviceNumber * sizeof(inaEE), inaEE); // Write the structure
146+
EEPROM.put(_EEPROM_offset + (deviceNumber * sizeof(inaEE)), inaEE); // Write the structure
147147
#ifdef ESP32
148-
EEPROM.commit(); // Force write to EEPROM when ESP32
148+
EEPROM.commit(); // Force write to EEPROM when ESP32
149149
#endif
150150
#endif
151151
#else
@@ -189,14 +189,14 @@ uint8_t INA_Class::begin(const uint16_t maxBusAmps, const uint32_t microOhmR,
189189
** RAM available at runtime to allocate sufficient space for 32 devices. **
190190
**********************************************************************************************/
191191
#if defined(ESP32) || defined(ESP8266)
192-
EEPROM.begin(512); // If ESP32 then allocate 512 Bytes
193-
maxDevices = 512 / sizeof(inaEE); // and compute number of devices
194-
#elif defined(__STM32F1__) // Emulated EEPROM for STM32F1
195-
maxDevices = EEPROM.maxcount() / sizeof(inaEE); // Compute number devices possible
196-
#elif defined(CORE_TEENSY) // TEENSY doesn't have EEPROM.length
197-
maxDevices = 2048 / sizeof(inaEE); // defined, so use 2Kb as value
192+
EEPROM.begin(512); // If ESP32 then allocate 512 Bytes
193+
maxDevices = (_EEPROM_offset + 512) / sizeof(inaEE); // and compute number of devices
194+
#elif defined(__STM32F1__) // Emulated EEPROM for STM32F1
195+
maxDevices = (_EEPROM_offset + EEPROM.maxcount()) / sizeof(inaEE); // Compute max possible
196+
#elif defined(CORE_TEENSY) // TEENSY doesn't have EEPROM.length
197+
maxDevices = (_EEPROM_offset + 2048) / sizeof(inaEE); // defined, so use 2Kb as value
198198
#elif defined(__AVR__)
199-
maxDevices = EEPROM.length() / sizeof(inaEE); // Compute number devices possible
199+
maxDevices = (_EEPROM_offset + EEPROM.length()) / sizeof(inaEE); // Compute max possible
200200
#else
201201
maxDevices = 32;
202202
#endif
@@ -604,9 +604,11 @@ int32_t INA_Class::getBusMicroAmps(const uint8_t deviceNumber) {
604604
if (ina.type == INA3221_0 || ina.type == INA3221_1 ||
605605
ina.type == INA3221_2) // Doesn't compute Amps
606606
{
607-
microAmps = getShuntMicroVolts(deviceNumber) * ((int32_t)1000000 / (int32_t)ina.microOhmR);
607+
microAmps =
608+
(int64_t)getShuntMicroVolts(deviceNumber) * ((int64_t)1000000 / (int64_t)ina.microOhmR);
608609
} else {
609-
microAmps = (int64_t)readWord(ina.currentRegister, ina.address) * ina.current_LSB / 1000;
610+
microAmps = (int64_t)readWord(ina.currentRegister, ina.address) * (int64_t)ina.current_LSB /
611+
(int64_t)1000;
610612
} // of if-then-else an INA3221
611613
return (microAmps);
612614
} // of method getBusMicroAmps()
@@ -623,10 +625,12 @@ int64_t INA_Class::getBusMicroWatts(const uint8_t deviceNumber) {
623625
if (ina.type == INA3221_0 || ina.type == INA3221_1 ||
624626
ina.type == INA3221_2) // Doesn't compute Amps
625627
{
626-
microWatts = (getShuntMicroVolts(deviceNumber) * 1000000 / ina.microOhmR) *
627-
getBusMilliVolts(deviceNumber) / 1000;
628+
microWatts =
629+
((int64_t)getShuntMicroVolts(deviceNumber) * (int64_t)1000000 / (int64_t)ina.microOhmR) *
630+
(int64_t)getBusMilliVolts(deviceNumber) / (int64_t)1000;
628631
} else {
629-
microWatts = (int64_t)readWord(INA_POWER_REGISTER, ina.address) * ina.power_LSB / 1000;
632+
microWatts =
633+
(int64_t)readWord(INA_POWER_REGISTER, ina.address) * (int64_t)ina.power_LSB / (int64_t)1000;
630634
} // of if-then-else an INA3221
631635
return (microWatts);
632636
} // of method getBusMicroWatts()

src/INA.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
*
7878
* Version | Date | Developer | Comments
7979
* ------- | ---------- | ----------- | --------
80+
* 1.0.12 | 2020-07-03 | SV-Zanshin | Issue #41. Added "_EEPROM_offset" variable
81+
* 1.0.12 | 2020-07-03 | sages | Issue #60. Possible Overflow getBus(MicroAmps,MicroWatts)
8082
* 1.0.11 | 2020-06-30 | SV-Zanshin | Issue #58, changed formatting to use clang-format
8183
* 1.0.11 | 2020-06-29 | SV-Zanshin | Issue #57. "Alert..." functions should be "alert..."
8284
* 1.0.11 | 2020-05-05 | oliverb68 | Issue #56. Limit of +/- 2kW on getBusMicroWatts
@@ -288,7 +290,7 @@ class INA_Class {
288290
const uint8_t deviceNumber = UINT8_MAX);
289291
bool alertOnPowerOverLimit(const bool alertState, const int32_t milliAmps,
290292
const uint8_t deviceNumber = UINT8_MAX);
291-
293+
uint16_t _EEPROM_offset = 0; ///< Offset to all EEPROM addresses, GitHub issue #41
292294
private:
293295
int16_t readWord(const uint8_t addr, const uint8_t deviceAddress);
294296
void writeWord(const uint8_t addr, const uint16_t data, const uint8_t deviceAddress);

0 commit comments

Comments
 (0)