diff --git a/libraries/Angle/Warning.txt b/libraries/Angle/Warning.txt deleted file mode 100644 index 91a29ae3..00000000 --- a/libraries/Angle/Warning.txt +++ /dev/null @@ -1,10 +0,0 @@ - -2015-10-19: version 0.1.06 -ug has been fixed but needs to be verified - -2015-10-18: version 0.1.05 -A serious bug has been found for negative angles. -Do not use this lib until an update is available. -(use at own risk) - -Sorry for the inconvenience. diff --git a/libraries/Cozir/test/unit_test_001.cpp b/libraries/Cozir/test/unit_test_001.cpp index 4e6a3224..8a901f91 100644 --- a/libraries/Cozir/test/unit_test_001.cpp +++ b/libraries/Cozir/test/unit_test_001.cpp @@ -3,23 +3,33 @@ // AUTHOR: Rob Tillaart // DATE: 2020-12-03 // PURPOSE: unit tests for the Cozir CO2 library -// https://github.com/RobTillaart/ +// https://github.com/RobTillaart/Cozir // https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md // // supported assertions // https://github.com/Arduino-CI/arduino_ci/blob/master/cpp/unittest/Assertion.h#L33-L42 // ---------------------------- -// assertEqual(expected, actual) -// assertNotEqual(expected, actual) -// assertLess(expected, actual) -// assertMore(expected, actual) -// assertLessOrEqual(expected, actual) -// assertMoreOrEqual(expected, actual) -// assertTrue(actual) -// assertFalse(actual) -// assertNull(actual) -// assertNotNull(actual) +// assertEqual(expected, actual); // a == b +// assertNotEqual(unwanted, actual); // a != b +// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b)) +// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b)) +// assertLess(upperBound, actual); // a < b +// assertMore(lowerBound, actual); // a > b +// assertLessOrEqual(upperBound, actual); // a <= b +// assertMoreOrEqual(lowerBound, actual); // a >= b +// assertTrue(actual); +// assertFalse(actual); +// assertNull(actual); + +// // special cases for floats +// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon +// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon +// assertInfinity(actual); // isinf(a) +// assertNotInfinity(actual); // !isinf(a) +// assertNAN(arg); // isnan(a) +// assertNotNAN(arg); // !isnan(a) + #include @@ -60,6 +70,7 @@ unittest(test_software_serial) assertEqual("K 2\r\n", state->digitalPin[transmitPin].toAscii(1, bigEndian)); } + unittest(test_constructor) { GodmodeState* state = GODMODE(); @@ -269,6 +280,18 @@ unittest(test_streaming_mode) co.SetOutputFields(CZR_HUMIDITY | CZR_RAWTEMP | CZR_RAWCO2); assertEqual("M 4226\r\n", state->serialPort[0].dataOut); + fprintf(stderr, "COZIR.GetRecentFields()\n"); + state->serialPort[0].dataIn = ""; + state->serialPort[0].dataOut = ""; + co.GetRecentFields(); + assertEqual("Q\r\n", state->serialPort[0].dataOut); + + fprintf(stderr, "COZIR.ClrOutputFields()\n"); + state->serialPort[0].dataIn = ""; + state->serialPort[0].dataOut = ""; + co.ClrOutputFields(); + assertEqual("M 1\r\n", state->serialPort[0].dataOut); + fprintf(stderr, "COZIR.GetRecentFields()\n"); state->serialPort[0].dataIn = ""; state->serialPort[0].dataOut = ""; @@ -306,6 +329,27 @@ unittest(test_eeprom) +unittest(test_PPM) +{ + GodmodeState* state = GODMODE(); + + COZIR co(&Serial); + + fprintf(stderr, "COZIR.init()\n"); + state->serialPort[0].dataIn = ""; + state->serialPort[0].dataOut = ""; + co.init(); + assertEqual("K 2\r\n", state->serialPort[0].dataOut); + + fprintf(stderr, "COZIR.getPPMFactor()\n"); + state->serialPort[0].dataIn = ""; + state->serialPort[0].dataOut = ""; + co.getPPMFactor(); + assertEqual(".\r\n", state->serialPort[0].dataOut); +} + + + unittest_main() // -------- diff --git a/libraries/Currency/.arduino-ci.yml b/libraries/Currency/.arduino-ci.yml new file mode 100644 index 00000000..ff5659b9 --- /dev/null +++ b/libraries/Currency/.arduino-ci.yml @@ -0,0 +1,7 @@ +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + - uno + - leonardo + - due + - zero diff --git a/libraries/Currency/.github/workflows/arduino_test_runner.yml b/libraries/Currency/.github/workflows/arduino_test_runner.yml new file mode 100644 index 00000000..476456bb --- /dev/null +++ b/libraries/Currency/.github/workflows/arduino_test_runner.yml @@ -0,0 +1,13 @@ +--- +name: Arduino CI + +on: [push, pull_request] + +jobs: + arduino_ci: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: Arduino-CI/action@master + # Arduino-CI/action@v0.1.1 diff --git a/libraries/Currency/LICENSE b/libraries/Currency/LICENSE new file mode 100644 index 00000000..a8b455d0 --- /dev/null +++ b/libraries/Currency/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021-2021 Rob Tillaart + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/libraries/Currency/README.md b/libraries/Currency/README.md new file mode 100644 index 00000000..3a93b149 --- /dev/null +++ b/libraries/Currency/README.md @@ -0,0 +1,87 @@ + +[![Arduino CI](https://github.com/RobTillaart/currency/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/currency/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/currency.svg?maxAge=3600)](https://github.com/RobTillaart/currency/releases) + + + +# Currency + +Arduino library to help formatting integers for printing as currency + +## Warning: experimental + + +## Description + +The currency library contains a number of functions that help to print +integers as currency. + +The currency functions assume you do the currency math in integer units. +For dollars and euro's this would be cents. For numbers with more decimals +it is a smaller unit. + +Using integers makes addition, subtraction and multiplication exact. + +Choosing int32_t as 'base' also means that there is a limit in terms +of minimum and maximum values. When large amounts are needed one can +use the currency64() or one of its derived formatters as this is based +upon int64_t numbers. + +There is a relation with the printhelpers class - https://github.com/RobTillaart/printHelpers +When this library has matured it might be merged with it. + + +## Interface + +The following functions are implemented: + + +### Core function + +- **char \* currency(int32_t value, uint8_t decimals, char decimalseparator, char thousandseparator, char symbol);** +- **char \* currency64(int64_t value, uint8_t decimals, char decimalseparator, char thousandseparator, char symbol);** + + +### int32 Wrapper functions + +- **char \* bitcoin(int32_t value)** +- **char \* dollar(int32_t value)** +- **char \* euro(int32_t value)** +- **char \* roebel(int32_t value)** +- **char \* yen(int32_t value)** +- **char \* yuan(int32_t value)** + + +### int64 Wrapper functions + +- **char \* bitcoin64(int64_t value)** +- **char \* dollar64(int64_t value)** +- **char \* euro64(int64_t value)** +- **char \* roebel64(int64_t value)** +- **char \* yen64(int64_t value)** +- **char \* yuan64(int64_t value)** + + +### float Wrapper functions + +Even more experimental - not tested + +- **char \* bitcoinf(double value)** +- **char \* dollarf(double value)** +- **char \* eurof(double value)** +- **char \* roebelf(double value)** +- **char \* yenf(double value)** +- **char \* yuanf(double value)** + + +## Future + +- More wrapper functions? +- test double parameters. + + +## Operation + +See examples + diff --git a/libraries/Currency/currency.h b/libraries/Currency/currency.h new file mode 100644 index 00000000..ec62d881 --- /dev/null +++ b/libraries/Currency/currency.h @@ -0,0 +1,132 @@ +#pragma once + +// +// FILE: currency.h +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: Currency library for Arduino +// URL: https://github.com/RobTillaart/Currency + +// HISTORY +// 0.1.0 2021-02-27 initial version + + +#include "Arduino.h" + + +#define CURRENCY_VERSION (F("0.1.0")) + + +// TODO +// optimize this 99% same code currency - currency64 +// print to string and "merge" with formatters? +// +// ALT-0165 = Â¥ +// ALT-0128 = € +// U+20BF = Bitcoin + + +char * currency(int32_t value, int decimals, char dsep, char tsep, char sym) +{ + static char tmp[16]; + int idx = 0; + + int32_t v = value; + bool neg = v < 0; + if (neg) v = -v; + + int p = -decimals; // decimal places + + while ((p < 1) || ( v > 0)) + { + // separators + if ((p == 0) && (decimals > 0) ) tmp[idx++] = dsep; + if ((p > 0) && (p % 3 == 0) && (v > 0)) tmp[idx++] = tsep; + + int d = (v % 10) + '0'; + v /= 10; + tmp[idx++] = d; + p++; + } + if (neg) tmp[idx++] = '-'; + else tmp[idx++] = ' '; + tmp[idx++] = sym; + tmp[idx] = 0; + + // reverse string + int len = strlen(tmp); + for (int i = 0; i < len / 2; i++) + { + char c = tmp[i]; + tmp[i] = tmp[len - i - 1]; + tmp[len - i - 1] = c; + } + return tmp; +} + + +char * currency64(int64_t value, int decimals, char dsep, char tsep, char sym) +{ + static char tmp[32]; + int idx = 0; + + int64_t v = value; + bool neg = v < 0; + if (neg) v = -v; + + int p = -decimals; // decimal places + + while ((p < 1) || ( v > 0)) + { + // separators + if ((p == 0) && (decimals > 0) ) tmp[idx++] = dsep; + if ((p > 0) && (p % 3 == 0) && (v > 0)) tmp[idx++] = tsep; + + int d = (v % 10) + '0'; + v /= 10; + tmp[idx++] = d; + p++; + } + if (neg) tmp[idx++] = '-'; + else tmp[idx++] = ' '; + tmp[idx++] = sym; + tmp[idx] = 0; + + // reverse string + int len = strlen(tmp); + for (int i = 0; i < len / 2; i++) + { + char c = tmp[i]; + tmp[i] = tmp[len - i - 1]; + tmp[len - i - 1] = c; + } + return tmp; +} + + +// +// DERIVED FUNCTIONS +// +char * bitcoin(int32_t value) { return currency(value, 6, '.', ',', 'B'); } +char * dollar(int32_t value) { return currency(value, 2, '.', ',', '$'); } +char * euro(int32_t value) { return currency(value, 2, ',', '.', 'E'); } +char * roebel(int32_t value) { return currency(value, 2, ',', '.', 'P'); } +char * yen(int32_t value) { return currency(value, 2, '.', ',', 'Y'); } +char * yuan(int32_t value) { return currency(value, 2, '.', ',', 'R'); } + +char * bitcoin64(int64_t value) { return currency64(value, 6, '.', ',', 'B'); } +char * dollar64(int64_t value) { return currency64(value, 2, '.', ',', '$'); } +char * euro64(int64_t value) { return currency64(value, 2, ',', '.', 'E'); } +char * roebel64(int64_t value) { return currency64(value, 2, ',', '.', 'P'); } +char * yen64(int64_t value) { return currency64(value, 2, '.', ',', 'Y'); } +char * yuan64(int64_t value) { return currency64(value, 2, '.', ',', 'R'); } + +char * bitcoinf(double value) { return currency64(round(value * 1000000), 6, '.', ',', 'B'); } +char * dollarf(double value) { return currency64(round(value * 100), 2, '.', ',', '$'); } +char * eurof(double value) { return currency64(round(value * 100), 2, ',', '.', 'E'); } +char * roebelf(double value) { return currency64(round(value * 100), 2, ',', '.', 'P'); } +char * yenf(double value) { return currency64(round(value * 100), 2, '.', ',', 'Y'); } +char * yuanf(double value) { return currency64(round(value * 100), 2, '.', ',', 'R'); } + + +// -- END OF FILE -- diff --git a/libraries/Currency/examples/print_currency/print_currency.ino b/libraries/Currency/examples/print_currency/print_currency.ino new file mode 100644 index 00000000..e2b114d0 --- /dev/null +++ b/libraries/Currency/examples/print_currency/print_currency.ino @@ -0,0 +1,83 @@ +// +// FILE: print_currency.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: display an int as currency +// DATE: 2021-02-28 +// URL: https://github.com/RobTillaart/printFormatters + + +#include "Arduino.h" +#include "currency.h" + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.println(); + + Serial.println( currency(10000000, 0, '.', ',', '$') ); + Serial.println( currency(10000000, 1, '.', ',', 'E') ); + Serial.println( currency(10000000, 2, '.', ',', 'Y') ); + Serial.println( currency(10000000, 3, '.', ',', '$') ); + Serial.println( currency(10000000, 4, '.', ',', '$') ); + Serial.println(); + + Serial.println( currency(0, 2, '.', ',', '$') ); + Serial.println( currency(9, 2, '.', ',', '$') ); + Serial.println( currency(10, 2, '.', ',', '$') ); + Serial.println( currency(99, 2, '.', ',', '$') ); + Serial.println( currency(100, 2, '.', ',', '$') ); + Serial.println( currency(999, 2, '.', ',', '$') ); + Serial.println( currency(1000, 2, '.', ',', '$') ); + Serial.println( currency(9999, 2, '.', ',', '$') ); + Serial.println( currency(10000, 2, '.', ',', '$') ); + Serial.println( currency(99999, 2, '.', ',', '$') ); + Serial.println( currency(100000, 2, '.', ',', '$') ); + Serial.println( currency(999999, 2, '.', ',', '$') ); + Serial.println( currency(1000000, 2, '.', ',', '$') ); + Serial.println( currency(9999999, 2, '.', ',', '$') ); + Serial.println( currency(10000000, 2, '.', ',', '$') ); + Serial.println( currency(99999999, 2, '.', ',', '$') ); + Serial.println( currency(100000000, 2, '.', ',', '$') ); + Serial.println( currency(999999999, 2, '.', ',', '$') ); + Serial.println( currency(1000000000, 2, '.', ',', '$') ); + Serial.println(); + + Serial.println( currency(-0, 2, '.', ',', '$') ); + Serial.println( currency(-9, 2, '.', ',', '$') ); + Serial.println( currency(-10, 2, '.', ',', '$') ); + Serial.println( currency(-99, 2, '.', ',', '$') ); + Serial.println( currency(-100, 2, '.', ',', '$') ); + Serial.println( currency(-999, 2, '.', ',', '$') ); + Serial.println( currency(-1000, 2, '.', ',', '$') ); + Serial.println( currency(-9999, 2, '.', ',', '$') ); + Serial.println( currency(-10000, 2, '.', ',', '$') ); + Serial.println( currency(-99999, 2, '.', ',', '$') ); + Serial.println( currency(-100000, 2, '.', ',', '$') ); + Serial.println( currency(-999999, 2, '.', ',', '$') ); + Serial.println( currency(-1000000, 2, '.', ',', '$') ); + Serial.println( currency(-9999999, 2, '.', ',', '$') ); + Serial.println( currency(-10000000, 2, '.', ',', '$') ); + Serial.println( currency(-99999999, 2, '.', ',', '$') ); + Serial.println( currency(-100000000, 2, '.', ',', '$') ); + Serial.println( currency(-999999999, 2, '.', ',', '$') ); + Serial.println( currency(-1000000000, 2, '.', ',', '$') ); + Serial.println(); + + Serial.println( currency64(-999999999999999, 2, '.', ',', '$') ); + Serial.println( currency64(-1000000000000000, 2, '.', ',', '$') ); + + Serial.println( bitcoin64(-123456789123456789) ); + Serial.println( yuan64(-1000000000000000) ); + + Serial.println("done"); +} + + +void loop() +{ +} + +// -- END OF FILE -- \ No newline at end of file diff --git a/libraries/Currency/keywords.txt b/libraries/Currency/keywords.txt new file mode 100644 index 00000000..601bb216 --- /dev/null +++ b/libraries/Currency/keywords.txt @@ -0,0 +1,32 @@ +# Syntax Coloring Map for currency + +# Datatypes (KEYWORD1) + +# Methods and Functions (KEYWORD2) +currency KEYWORD2 +currency64 KEYWORD2 + +bitcoin KEYWORD2 +dollar KEYWORD2 +euro KEYWORD2 +roebel KEYWORD2 +yen KEYWORD2 +yuan KEYWORD2 + +bitcoin64 KEYWORD2 +dollar64 KEYWORD2 +euro64 KEYWORD2 +roebel64 KEYWORD2 +yen64 KEYWORD2 +yuan64 KEYWORD2 + +bitcoinf KEYWORD2 +dollarf KEYWORD2 +eurof KEYWORD2 +roebelf KEYWORD2 +yenf KEYWORD2 +yuanf KEYWORD2 + + +# Constants (LITERAL1) + diff --git a/libraries/Currency/library.json b/libraries/Currency/library.json new file mode 100644 index 00000000..93b9f20a --- /dev/null +++ b/libraries/Currency/library.json @@ -0,0 +1,21 @@ +{ + "name": "currency", + "keywords": "currency, bitcoin, dollar, euro, roebel, yen, yuan", + "description": "Arduino library to help formatting integers as currency e.g. $ 1.000.000,00. ", + "authors": + [ + { + "name": "Rob Tillaart", + "email": "Rob.Tillaart@gmail.com", + "maintainer": true + } + ], + "repository": + { + "type": "git", + "url": "https://github.com/RobTillaart/currency" + }, + "version":"0.1.0", + "frameworks": "arduino", + "platforms": "*" +} diff --git a/libraries/Currency/library.properties b/libraries/Currency/library.properties new file mode 100644 index 00000000..00319770 --- /dev/null +++ b/libraries/Currency/library.properties @@ -0,0 +1,11 @@ +name=currency +version=0.1.0 +author=Rob Tillaart +maintainer=Rob Tillaart +sentence=Arduino library to help formatting integers as currency e.g. $ 1.000.000,00. +paragraph=Supports 64 bit integers currency64(..) +category=Uncategorized +url=https://github.com/RobTillaart/currency +architectures=* +includes=currency.h +depends= diff --git a/libraries/Currency/test/unit_test_001.cpp b/libraries/Currency/test/unit_test_001.cpp new file mode 100644 index 00000000..0c6a364f --- /dev/null +++ b/libraries/Currency/test/unit_test_001.cpp @@ -0,0 +1,164 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2021-02-27 +// PURPOSE: unit tests for the printHelpers +// https://github.com/RobTillaart/currency +// + +// supported assertions +// ---------------------------- +// assertEqual(expected, actual); // a == b +// assertNotEqual(unwanted, actual); // a != b +// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b)) +// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b)) +// assertLess(upperBound, actual); // a < b +// assertMore(lowerBound, actual); // a > b +// assertLessOrEqual(upperBound, actual); // a <= b +// assertMoreOrEqual(lowerBound, actual); // a >= b +// assertTrue(actual); +// assertFalse(actual); +// assertNull(actual); + +// // special cases for floats +// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon +// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon +// assertInfinity(actual); // isinf(a) +// assertNotInfinity(actual); // !isinf(a) +// assertNAN(arg); // isnan(a) +// assertNotNAN(arg); // !isnan(a) + + +#include + + +#include "Arduino.h" +#include "currency.h" + + +unittest_setup() +{ +} + +unittest_teardown() +{ +} + + +unittest(currency32) +{ + fprintf(stderr, "VERSION: %s\n", CURRENCY_VERSION); + + fprintf(stderr, "%s\n", currency(10000000, 0, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(10000000, 1, '.', ',', 'E') ); + fprintf(stderr, "%s\n", currency(10000000, 2, '.', ',', 'Y') ); + fprintf(stderr, "%s\n", currency(10000000, 3, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(10000000, 4, '.', ',', '$') ); + fprintf(stderr, "\n"); + + fprintf(stderr, "%s\n", currency(0, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(9, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(10, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(99, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(100, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(1000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(9999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(10000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(99999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(100000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(999999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(1000000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(9999999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(10000000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(99999999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(100000000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(999999999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(1000000000, 2, '.', ',', '$') ); + fprintf(stderr, "\n"); + + fprintf(stderr, "%s\n", currency(-0, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-9, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-10, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-99, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-100, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-1000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-9999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-10000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-99999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-100000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-999999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-1000000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-9999999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-10000000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-99999999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-100000000, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-999999999, 2, '.', ',', '$') ); + fprintf(stderr, "%s\n", currency(-1000000000, 2, '.', ',', '$') ); + fprintf(stderr, "\n"); + + assertEqual(0, strcmp("$ 0.00", currency(0, 2, '.', ',', '$') ) ); + assertEqual(0, strcmp("$ 9,999,999.99", currency(999999999, 2, '.', ',', '$') ) ); + assertEqual(0, strcmp("$-9,999,999.99", currency(-999999999, 2, '.', ',', '$') ) ); +} + + +unittest(currency64) +{ + fprintf(stderr, "VERSION: %s\n", CURRENCY_VERSION); + + assertEqual(0, strcmp("$ 0.00", currency64(0, 2, '.', ',', '$') ) ); + assertEqual(0, strcmp("$ 9,999,999.99", currency64(999999999, 2, '.', ',', '$') ) ); + assertEqual(0, strcmp("$-9,999,999.99", currency64(-999999999, 2, '.', ',', '$') ) ); +} + + +unittest(wrappers32) +{ + fprintf(stderr, "VERSION: %s\n", CURRENCY_VERSION); + + assertEqual(0, strcmp("$ 0.00", dollar(0) ) ); + assertEqual(0, strcmp("$ 9,999,999.99", dollar(999999999) ) ); + assertEqual(0, strcmp("$-9,999,999.99", dollar(-999999999) ) ); + assertEqual(0, strcmp("E 9.999.999,99", euro(999999999) ) ); + assertEqual(0, strcmp("E-9.999.999,99", euro(-999999999) ) ); + assertEqual(0, strcmp("B 999.999999", bitcoin(999999999) ) ); + assertEqual(0, strcmp("B-999.999999", bitcoin(-999999999) ) ); +} + + +unittest(wrappers64) +{ + fprintf(stderr, "VERSION: %s\n", CURRENCY_VERSION); + + assertEqual(0, strcmp("$ 0.00", dollar64(0) ) ); + assertEqual(0, strcmp("$ 9,999,999.99", dollar64(999999999) ) ); + assertEqual(0, strcmp("$-9,999,999.99", dollar64(-999999999) ) ); + assertEqual(0, strcmp("E 9.999.999,99", euro64(999999999) ) ); + assertEqual(0, strcmp("E-9.999.999,99", euro64(-999999999) ) ); + assertEqual(0, strcmp("B 999.999999", bitcoin64(999999999) ) ); + assertEqual(0, strcmp("B-999.999999", bitcoin64(-999999999) ) ); +} + +unittest(wrappersdouble) +{ + fprintf(stderr, "VERSION: %s\n", CURRENCY_VERSION); + + assertEqual(0, strcmp("$ 0.00", dollarf(0) ) ); + assertEqual(0, strcmp("$ 9,999.99", dollarf(9999.99) ) ); + assertEqual(0, strcmp("$-9,999.99", dollarf(-9999.99) ) ); + assertEqual(0, strcmp("E 9.999,99", eurof(9999.99) ) ); + assertEqual(0, strcmp("E-9.999,99", eurof(-9999.99) ) ); + // rounding !! + fprintf(stderr, "%s\n", bitcoinf(9999.99) ); + fprintf(stderr, "%s\n", bitcoinf(-9999.99) ); + + assertEqual(0, strcmp("B 9,999.990000", bitcoinf(9999.99) ) ); + assertEqual(0, strcmp("B-9,999.990000", bitcoinf(-9999.99) ) ); +} + + +unittest_main() + +// -------- diff --git a/libraries/DHTNEW/dhtnew.cpp b/libraries/DHTNEW/dhtnew.cpp index 075b01e6..6d0118c8 100644 --- a/libraries/DHTNEW/dhtnew.cpp +++ b/libraries/DHTNEW/dhtnew.cpp @@ -1,7 +1,7 @@ // // FILE: dhtnew.cpp // AUTHOR: Rob.Tillaart@gmail.com -// VERSION: 0.4.4 +// VERSION: 0.4.5 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino // URL: https://github.com/RobTillaart/DHTNEW // @@ -37,6 +37,7 @@ // 0.4.2 2020-12-15 fix negative temperatures // 0.4.3 2021-01-13 add reset(), add lastRead() // 0.4.4 2021-02-01 fix negative temperatures DHT22 (again) +// 0.4.5 2021-02-14 fix -0°C encoding of DHT22 ( bit pattern 0x8000 ) #include "dhtnew.h" @@ -189,7 +190,10 @@ int DHTNEW::_read() { _humidity = (_bits[0] * 256 + _bits[1]) * 0.1; int16_t t = (_bits[2] * 256 + _bits[3]); - _temperature = t * 0.1; + if(_bits[2] == 0x80) + _temperature = 0; + else + _temperature = t * 0.1; } else // if (_type == 11) // DHT11, DH12, compatible { diff --git a/libraries/DHTNEW/dhtnew.h b/libraries/DHTNEW/dhtnew.h index fee9ae3c..41e6901b 100644 --- a/libraries/DHTNEW/dhtnew.h +++ b/libraries/DHTNEW/dhtnew.h @@ -2,7 +2,7 @@ // // FILE: dhtnew.h // AUTHOR: Rob Tillaart -// VERSION: 0.4.4 +// VERSION: 0.4.5 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino // URL: https://github.com/RobTillaart/DHTNEW // @@ -22,7 +22,7 @@ #include "Arduino.h" -#define DHTNEW_LIB_VERSION (F("0.4.4")) +#define DHTNEW_LIB_VERSION (F("0.4.5")) #define DHTLIB_OK 0 diff --git a/libraries/DHTNEW/examples/dhtnew_endless_insideFunction/dhtnew_endless_insideFunction.ino b/libraries/DHTNEW/examples/dhtnew_endless_insideFunction/dhtnew_endless_insideFunction.ino new file mode 100644 index 00000000..8e628d68 --- /dev/null +++ b/libraries/DHTNEW/examples/dhtnew_endless_insideFunction/dhtnew_endless_insideFunction.ino @@ -0,0 +1,135 @@ +// +// FILE: dhtnew_endless_insideFunction.ino +// AUTHORS: Rob Tillaart, Vladislaw Kuzmin +// VERSION: 0.1.5 +// PURPOSE: Demonstration example of endless DHT values' reporting in a function +// DATE: 2021-02-19 +// (c) : MIT +// +// 0.1.0 2020-06-04 initial version +// 0.1.1 2020-06-15 match 0.3.0 error handling +// 0.1.2 2020-09-22 fix typo +// 0.1.3 2020-11-09 wait for read handling +// 0.1.5 2021-02-19 improved the sketch to read the DHT's value in a function +// +// DHT PINs' layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND + + +#include + +uint64_t previousMillis; +uint32_t count = 0; +uint32_t start, stop; + +uint32_t errors[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + +void setup() +{ + Serial.begin(115200); + Serial.println("DHT_endless.ino"); + Serial.print("LIBRARY VERSION: "); + Serial.println(DHTNEW_LIB_VERSION); + Serial.println(); +} + +void DHTt(const uint8_t pin) +{ + if (millis() - previousMillis > 2000) { + previousMillis = millis(); + DHTNEW mySensor(pin); + + count++; + // show counters for OK and errors. + if (count % 50 == 0) + { + Serial.println(); + Serial.println("OK \tCRC \tTOA \tTOB \tTOC \tTOD \tSNR \tBS \tWFR \tUNK"); + for (uint8_t i = 0; i < 10; i++) + { + Serial.print(errors[i]); + Serial.print('\t'); + } + Serial.println(); + Serial.println(); + } + + if (count % 10 == 0) + { + Serial.println(); + Serial.println("TIM\tCNT\tSTAT\tHUMI\tTEMP\tTIME\tTYPE"); + } + Serial.print(millis()); + Serial.print("\t"); + Serial.print(count); + Serial.print("\t"); + + start = micros(); + int chk = mySensor.read(); + stop = micros(); + + switch (chk) + { + case DHTLIB_OK: + Serial.print("OK,\t"); + errors[0]++; + break; + case DHTLIB_ERROR_CHECKSUM: + Serial.print("CRC,\t"); + errors[1]++; + break; + case DHTLIB_ERROR_TIMEOUT_A: + Serial.print("TOA,\t"); + errors[2]++; + break; + case DHTLIB_ERROR_TIMEOUT_B: + Serial.print("TOB,\t"); + errors[3]++; + break; + case DHTLIB_ERROR_TIMEOUT_C: + Serial.print("TOC,\t"); + errors[4]++; + break; + case DHTLIB_ERROR_TIMEOUT_D: + Serial.print("TOD,\t"); + errors[5]++; + break; + case DHTLIB_ERROR_SENSOR_NOT_READY: + Serial.print("SNR,\t"); + errors[6]++; + break; + case DHTLIB_ERROR_BIT_SHIFT: + Serial.print("BS,\t"); + errors[7]++; + break; + case DHTLIB_WAITING_FOR_READ: + Serial.print("WFR,\t"); + errors[8]++; + break; + default: + Serial.print("U"); + Serial.print(chk); + Serial.print(",\t"); + errors[9]++; + break; + } + // DISPLAY DATA + Serial.print(mySensor.getHumidity(), 1); + Serial.print(",\t"); + Serial.print(mySensor.getTemperature(), 1); + Serial.print(",\t"); + Serial.print(stop - start); + Serial.print(",\t"); + Serial.println(mySensor.getType()); + } +} + +void loop() { + DHTt(2); +} diff --git a/libraries/DHTNEW/examples/dhtnew_minimum_insideFunction/dhtnew_insideFunction.ino b/libraries/DHTNEW/examples/dhtnew_minimum_insideFunction/dhtnew_insideFunction.ino new file mode 100644 index 00000000..fc62bfc2 --- /dev/null +++ b/libraries/DHTNEW/examples/dhtnew_minimum_insideFunction/dhtnew_insideFunction.ino @@ -0,0 +1,53 @@ +// +// FILE: dhtnew_minimum_insideFunction.ino +// AUTHORS: Rob Tillaart, Vladislaw Kuzmin +// VERSION: 0.1.2 +// PURPOSE: DHTNEW library test sketch +// URL: https://github.com/RobTillaart/DHTNew +// +// HISTORY: +// 0.1.5 2021-02-19 improved the sketch to read DHT value in a function +// 0.1.0 2018-01-08 initial version +// 0.1.1 2020-04-30 replaced humidity and temperature with functions +// 0.1.2 2020-06-15 match 0.3.0 error handling +// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND + +#include + +uint64_t previousMillis; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.println(); +} + + +void DHTt(uint8_t pin) +{ + DHTNEW mySensor(pin); + + if (millis() - mySensor.lastRead() > 2000) + { + previousMillis = millis(); + mySensor.read(); + Serial.print(mySensor.getHumidity(), 2); + Serial.print("\t"); + Serial.println(mySensor.getTemperature(), 2); + } +} + + +void loop() { + DHTt(2); +} + +// END OF FILE diff --git a/libraries/DHTNEW/library.json b/libraries/DHTNEW/library.json index 024dc03d..8eef66e1 100644 --- a/libraries/DHTNEW/library.json +++ b/libraries/DHTNEW/library.json @@ -13,7 +13,7 @@ "type": "git", "url": "https://github.com/RobTillaart/DHTNEW.git" }, - "version":"0.4.4", + "version":"0.4.5", "frameworks": "arduino", "platforms": "*" } diff --git a/libraries/DHTNEW/library.properties b/libraries/DHTNEW/library.properties index 58286da1..55d8d489 100644 --- a/libraries/DHTNEW/library.properties +++ b/libraries/DHTNEW/library.properties @@ -1,5 +1,5 @@ name=DHTNEW -version=0.4.4 +version=0.4.5 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for DHT temperature and humidity sensor, with automatic sensortype recognition. diff --git a/libraries/DHTlib/dht.cpp b/libraries/DHTlib/dht.cpp index 11b00be1..4f39f9f9 100644 --- a/libraries/DHTlib/dht.cpp +++ b/libraries/DHTlib/dht.cpp @@ -1,12 +1,13 @@ // // FILE: dht.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.32 +// VERSION: 0.1.33 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino, AVR optimized // URL: https://github.com/RobTillaart/DHTlib // http://arduino.cc/playground/Main/DHTLib // // HISTORY: +// 0.1.33 2021-02-16 fix #6 T-GO signal in handshake. (needed for long wires) // 0.1.32 2021-02-01 fix negative temperature DHT22 again (code from DHTNew) // 0.1.31 2020-12-15 fix negative temperature DHT22 (code from DHTNew) // 0.1.30 2020-06-30 own repo; @@ -182,7 +183,7 @@ int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBit digitalWrite(pin, LOW); // T-be if (wakeupDelay > 8) delay(wakeupDelay); else delayMicroseconds(wakeupDelay * 1000UL); - // digitalWrite(pin, HIGH); // T-go + digitalWrite(pin, HIGH); // T-go pinMode(pin, INPUT); uint16_t loopCount = DHTLIB_TIMEOUT * 2; // 200uSec max diff --git a/libraries/DHTlib/dht.h b/libraries/DHTlib/dht.h index fd4014d0..0f182538 100644 --- a/libraries/DHTlib/dht.h +++ b/libraries/DHTlib/dht.h @@ -1,7 +1,7 @@ // // FILE: dht.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.32 +// VERSION: 0.1.33 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino. AVR optimized // URL: https://github.com/RobTillaart/DHTlib // http://arduino.cc/playground/Main/DHTLib @@ -21,7 +21,7 @@ #endif -#define DHT_LIB_VERSION (F("0.1.32")) +#define DHT_LIB_VERSION (F("0.1.33")) #define DHTLIB_OK 0 #define DHTLIB_ERROR_CHECKSUM -1 diff --git a/libraries/DHTlib/examples/dht22_in_function/dht22_in_function.ino b/libraries/DHTlib/examples/dht22_in_function/dht22_in_function.ino new file mode 100644 index 00000000..17c5f5f4 --- /dev/null +++ b/libraries/DHTlib/examples/dht22_in_function/dht22_in_function.ino @@ -0,0 +1,80 @@ +// +// FILE: dht22_in_function.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// DATE: 2021-02-19 +// PURPOSE: show usage of DHT object in a function +// URL: https://github.com/RobTillaart/DHTlib + +// based on issue #8 + +#include "dht.h" + +#define DHTPIN 8 + +void printDHT(const uint8_t pin) // uint8_t is an 8 bit unsigned integer +{ + // This command questions a DHT22 on a specific 'pin'. + // on success, it prints "OK;{temperature};{humidity};" + // on error, it prints "ERR;DHTt;{errorCode};". + // + // param 'pin': int + // The pin, where the DHT22 is connected. + + dht DHT; + + int chk = DHT.read22(pin); + if (chk == DHTLIB_OK) + { + Serial.print("OK;"); + Serial.print(DHT.temperature); + Serial.print(";"); + Serial.print(DHT.humidity); + Serial.println(";"); + return; + } + + Serial.print("ERR;DHTt;"); + switch (chk) + { + case DHTLIB_ERROR_CHECKSUM: + Serial.println("CHSM;"); + break; + case DHTLIB_ERROR_TIMEOUT: + Serial.println("TIMO"); + break; + case DHTLIB_ERROR_CONNECT: + Serial.println("NCNN"); + break; + case DHTLIB_ERROR_ACK_L: + Serial.println("ACKL"); + break; + case DHTLIB_ERROR_ACK_H: + Serial.println("ACKH"); + break; + default: + Serial.println("UNKN"); + break; + } +} + +void setup() +{ + Serial.begin(115200); + Serial.println("\n"); +} + + +void loop() +{ + static uint32_t lastTime = 0; // holds its value after every iteration of loop + if (millis() - lastTime >= 2000) // print every 2000 milliseconds + { + lastTime = millis(); + printDHT(DHTPIN); + } + + // add your other code here +} + +// -- END OF FILE -- diff --git a/libraries/DHTlib/library.json b/libraries/DHTlib/library.json index 0b13224f..a8799787 100644 --- a/libraries/DHTlib/library.json +++ b/libraries/DHTlib/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/DHTlib.git" }, - "version":"0.1.32", + "version":"0.1.33", "frameworks": "arduino", "platforms": "*" } diff --git a/libraries/DHTlib/library.properties b/libraries/DHTlib/library.properties index 36ad52e9..8992395e 100644 --- a/libraries/DHTlib/library.properties +++ b/libraries/DHTlib/library.properties @@ -1,5 +1,5 @@ name=DHTlib -version=0.1.32 +version=0.1.33 author=Rob Tillaart maintainer=Rob Tillaart sentence=AVR Optimized Library for DHT Temperature & Humidity Sensor on AVR only. diff --git a/libraries/DHTstable/dht.cpp b/libraries/DHTstable/dht.cpp index cb0d4dc3..49cb741c 100644 --- a/libraries/DHTstable/dht.cpp +++ b/libraries/DHTstable/dht.cpp @@ -1,36 +1,37 @@ // // FILE: dht.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.8 +// VERSION: 0.2.9 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino // URL: https://github.com/RobTillaart/DHTstable // -// HISTORY: -// 0.2.8 2021-02-01 fix negative temperature (from dhtnew) -// 0.2.7 2020-12-20 add arduino-CI, unit test, +// HISTORY: +// 0.2.9 2021-02-27 fix URL in library.json +// 0.2.8 2021-02-01 fix negative temperature (from dhtnew) +// 0.2.7 2020-12-20 add arduino-CI, unit test, // reset(), getTemperature(), getHumidity() -// 0.2.6 2020-07-20 update URL in .cpp -// 0.2.5 2020-06-30 move to own repository; update headers mainly. -// 0.2.4 2018-04-03 add get-/setDisableIRQ(bool b) -// 0.2.3 2018-02-21 change #defines in const int to enforce return types. +// 0.2.6 2020-07-20 update URL in .cpp +// 0.2.5 2020-06-30 move to own repository; update headers mainly. +// 0.2.4 2018-04-03 add get-/setDisableIRQ(bool b) +// 0.2.3 2018-02-21 change #defines in const int to enforce return types. // https://github.com/RobTillaart/Arduino/issues/94 -// 0.2.2 2017-12-12 add support for AM23XX types more explicitly -// 0.2.1 2017-09-20 fix https://github.com/RobTillaart/Arduino/issues/80 -// 0.2.0 2017-07-24 fix https://github.com/RobTillaart/Arduino/issues/31 + 33 -// 0.1.13 fix negative temperature -// 0.1.12 support DHT33 and DHT44 initial version -// 0.1.11 renamed DHTLIB_TIMEOUT -// 0.1.10 optimized faster WAKEUP + TIMEOUT -// 0.1.09 optimize size: timeout check + use of mask -// 0.1.08 added formula for timeout based upon clockspeed -// 0.1.07 added support for DHT21 -// 0.1.06 minimize footprint (2012-12-27) -// 0.1.05 fixed negative temperature bug (thanks to Roseman) -// 0.1.04 improved readability of code using DHTLIB_OK in code -// 0.1.03 added error values for temp and humidity when read failed -// 0.1.02 added error codes -// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011) -// 0.1.0 by Rob Tillaart (01/04/2011) +// 0.2.2 2017-12-12 add support for AM23XX types more explicitly +// 0.2.1 2017-09-20 fix https://github.com/RobTillaart/Arduino/issues/80 +// 0.2.0 2017-07-24 fix https://github.com/RobTillaart/Arduino/issues/31 + 33 +// 0.1.13 fix negative temperature +// 0.1.12 support DHT33 and DHT44 initial version +// 0.1.11 renamed DHTLIB_TIMEOUT +// 0.1.10 optimized faster WAKEUP + TIMEOUT +// 0.1.09 optimize size: timeout check + use of mask +// 0.1.08 added formula for timeout based upon clockspeed +// 0.1.07 added support for DHT21 +// 0.1.06 minimize footprint (2012-12-27) +// 0.1.05 fixed negative temperature bug (thanks to Roseman) +// 0.1.04 improved readability of code using DHTLIB_OK in code +// 0.1.03 added error values for temp and humidity when read failed +// 0.1.02 added error codes +// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011) +// 0.1.0 by Rob Tillaart (01/04/2011) // // inspired by DHT11 library // diff --git a/libraries/DHTstable/dht.h b/libraries/DHTstable/dht.h index 0f94d124..1bc3dd5f 100644 --- a/libraries/DHTstable/dht.h +++ b/libraries/DHTstable/dht.h @@ -1,7 +1,7 @@ // // FILE: dht.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.8 +// VERSION: 0.2.9 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino // URL: https://github.com/RobTillaart/DHTstable // @@ -19,7 +19,7 @@ #endif -#define DHT_LIB_VERSION (F("0.2.8 - dhtstable")) +#define DHT_LIB_VERSION (F("0.2.9 - dhtstable")) const int DHTLIB_OK = 0; diff --git a/libraries/DHTstable/library.json b/libraries/DHTstable/library.json index e88a431e..5f48d7d8 100644 --- a/libraries/DHTstable/library.json +++ b/libraries/DHTstable/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/DHTstable" }, - "version": "0.2.8", + "version":"0.2.9", "frameworks": "arduino", "platforms": "atmelavr" } diff --git a/libraries/DHTstable/library.properties b/libraries/DHTstable/library.properties index 99c172c2..9cca4817 100644 --- a/libraries/DHTstable/library.properties +++ b/libraries/DHTstable/library.properties @@ -1,5 +1,5 @@ name=DHTStable -version=0.2.8 +version=0.2.9 author=Rob Tillaart maintainer=Rob Tillaart sentence=Stable version of library for DHT Temperature & Humidity Sensor diff --git a/libraries/MCP23017_RT/MCP23017.cpp b/libraries/MCP23017_RT/MCP23017.cpp index 6e2048d5..981d8a6b 100644 --- a/libraries/MCP23017_RT/MCP23017.cpp +++ b/libraries/MCP23017_RT/MCP23017.cpp @@ -1,7 +1,7 @@ // // FILE: MCP23017.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.0 +// VERSION: 0.2.1 // PURPOSE: Arduino library for I2C MCP23017 16 channel port expander // DATE: 2019-10-12 // URL: https://github.com/RobTillaart/MCP23017_RT @@ -12,6 +12,7 @@ // 0.1.2 2021-01-01 add arduino-ci + unit test // 0.2.0 2021-01-11 Multiple Wire support Wire0 .. 5 // error handling +// 0.2.1 2021-02-17 fix #7 DDR is defined in ESP32 // TODO: // interrupts @@ -92,13 +93,13 @@ bool MCP23017::pinMode(uint8_t pin, uint8_t value) return false; } - uint8_t DDR = MCP23017_DDR_A; // Data Direction Register + uint8_t dataDirectionRegister = MCP23017_DDR_A; if (pin > 7) { - DDR = MCP23017_DDR_B; + dataDirectionRegister = MCP23017_DDR_B; pin -= 8; } - uint8_t val = readReg(DDR); + uint8_t val = readReg(dataDirectionRegister); uint8_t mask = 1 << pin; // only work with valid if (value == INPUT || value == INPUT_PULLUP) @@ -110,7 +111,7 @@ bool MCP23017::pinMode(uint8_t pin, uint8_t value) val &= ~mask; } // other values won't change val .... - writeReg(DDR, val); + writeReg(dataDirectionRegister, val); _error = MCP23017_OK; return true; } diff --git a/libraries/MCP23017_RT/MCP23017.h b/libraries/MCP23017_RT/MCP23017.h index dcd11f5d..18dccbf9 100644 --- a/libraries/MCP23017_RT/MCP23017.h +++ b/libraries/MCP23017_RT/MCP23017.h @@ -2,7 +2,7 @@ // // FILE: MCP23017.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.0 +// VERSION: 0.2.1 // PURPOSE: Arduino library for I2C MCP23017 16 channel port expander // DATE: 2019-10-12 // URL: https://github.com/RobTillaart/MCP23017_RT @@ -12,7 +12,7 @@ #include "Wire.h" -#define MCP23017_LIB_VERSION (F("0.2.0")) +#define MCP23017_LIB_VERSION (F("0.2.1")) #define MCP23017_OK 0x00 #define MCP23017_PIN_ERROR 0x81 diff --git a/libraries/MCP23017_RT/library.json b/libraries/MCP23017_RT/library.json index d8e50d1b..55043fd0 100644 --- a/libraries/MCP23017_RT/library.json +++ b/libraries/MCP23017_RT/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/MCP23017_RT.git" }, - "version":"0.2.0", + "version":"0.2.1", "frameworks": "arduino", "platforms": "*" } diff --git a/libraries/MCP23017_RT/library.properties b/libraries/MCP23017_RT/library.properties index b5479038..e87a04fa 100644 --- a/libraries/MCP23017_RT/library.properties +++ b/libraries/MCP23017_RT/library.properties @@ -1,5 +1,5 @@ name=MCP23017_RT -version=0.2.0 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for I2C MCP23017 16 channel port expander 16 IO-lines diff --git a/libraries/PCF8575/examples/PCF8575_performance/PCF8575_performance.ino b/libraries/PCF8575/examples/PCF8575_performance/PCF8575_performance.ino new file mode 100644 index 00000000..1e27a307 --- /dev/null +++ b/libraries/PCF8575/examples/PCF8575_performance/PCF8575_performance.ino @@ -0,0 +1,50 @@ +// +// FILE: PCF8575_performance.ino +// AUTHOR: Rob Tillaart +// DATE: 2021-01-24 +// +// PUPROSE: test PCF8575 library + +#include "PCF8575.h" + +PCF8575 PCF(0x38); + +uint32_t start, stop; + +volatile uint16_t x; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("PCF8575_LIB_VERSION:\t"); + Serial.println(PCF8575_LIB_VERSION); + + PCF.begin(); + Serial.println(PCF.isConnected()); + + for (long clk = 100000; clk < 500000; clk += 50000) + { + Serial.println(clk); + Wire.setClock(clk); + start = micros(); + x = PCF.read16(); + stop = micros(); + Serial.print("Read:\t"); + Serial.println(stop - start); + delay(1000); + + start = micros(); + PCF.write16(0xFFFF); + stop = micros(); + Serial.print("Write:\t "); + Serial.println(stop - start); + delay(1000); + } + +} + +void loop() +{ + +}