From 029aab42193420ab3dbad489c32c5ad8ee282c63 Mon Sep 17 00:00:00 2001 From: RobTillaart Date: Mon, 27 Jan 2020 17:06:52 +0100 Subject: [PATCH] issue #140 refactor constructor / configure --- libraries/Max44009/Max44009.h | 8 +++---- libraries/Max44009/library.json | 2 +- libraries/Max44009/library.properties | 2 +- libraries/Max44009/max44009.cpp | 32 ++++++++++----------------- libraries/Max44009/readme.md | 4 ++++ 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/libraries/Max44009/Max44009.h b/libraries/Max44009/Max44009.h index 66b32852..589686aa 100644 --- a/libraries/Max44009/Max44009.h +++ b/libraries/Max44009/Max44009.h @@ -3,7 +3,7 @@ // // FILE: Max44009.h // AUTHOR: Rob dot Tillaart at gmail dot com -// VERSION: 0.3.1 +// VERSION: 0.3.3 // PURPOSE: library for MAX44009 lux sensor Arduino // HISTORY: See Max440099.cpp // @@ -18,7 +18,7 @@ #include "WProgram.h" #endif -#define MAX44009_LIB_VERSION "0.3.1" +#define MAX44009_LIB_VERSION "0.3.3" #define MAX44009_DEFAULT_ADDRESS 0x4A #define MAX44009_ALT_ADDRESS 0x4B @@ -59,10 +59,10 @@ public: // ctor for UNO Max44009(const uint8_t address, const Boolean begin = Boolean::True); - // default ctor with default address 0xCB + // default ctor with default address Max44009(const Boolean begin = Boolean::True); // Change I2C interface and address - void configure(const uint8_t address, TwoWire *wire); + void configure(const uint8_t address, TwoWire *wire, const Boolean begin = Boolean::True); float getLux(); int getError(); diff --git a/libraries/Max44009/library.json b/libraries/Max44009/library.json index e9b35229..cabd8af0 100644 --- a/libraries/Max44009/library.json +++ b/libraries/Max44009/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Arduino.git" }, - "version": "0.3.2", + "version": "0.3.3", "frameworks": "arduino", "platforms": "*", "export": { diff --git a/libraries/Max44009/library.properties b/libraries/Max44009/library.properties index 7b7153bb..8da23cb2 100644 --- a/libraries/Max44009/library.properties +++ b/libraries/Max44009/library.properties @@ -1,5 +1,5 @@ name=Max44009 -version=0.3.2 +version=0.3.3 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library for MAX44009 lux sensor Arduino. diff --git a/libraries/Max44009/max44009.cpp b/libraries/Max44009/max44009.cpp index 63202e0a..8f67ba20 100644 --- a/libraries/Max44009/max44009.cpp +++ b/libraries/Max44009/max44009.cpp @@ -1,12 +1,13 @@ // // FILE: Max44009.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.3.2 +// VERSION: 0.3.3 // PURPOSE: library for MAX44009 lux sensor Arduino // URL: https://github.com/RobTillaart/Arduino/tree/master/libraries // // Released to the public domain // +// 0.3.3 - 2020-01-27 issue #140 refactor constructors / configure // 0.3.2 - 2020-01-21 solve #132 cannot read full range in manual mode. // set automatic mode explicitly in constructors; // added some error checks @@ -48,26 +49,23 @@ Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t c } #endif -Max44009::Max44009(const uint8_t address, Boolean begin) +Max44009::Max44009(const uint8_t address, const Boolean begin) { - _address = address; - _data = 0; - _error = MAX44009_OK; - _wire = &Wire; - - if (begin == Boolean::True) - { - _wire->begin(); - setAutomaticMode(); - } + Max44009::configure(address, &Wire, begin); } Max44009::Max44009(const Boolean begin) { - _address = MAX44009_DEFAULT_ADDRESS; + Max44009::configure(MAX44009_DEFAULT_ADDRESS, &Wire, begin); +} + + +void Max44009::configure(const uint8_t address, TwoWire *wire, const Boolean begin) +{ + _address = address; _data = 0; _error = MAX44009_OK; - _wire = &Wire; + _wire = wire; if (begin == Boolean::True) { @@ -76,12 +74,6 @@ Max44009::Max44009(const Boolean begin) } } -void Max44009::configure(const uint8_t address, TwoWire *wire) -{ - _address = address; - _wire = wire; -} - float Max44009::getLux(void) { uint8_t dhi = read(MAX44009_LUX_READING_HIGH); diff --git a/libraries/Max44009/readme.md b/libraries/Max44009/readme.md index 9f3289d4..7df589d0 100644 --- a/libraries/Max44009/readme.md +++ b/libraries/Max44009/readme.md @@ -10,3 +10,7 @@ - will not compile for UNO - use for e.g. ESP32 +## Notes +Please be aware this is a 3.3 Volt device so it should not be connected +to an Arduino or other 5 Volt device directly. Use a level convertor to +solve this.