issue #140 refactor constructor / configure

This commit is contained in:
RobTillaart 2020-01-27 17:06:52 +01:00
parent 8ddfb12b44
commit 029aab4219
5 changed files with 22 additions and 26 deletions

View File

@ -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();

View File

@ -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": {

View File

@ -1,5 +1,5 @@
name=Max44009
version=0.3.2
version=0.3.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for MAX44009 lux sensor Arduino.

View File

@ -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);

View File

@ -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.