From fd3905552fc4535de41df72d73cfc79cb32ff7cd Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Thu, 23 Dec 2021 12:48:03 +0100 Subject: [PATCH] update library.json, license, readme, minor edits (#31) --- LICENSE | 2 +- PCF8574.cpp | 32 ++++++++++--------- PCF8574.h | 21 ++++++------ README.md | 8 ++--- examples/PCF8574_Wire2/PCF8574_Wire2.ino | 3 +- .../PCF8574_interrupt/PCF8574_interrupt.ino | 10 +++--- .../PCF8574_isConnected.ino | 2 +- .../PCF8574_rotaryEncoder.ino | 4 +-- examples/PCF8574_test/PCF8574_test.ino | 2 -- examples/PCF8574_test1/PCF8574_test1.ino | 4 +-- examples/PCF8574_test2/PCF8574_test2.ino | 1 - keywords.txt | 3 +- library.json | 2 +- library.properties | 2 +- test/unit_test_001.cpp | 6 ++-- 15 files changed, 52 insertions(+), 50 deletions(-) diff --git a/LICENSE b/LICENSE index 39d07e3..c9bd779 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2013-2021 Rob Tillaart +Copyright (c) 2013-2022 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 diff --git a/PCF8574.cpp b/PCF8574.cpp index 533f21d..11d58c4 100644 --- a/PCF8574.cpp +++ b/PCF8574.cpp @@ -2,13 +2,14 @@ // FILE: PCF8574.cpp // AUTHOR: Rob Tillaart // DATE: 02-febr-2013 -// VERSION: 0.3.2 +// VERSION: 0.3.3 // PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander // URL: https://github.com/RobTillaart/PCF8574 // http://forum.arduino.cc/index.php?topic=184800 // // HISTORY: -// +// +// 0.3.3 2021-12-23 update library.json, license, readme, minor edits // 0.3.2 2021-07-04 fix #25 add setAddress() // 0.3.1 2021-04-23 Fix for platformIO compatibility // 0.3.0 2021-01-03 multiWire support - inspired by mattbue - issue #14 @@ -20,9 +21,9 @@ // removed pre 1.0 support // added begin(dsa, scl) for ESP32 // added reverse() -// +// // 0.1.9 2017-02-27 fix warning about return in readButton8() -// 0.1.08 2016-05-20 Merged work of Septillion +// 0.1.08 2016-05-20 Merged work of Septillion // Fix/refactor ButtonRead8() - see https://github.com/RobTillaart/Arduino/issues/38 // missing begin() => mask parameter // 0.1.07 2016-05-02 (manually merged) Septillion @@ -60,7 +61,7 @@ PCF8574::PCF8574(const uint8_t deviceAddress, TwoWire *wire) #if defined (ESP8266) || defined(ESP32) -bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t val) +bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t value) { _wire = &Wire; if ((dataPin < 255) && (clockPin < 255)) @@ -70,17 +71,17 @@ bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t val) _wire->begin(); } if (! isConnected()) return false; - PCF8574::write8(val); + PCF8574::write8(value); return true; } #endif -bool PCF8574::begin(uint8_t val) +bool PCF8574::begin(uint8_t value) { _wire->begin(); if (! isConnected()) return false; - PCF8574::write8(val); + PCF8574::write8(value); return true; } @@ -105,11 +106,11 @@ uint8_t PCF8574::getAddress() } -// removed _wire->beginTransmission(addr); -// with @100KHz -> 265 micros() -// without @100KHz -> 132 micros() -// without @400KHz -> 52 micros() -// TODO @800KHz -> ?? +// removed _wire->beginTransmission(_address); +// with @100 KHz -> 265 micros() +// without @100 KHz -> 132 micros() +// without @400 KHz -> 52 micros() +// TODO @800 KHz -> ?? uint8_t PCF8574::read8() { if (_wire->requestFrom(_address, (uint8_t)1) != 1) @@ -253,10 +254,11 @@ uint8_t PCF8574::readButton(const uint8_t pin) uint8_t temp = _dataOut; PCF8574::write(pin, HIGH); - uint8_t rtn = PCF8574::read(pin); + uint8_t value = PCF8574::read(pin); PCF8574::write8(temp); - return rtn; + return value; } // -- END OF FILE -- + diff --git a/PCF8574.h b/PCF8574.h index ca91154..197b356 100644 --- a/PCF8574.h +++ b/PCF8574.h @@ -1,9 +1,9 @@ #pragma once // -// FILE: PCF8574.H +// FILE: PCF8574.h // AUTHOR: Rob Tillaart // DATE: 02-febr-2013 -// VERSION: 0.3.2 +// VERSION: 0.3.3 // PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander // URL: https://github.com/RobTillaart/PCF8574 // http://forum.arduino.cc/index.php?topic=184800 @@ -17,26 +17,26 @@ #include "Wire.h" -#define PCF8574_LIB_VERSION (F("0.3.2")) +#define PCF8574_LIB_VERSION (F("0.3.3")) #ifndef PCF8574_INITIAL_VALUE -#define PCF8574_INITIAL_VALUE 0xFF +#define PCF8574_INITIAL_VALUE 0xFF #endif -#define PCF8574_OK 0x00 -#define PCF8574_PIN_ERROR 0x81 -#define PCF8574_I2C_ERROR 0x82 +#define PCF8574_OK 0x00 +#define PCF8574_PIN_ERROR 0x81 +#define PCF8574_I2C_ERROR 0x82 class PCF8574 { public: - explicit PCF8574(const uint8_t deviceAddress, TwoWire *wire = &Wire); + explicit PCF8574(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire); #if defined (ESP8266) || defined(ESP32) - bool begin(uint8_t sda, uint8_t scl, uint8_t val = PCF8574_INITIAL_VALUE); + bool begin(uint8_t sda, uint8_t scl, uint8_t value = PCF8574_INITIAL_VALUE); #endif - bool begin(uint8_t val = PCF8574_INITIAL_VALUE); + bool begin(uint8_t value = PCF8574_INITIAL_VALUE); bool isConnected(); @@ -89,3 +89,4 @@ class PCF8574 // -- END OF FILE -- + diff --git a/README.md b/README.md index 2c4a93e..6a0b7c9 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,10 @@ the include of "pcf8574.h" to overrule the default value used with the **begin() ### Constructor -- **PCF8574(deviceAddress, TwoWire \*wire = &Wire)** Constructor with device address, -and optional the Wire interface as parameter. -- **bool begin(uint8_t val = PCF8574_INITIAL_VALUE)** set the initial value for the pins and masks. -- **bool begin(uint8_t sda, uint8_t scl, uint8_t val = PCF8574_INITIAL_VALUE)** idem, for the ESP32 where one can choose the I2C pins. +- **PCF8574(uint8_t deviceAddress = 0x20, TwoWire \*wire = &Wire)** Constructor with optional device address, default 0x20, +and the optional Wire interface as parameter. +- **bool begin(uint8_t value = PCF8574_INITIAL_VALUE)** set the initial value for the pins and masks. +- **bool begin(uint8_t sda, uint8_t scl, uint8_t value = PCF8574_INITIAL_VALUE)** idem, for the ESP32 where one can choose the I2C pins. - **bool isConnected()** checks if the address set in the constructor or by **setAddress()** is visible on the I2C bus. - **bool setAddress(const uint8_t deviceAddress)** sets the device address after construction. Can be used to switch between PCF8574 modules runtime. Note this corrupts internal buffered values, diff --git a/examples/PCF8574_Wire2/PCF8574_Wire2.ino b/examples/PCF8574_Wire2/PCF8574_Wire2.ino index 9ab3a5b..73863e5 100644 --- a/examples/PCF8574_Wire2/PCF8574_Wire2.ino +++ b/examples/PCF8574_Wire2/PCF8574_Wire2.ino @@ -2,8 +2,7 @@ // FILE: PCF8574_Wire2.ino // AUTHOR: Rob Tillaart // DATE: 2016-04-30 -// PUPROSE: demo -// +// PUPROSE: demo #include "PCF8574.h" diff --git a/examples/PCF8574_interrupt/PCF8574_interrupt.ino b/examples/PCF8574_interrupt/PCF8574_interrupt.ino index 8b7bb44..b215162 100644 --- a/examples/PCF8574_interrupt/PCF8574_interrupt.ino +++ b/examples/PCF8574_interrupt/PCF8574_interrupt.ino @@ -4,13 +4,12 @@ // DATE: 2020-12-07 // PUPROSE: test PCF8574 library // - // TEST SETUP -// Connect INT pin of the PCF8574 to UNO pin 2 +// Connect INT pin of the PCF8574 to UNO pin 2 // -// (from figure 4 datasheet -// Place a pull up resistor 4K7 between pin and 5V -// Place a capacitor 10-400pF between pin and GND +// (from figure 4 datasheet +// Place a pull up resistor 4K7 between pin and 5V +// Place a capacitor 10-400pF between pin and GND #include "PCF8574.h" @@ -69,3 +68,4 @@ void loop() // -- END OF FILE -- + diff --git a/examples/PCF8574_isConnected/PCF8574_isConnected.ino b/examples/PCF8574_isConnected/PCF8574_isConnected.ino index 37de345..8bdf5d2 100644 --- a/examples/PCF8574_isConnected/PCF8574_isConnected.ino +++ b/examples/PCF8574_isConnected/PCF8574_isConnected.ino @@ -3,7 +3,6 @@ // AUTHOR: Rob Tillaart // DATE: 2021-01-03 // PUPROSE: demo isConnected function -// #include "PCF8574.h" @@ -40,3 +39,4 @@ void loop() // -- END OF FILE -- + diff --git a/examples/PCF8574_rotaryEncoder/PCF8574_rotaryEncoder.ino b/examples/PCF8574_rotaryEncoder/PCF8574_rotaryEncoder.ino index cd204f5..8c1d729 100644 --- a/examples/PCF8574_rotaryEncoder/PCF8574_rotaryEncoder.ino +++ b/examples/PCF8574_rotaryEncoder/PCF8574_rotaryEncoder.ino @@ -2,9 +2,8 @@ // FILE: PCF8574_rotaryEncoder.ino // AUTHOR: Rob Tillaart // DATE: 2021-05-08 -// // PUPROSE: demo PCF8574 as rotary encoder reader. - +// // // RotaryEncoder PCF8574 UNO // -------------------------------------- @@ -132,3 +131,4 @@ void updateRotaryDecoder() // -- END OF FILE -- + diff --git a/examples/PCF8574_test/PCF8574_test.ino b/examples/PCF8574_test/PCF8574_test.ino index 0f13e17..742dab9 100644 --- a/examples/PCF8574_test/PCF8574_test.ino +++ b/examples/PCF8574_test/PCF8574_test.ino @@ -1,10 +1,8 @@ - // // FILE: PCF8574_test.ino // AUTHOR: Rob Tillaart // DATE: 7-febr-2013 // PUPROSE: test PCF8574 library -// #include "PCF8574.h" diff --git a/examples/PCF8574_test1/PCF8574_test1.ino b/examples/PCF8574_test1/PCF8574_test1.ino index f092f7c..09a9f49 100644 --- a/examples/PCF8574_test1/PCF8574_test1.ino +++ b/examples/PCF8574_test1/PCF8574_test1.ino @@ -1,9 +1,9 @@ // -// FILE: pcf8574_test.ino +// FILE: PCF8574_test.ino // AUTHOR: Rob Tillaart // DATE: 27-08-2013 // PUPROSE: demo -// + #include "PCF8574.h" diff --git a/examples/PCF8574_test2/PCF8574_test2.ino b/examples/PCF8574_test2/PCF8574_test2.ino index 783d4f7..2013b74 100644 --- a/examples/PCF8574_test2/PCF8574_test2.ino +++ b/examples/PCF8574_test2/PCF8574_test2.ino @@ -3,7 +3,6 @@ // AUTHOR: Rob Tillaart // DATE: 2016-04-30 // PUPROSE: demo rotateLeft, -Right and toggleMask -// #include "PCF8574.h" diff --git a/keywords.txt b/keywords.txt index c8f523c..f98d901 100644 --- a/keywords.txt +++ b/keywords.txt @@ -37,4 +37,5 @@ lastError KEYWORD2 PCF8574_LIB_VERSION LITERAL1 PCF8574_OK LITERAL1 PCF8574_PIN_ERROR LITERAL1 -PCF8574_I2C_ERROR LITERAL1 \ No newline at end of file +PCF8574_I2C_ERROR LITERAL1 + diff --git a/library.json b/library.json index 3ddbf25..8529d7e 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/PCF8574.git" }, - "version": "0.3.2", + "version": "0.3.3", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index d72c2d9..8973a48 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PCF8574 -version=0.3.2 +version=0.3.3 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for PCF8574 - 8 channel I2C IO expander diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 3139a81..af58a29 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -42,16 +42,17 @@ PCF8574 PCF(0x38); unittest_setup() { + fprintf(stderr, "PCF8574_LIB_VERSION: %s\n", (char *) PCF8574_LIB_VERSION); } + unittest_teardown() { } + unittest(test_begin) { - fprintf(stderr, "VERSION: %s\n", PCF8574_LIB_VERSION); - PCF8574 PCF(0x38); PCF.begin(); @@ -103,4 +104,5 @@ unittest(test_address) unittest_main() + // --------