diff --git a/libraries/Max44009/Max44009.h b/libraries/Max44009/Max44009.h index 9c47d910..db5997fc 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.1.7 +// VERSION: 0.1.8 // PURPOSE: library for MAX44009 lux sensor Arduino // HISTORY: See Max440099.cpp // @@ -18,13 +18,14 @@ #include "WProgram.h" #endif -#define MAX44009_LIB_VERSION "0.1.7" +#define MAX44009_LIB_VERSION "0.1.8" // REGISTERS #define MAX44009_INTERRUPT_STATUS 0x00 #define MAX44009_INTERRUPT_ENABLE 0x01 #define MAX44009_CONFIGURATION 0x02 -#define MAX44009_LUX_READING 0x03 // (03 = HIGH BYTE, (04 = LOW BYTE +#define MAX44009_LUX_READING_HIGH 0x03 +#define MAX44009_LUX_READING_LOW 0x04 #define MAX44009_THRESHOLD_HIGH 0x05 #define MAX44009_THRESHOLD_LOW 0x06 #define MAX44009_THRESHOLD_TIMER 0x07 @@ -80,11 +81,11 @@ private: void setThreshold(uint8_t, float); float getThreshold(uint8_t); - uint16_t read(uint8_t reg, uint8_t bytes = 1); - void write(uint8_t, uint8_t); + uint8_t read(uint8_t reg); + void write(uint8_t, uint8_t); uint8_t _address; - uint16_t _data; + uint8_t _data; int _error; }; #endif diff --git a/libraries/Max44009/library.json b/libraries/Max44009/library.json index 6f4d4402..621f021b 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.1.7", + "version":"0.1.8", "frameworks": "arduino", "platforms": "*", "export": { diff --git a/libraries/Max44009/library.properties b/libraries/Max44009/library.properties index ef74ec45..99553511 100644 --- a/libraries/Max44009/library.properties +++ b/libraries/Max44009/library.properties @@ -1,5 +1,5 @@ name=Max44009 -version=0.1.7 +version=0.1.8 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 49143ada..b82470bf 100644 --- a/libraries/Max44009/max44009.cpp +++ b/libraries/Max44009/max44009.cpp @@ -1,12 +1,14 @@ // // FILE: Max44009.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.7 +// VERSION: 0.1.8 // PURPOSE: library for MAX44009 lux sensor Arduino // URL: https://github.com/RobTillaart/Arduino/tree/master/libraries // // Released to the public domain // +// 0.1.8 - 2018-05-13 issue #105 Fix read register +// (thanks morxGrillmeister) // 0.1.7 - 2018-04-02 issue #98 extend constructor for ESP8266 // 0.1.6 - 2017-07-26 revert double to float // 0.1.5 - updated history @@ -34,9 +36,10 @@ Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t c float Max44009::getLux(void) { - uint16_t data = read(MAX44009_LUX_READING, 2); - uint8_t e = (data & 0xF000) >> 12; - uint32_t m = ((data & 0x0F00) >> 4) + (data & 0x000F); + uint8_t dhi = read(MAX44009_LUX_READING_HIGH); + uint8_t dlo = read(MAX44009_LUX_READING_LOW); + uint8_t e = dhi >> 4; + uint32_t m = (dhi << 4) + (dlo & 0x0F); m <<= e; float val = m * 0.045; return val; @@ -76,7 +79,7 @@ void Max44009::setThresholdTimer(const uint8_t value) uint8_t Max44009::getThresholdTimer() { - return read(MAX44009_THRESHOLD_TIMER, 1); + return read(MAX44009_THRESHOLD_TIMER); } void Max44009::setConfiguration(const uint8_t value) @@ -86,7 +89,7 @@ void Max44009::setConfiguration(const uint8_t value) uint8_t Max44009::getConfiguration() { - return read(MAX44009_CONFIGURATION, 1); + return read(MAX44009_CONFIGURATION); } void Max44009::setAutomaticMode() @@ -138,7 +141,7 @@ void Max44009::setThreshold(const uint8_t reg, const float value) float Max44009::getThreshold(uint8_t reg) { - uint16_t data = read(reg, 1); + uint8_t data = read(reg); uint8_t e = (data & 0xF0) >> 4; uint32_t m = ((data & 0x0F) << 4) + 0x0F; m <<= e; @@ -146,8 +149,7 @@ float Max44009::getThreshold(uint8_t reg) return val; } -// bytes is 1 or 2 -uint16_t Max44009::read(uint8_t reg, uint8_t bytes) +uint8_t Max44009::read(uint8_t reg) { Wire.beginTransmission(_address); Wire.write(reg); @@ -156,17 +158,15 @@ uint16_t Max44009::read(uint8_t reg, uint8_t bytes) { return _data; // last value } - if (Wire.requestFrom(_address, (uint8_t) bytes) != bytes) + if (Wire.requestFrom(_address, (uint8_t) 1) != 1) { _error = 10; return _data; // last value } #if (ARDUINO < 100) _data = Wire.receive(); - if (bytes == 2) _data = _data * 256 + Wire.receive(); #else _data = Wire.read(); - if (bytes == 2) _data = _data * 256 + Wire.read(); #endif return _data; }