diff --git a/.clang-format b/.clang-format index 946ecd9..f40d764 100644 --- a/.clang-format +++ b/.clang-format @@ -3,27 +3,25 @@ ## ## ## Date Developer Description ## ## ========== ========== =====================================================## -## 2020-06-30 SV-Zanshin Changed indentation ## +## 2020-07-03 SV-Zanshin Removed several options not present in Travis-CI ## +## 2020-06-28 SV-Zanshin Changed indentation ## ## ## ################################################################################ --- Language: Cpp AccessModifierOffset: -1 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: true AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true -AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: Never +AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: All -AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse +#AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None @@ -32,7 +30,6 @@ AlwaysBreakTemplateDeclarations: Yes BinPackArguments: true BinPackParameters: true BraceWrapping: - AfterCaseLabel: false AfterClass: false AfterControlStatement: false AfterEnum: false @@ -58,13 +55,12 @@ BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 100 -CommentPragmas: '^\\.+' +CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DeriveLineEnding: true DerivePointerAlignment: true DisableFormat: false ExperimentalAutoDetectBinPacking: false @@ -77,20 +73,14 @@ IncludeBlocks: Regroup IncludeCategories: - Regex: '^' Priority: 2 - SortPriority: 0 - Regex: '^<.*\.h>' Priority: 1 - SortPriority: 0 - Regex: '^<.*' Priority: 2 - SortPriority: 0 - Regex: '.*' Priority: 3 - SortPriority: 0 IncludeIsMainRegex: '([-_](test|unittest))?$' -IncludeIsMainSourceRegex: '' IndentCaseLabels: true -IndentGotoLabels: true IndentPPDirectives: None IndentWidth: 2 IndentWrappedFunctionNames: false @@ -146,7 +136,6 @@ ReflowComments: true SortIncludes: true SortUsingDeclarations: true SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeCpp11BracedList: false @@ -154,22 +143,14 @@ SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 SpacesInAngles: false -#SpacesInConditionalStatement: false SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false Standard: Auto -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION TabWidth: 8 -UseCRLF: false UseTab: Never ... - diff --git a/.travis.yml b/.travis.yml index 943c1c4..39a5218 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,45 @@ ###################################################################################################### ## Travis-CI control file ## ## ## -## Date Developer Comments ## -## ========== =================== ================================================================= ## -## 2020-05-11 Arnd@SV-Zanshin Removed Adafruit libraries which now caused Travis to fail ## -## 2020-05-03 Arnd@SV-Zanshin Commented out Adafruit libraries which now caused Travis to fail ## -## 2019-01-20 Arnd@SV-Zanshin Linked to Adafruit script rather than manually defining all tests ## -## 2019-01-19 Arnd@SV-Zanshin Initial coding ## +## Date Developer Comments ## +## ========== ========== ========================================================================== ## +## 2020-07-12 SV-Zanshin Commented out the "cache:" section, as that was causing the build to fail ## +## 2020-07-03 SV-Zanshin Added elements to call "clang-format" to make sure formatting is correct ## +## 2020-05-11 SV-Zanshin Removed Adafruit libraries which now caused Travis to fail ## +## 2020-05-03 SV-Zanshin Commented out Adafruit libraries which now caused Travis to fail ## +## 2019-01-20 SV-Zanshin Linked to Adafruit script rather than manually defining all tests ## +## 2019-01-19 SV-Zanshin Initial coding ## ## ## ###################################################################################################### language: c sudo: false -# Blacklist +######################################################### +# Keep the gh-pages from being included in the CI runs ## +######################################################### branches: except: - gh-pages - + +#cache: +# directories: +# - ~/arduino_ide +# - ~/.arduino15/packages/ + git: depth: false quiet: true + +addons: + apt: + sources: + - llvm-toolchain-trusty-5.0 + - key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key' + packages: + - python3-pip + - python3-wheel + - clang-format-5.0 + env: global: - PRETTYNAME="SV-Zanshin INA2xx Arduino Library" @@ -27,10 +47,13 @@ env: before_install: - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) + - curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/run-clang-format.py > run-clang-format.py + install: script: + - python run-clang-format.py -r . - build_main_platforms notifications: @@ -38,5 +61,8 @@ notifications: on_success: change on_failure: change +########################################################### +# Generate the Doxygen documentation upon successful run ## +########################################################### after_success: - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh) diff --git a/Doxyfile b/Doxyfile index 70bd582..c6bed5a 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1,15 +1,16 @@ ###################################################################################################### ## Doxygen control file for Version 1.8.16 ## ## ## -## Date Developer Comments ## -## ========== =================== ================================================================= ## -## 2020-06-06 Arnd@SV-Zanshin Updated to version v1.0.11 ## -## 2020-05-10 Arnd@SV-Zanshin Removed all comments in order to compact this file ## +## Date Developer Comments ## +## ========== ============== ====================================================================== ## +## 2020-06-30 SV-Zanshin Updated to version v1.0.12 ## +## 2020-06-06 SV-Zanshin Updated to version v1.0.11 ## +## 2020-05-10 SV-Zanshin Removed all comments in order to compact this file ## ## ## ###################################################################################################### DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = INA2xx -PROJECT_NUMBER = "Version 1.0.11" +PROJECT_NUMBER = "Version 1.0.12" PROJECT_BRIEF = "Arduino Library for INA2xx power measurement devices" PROJECT_LOGO = images/horizontal_narrow_small.png OUTPUT_DIRECTORY = diff --git a/examples/DisplayReadings/DisplayReadings.ino b/examples/DisplayReadings/DisplayReadings.ino index 2a801fb..a72d03e 100644 --- a/examples/DisplayReadings/DisplayReadings.ino +++ b/examples/DisplayReadings/DisplayReadings.ino @@ -98,7 +98,7 @@ void setup() { #ifdef __AVR_ATmega32U4__ // If a 32U4 processor, then wait 2 seconds to initialize delay(2000); #endif - Serial.print("\n\nDisplay INA Readings V1.0.6\n"); + Serial.print("\n\nDisplay INA Readings V1.0.7\n"); Serial.print(" - Searching & Initializing INA devices\n"); /************************************************************************************************ ** The INA.begin call initializes the device(s) found with an expected ±1 Amps maximum current ** diff --git a/library.properties b/library.properties index b591c02..05d79fc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=INA2xx -version=1.0.11 +version=1.0.12 author=https://github.com/SV-Zanshin maintainer=https://github.com/SV-Zanshin sentence=Read current and voltage data from multiple INA2xx devices diff --git a/src/INA.cpp b/src/INA.cpp index 4bc52cf..04c9b5b 100644 --- a/src/INA.cpp +++ b/src/INA.cpp @@ -112,15 +112,15 @@ void INA_Class::readInafromEEPROM(const uint8_t deviceNumber) { @param[in] deviceNumber Index to device array */ if (deviceNumber == _currentINA || deviceNumber > _DeviceCount) return; // Skip if correct device #if defined(__AVR__) || defined(CORE_TEENSY) || defined(ESP32) || defined(ESP8266) || (__STM32F1__) -#ifdef __STM32F1__ // STM32F1 has no built-in EEPROM - uint16_t e = deviceNumber * sizeof(inaEE); // it uses flash memory to emulate - uint16_t *ptr = (uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type - for (uint8_t n = sizeof(inaEE); n; --n) // Implement EEPROM.get template +#ifdef __STM32F1__ // STM32F1 has no built-in EEPROM + uint16_t e = deviceNumber * sizeof(inaEE); // it uses flash memory to emulate + uint16_t *ptr = (uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type + for (uint8_t n = sizeof(inaEE) + _EEPROM_offset; n; --n) // Implement EEPROM.get template { EEPROM.read(e++, ptr++); // for ina (inaDet type) } // of for-next each byte #else - EEPROM.get(deviceNumber * sizeof(inaEE), inaEE); // Read EEPROM values to structure + EEPROM.get(_EEPROM_offset + (deviceNumber * sizeof(inaEE)), inaEE); // Read EEPROM values #endif #else inaEE = _EEPROMEmulation[deviceNumber]; @@ -135,17 +135,17 @@ void INA_Class::writeInatoEEPROM(const uint8_t deviceNumber) { @param[in] deviceNumber Index to device array */ inaEE = ina; // only save relevant part of ina to EEPROM #if defined(__AVR__) || defined(CORE_TEENSY) || defined(ESP32) || defined(ESP8266) || (__STM32F1__) -#ifdef __STM32F1__ // STM32F1 has no built-in EEPROM - uint16_t e = deviceNumber * sizeof(inaEE); // it uses flash memory to emulate - const uint16_t *ptr = (const uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type - for (uint8_t n = sizeof(inaEE); n; --n) // Implement EEPROM.put template +#ifdef __STM32F1__ // STM32F1 has no built-in EEPROM + uint16_t e = deviceNumber * sizeof(inaEE); // it uses flash memory to emulate + const uint16_t *ptr = (const uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type + for (uint8_t n = sizeof(inaEE) + _EEPROM_offset; n; --n) // Implement EEPROM.put template { EEPROM.update(e++, *ptr++); // for ina (inaDet type) } // for-next #else - EEPROM.put(deviceNumber * sizeof(inaEE), inaEE); // Write the structure + EEPROM.put(_EEPROM_offset + (deviceNumber * sizeof(inaEE)), inaEE); // Write the structure #ifdef ESP32 - EEPROM.commit(); // Force write to EEPROM when ESP32 + EEPROM.commit(); // Force write to EEPROM when ESP32 #endif #endif #else @@ -189,14 +189,14 @@ uint8_t INA_Class::begin(const uint16_t maxBusAmps, const uint32_t microOhmR, ** RAM available at runtime to allocate sufficient space for 32 devices. ** **********************************************************************************************/ #if defined(ESP32) || defined(ESP8266) - EEPROM.begin(512); // If ESP32 then allocate 512 Bytes - maxDevices = 512 / sizeof(inaEE); // and compute number of devices -#elif defined(__STM32F1__) // Emulated EEPROM for STM32F1 - maxDevices = EEPROM.maxcount() / sizeof(inaEE); // Compute number devices possible -#elif defined(CORE_TEENSY) // TEENSY doesn't have EEPROM.length - maxDevices = 2048 / sizeof(inaEE); // defined, so use 2Kb as value + EEPROM.begin(512); // If ESP32 then allocate 512 Bytes + maxDevices = (_EEPROM_offset + 512) / sizeof(inaEE); // and compute number of devices +#elif defined(__STM32F1__) // Emulated EEPROM for STM32F1 + maxDevices = (_EEPROM_offset + EEPROM.maxcount()) / sizeof(inaEE); // Compute max possible +#elif defined(CORE_TEENSY) // TEENSY doesn't have EEPROM.length + maxDevices = (_EEPROM_offset + 2048) / sizeof(inaEE); // defined, so use 2Kb as value #elif defined(__AVR__) - maxDevices = EEPROM.length() / sizeof(inaEE); // Compute number devices possible + maxDevices = (_EEPROM_offset + EEPROM.length()) / sizeof(inaEE); // Compute max possible #else maxDevices = 32; #endif @@ -604,9 +604,11 @@ int32_t INA_Class::getBusMicroAmps(const uint8_t deviceNumber) { if (ina.type == INA3221_0 || ina.type == INA3221_1 || ina.type == INA3221_2) // Doesn't compute Amps { - microAmps = getShuntMicroVolts(deviceNumber) * ((int32_t)1000000 / (int32_t)ina.microOhmR); + microAmps = + (int64_t)getShuntMicroVolts(deviceNumber) * ((int64_t)1000000 / (int64_t)ina.microOhmR); } else { - microAmps = (int64_t)readWord(ina.currentRegister, ina.address) * ina.current_LSB / 1000; + microAmps = (int64_t)readWord(ina.currentRegister, ina.address) * (int64_t)ina.current_LSB / + (int64_t)1000; } // of if-then-else an INA3221 return (microAmps); } // of method getBusMicroAmps() @@ -623,10 +625,12 @@ int64_t INA_Class::getBusMicroWatts(const uint8_t deviceNumber) { if (ina.type == INA3221_0 || ina.type == INA3221_1 || ina.type == INA3221_2) // Doesn't compute Amps { - microWatts = (getShuntMicroVolts(deviceNumber) * 1000000 / ina.microOhmR) * - getBusMilliVolts(deviceNumber) / 1000; + microWatts = + ((int64_t)getShuntMicroVolts(deviceNumber) * (int64_t)1000000 / (int64_t)ina.microOhmR) * + (int64_t)getBusMilliVolts(deviceNumber) / (int64_t)1000; } else { - microWatts = (int64_t)readWord(INA_POWER_REGISTER, ina.address) * ina.power_LSB / 1000; + microWatts = + (int64_t)readWord(INA_POWER_REGISTER, ina.address) * (int64_t)ina.power_LSB / (int64_t)1000; } // of if-then-else an INA3221 return (microWatts); } // of method getBusMicroWatts() diff --git a/src/INA.h b/src/INA.h index 4df0aef..472faae 100644 --- a/src/INA.h +++ b/src/INA.h @@ -77,6 +77,8 @@ * * Version | Date | Developer | Comments * ------- | ---------- | ----------- | -------- + * 1.0.12 | 2020-07-03 | SV-Zanshin | Issue #41. Added "_EEPROM_offset" variable + * 1.0.12 | 2020-07-03 | sages | Issue #60. Possible Overflow getBus(MicroAmps,MicroWatts) * 1.0.11 | 2020-06-30 | SV-Zanshin | Issue #58, changed formatting to use clang-format * 1.0.11 | 2020-06-29 | SV-Zanshin | Issue #57. "Alert..." functions should be "alert..." * 1.0.11 | 2020-05-05 | oliverb68 | Issue #56. Limit of +/- 2kW on getBusMicroWatts @@ -288,7 +290,7 @@ class INA_Class { const uint8_t deviceNumber = UINT8_MAX); bool alertOnPowerOverLimit(const bool alertState, const int32_t milliAmps, const uint8_t deviceNumber = UINT8_MAX); - + uint16_t _EEPROM_offset = 0; ///< Offset to all EEPROM addresses, GitHub issue #41 private: int16_t readWord(const uint8_t addr, const uint8_t deviceAddress); void writeWord(const uint8_t addr, const uint16_t data, const uint8_t deviceAddress);