Skip to content

Commit

Permalink
add changelog.md (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart authored Nov 16, 2022
1 parent ee2a235 commit d8eeff6
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 118 deletions.
16 changes: 16 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
Expand All @@ -9,3 +24,4 @@ compile:
- esp32
# - esp8266
# - mega2560
- rpipico
99 changes: 99 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Change Log MAX44009

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.5.3] - 2022-11-16
- add RP2040 in build-CI
- add changelog.md
- minor edit readme.md


## [0.5.2] - 2022-01-05
- minor edits after creating Max44007 library

## [0.5.1] - 2021-12-21
- update library.json
- update license
- minor edits

## [0.5.0] - 2021-06-04
- fix exponent math.

----

## [0.4.4] - 2021-05-27
- add Arduino-lint

## [0.4.3] - 2020-12-30
- Arduino-CI, unit test

## [0.4.2] - 2020-06-19
- fix library.json

## [0.4.1] - 2020-03-21
- add #pragma
- update readme.md
- license.md

## [0.4.0] - 2020-01-30
- remove automatic mode from constructors;
- added example code

----

## [0.3.3] - 2020-01-27
- fix #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

## [0.3.1] - 2020-01-21
- fix #133 overflow of the exponent.

## [0.3.0] - 2020-01-20
- fix #141 Kudos to Moritz89

## [0.2.0] - 2019-08-23
- solve #127 == redo #118

----

## [0.1.10] - 2018-12-08
- issue #118 Fix constructor esp8266 (thanks to Bolukan)

## [0.1.9] - 2018-07-01
- issue #108 Fix shift math (thanks Roland vandecook)

## [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]
- update history

## [0.1.4]
- added setAutomaticMode() to max44009.h (thanks debsahu)

## [0.1.03]
- added configuration

## [0.1.02]
- added threshold code

## [0.1.01]
- added interrupt code

## [0.1.00] - 2010-??-??
- initial version.

56 changes: 13 additions & 43 deletions Max44009.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@
//
// FILE: Max44009.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.5.2
// VERSION: 0.5.3
// PURPOSE: library for MAX44009 lux sensor Arduino
// URL: https://github.com/RobTillaart/MAX44009
//
// HISTORY
//
// 0.5.2 2022-01-05 minor edits after creating Max44007 library
// 0.5.1 2021-12-21 update library.json, license, minor edits
// 0.5.0 2021-06-04 fix exponent math.
// 0.4.4 2021-05-27 Arduino-lint
// 0.4.3 2020-12-30 Arduino-CI, unit test
// 0.4.2 2020-06-19 fix library.json
// 0.4.1 2020-03-21 #pragma, readme.md, license.md
// 0.4.0 2020-01-30 remove automatic mode from constructors;
// added example code
// 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
// 0.3.1 2020-01-21 issue #133 overflow of the exponent
// 0.3.0 2020-01-20 issue #141 Kudos to Moritz89
// 0.2.0 2019-08-23 solve #127 == redo #118
// 0.1.10 2018-12-08 issue #118 Fix constructor esp8266
// (thanks to Bolukan)
// 0.1.9 2018-07-01 issue #108 Fix shift math
// (thanks Roland vandecook)
// 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
// 0.1.4 added setAutomaticMode() to max44009.h (thanks debsahu)
// 0.1.03 added configuration
// 0.1.02 added threshold code
// 0.1.01 added interrupt code
// 0.1.00 initial version
// HISTORY: see changelog.md



#include "Max44009.h"
Expand Down Expand Up @@ -207,12 +177,12 @@ void Max44009::clrContinuousMode()

void Max44009::setManualMode(uint8_t CDR, uint8_t TIM)
{
if (CDR !=0) CDR = 1; // only 0 or 1
if (CDR !=0) CDR = 1; // only 0 or 1
if (TIM > 7) TIM = 7;
uint8_t config = read(MAX44009_CONFIGURATION);
config |= MAX44009_CFG_MANUAL;
config &= 0xF0; // clear old CDR & TIM bits
config |= CDR << 3 | TIM; // set new CDR & TIM bits
config &= 0xF0; // clear old CDR & TIM bits
config |= CDR << 3 | TIM; // set new CDR & TIM bits
write(MAX44009_CONFIGURATION, config);
}

Expand All @@ -228,18 +198,18 @@ float Max44009::convertToLux(uint8_t datahigh, uint8_t datalow)

///////////////////////////////////////////////////////////
//
// PRIVATE
// PRIVATE
//
bool Max44009::setThreshold(const uint8_t reg, const float value)
{
// CHECK RANGE OF VALUE
// CHECK RANGE OF VALUE
if ((value < 0.0) || (value > MAX44009_MAX_LUX)) return false;

uint32_t mantissa = round(value * (1.0 / MAX44009_MIN_LUX)); // compile time optimized.
uint8_t exponent = 0;
while (mantissa > 255)
{
mantissa >>= 1; // bits get lost
mantissa >>= 1; // bits get lost
exponent++;
};
mantissa = (mantissa >> 4) & 0x0F;
Expand All @@ -252,7 +222,7 @@ bool Max44009::setThreshold(const uint8_t reg, const float value)
float Max44009::getThreshold(uint8_t reg)
{
uint8_t datahigh = read(reg);
float lux = convertToLux(datahigh, 0x08); // 0x08 = correction for lost bits
float lux = convertToLux(datahigh, 0x08); // 0x08 = correction for lost bits
return lux;
}

Expand All @@ -264,12 +234,12 @@ uint8_t Max44009::read(uint8_t reg)
_error = _wire->endTransmission();
if (_error != MAX44009_OK)
{
return _data; // last value
return _data; // last value
}
if (_wire->requestFrom(_address, (uint8_t) 1) != 1)
{
_error = MAX44009_ERROR_WIRE_REQUEST;
return _data; // last value
return _data; // last value
}
_data = _wire->read();
return _data;
Expand All @@ -285,4 +255,4 @@ void Max44009::write(uint8_t reg, uint8_t value)
}


// -- END OF FILE --
// -- END OF FILE --
89 changes: 45 additions & 44 deletions Max44009.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@

// FILE: Max44009.h
// AUTHOR: Rob dot Tillaart at gmail dot com
// VERSION: 0.5.2
// VERSION: 0.5.3
// PURPOSE: library for MAX44009 lux sensor Arduino
// HISTORY: See Max440099.cpp
// HISTORY: See changelog.md


// breakout MAX44009 / GY-49
// breakout MAX44009 / GY-49
//
// +--------+
// VCC |o |
// GND |o |
// SCL |o o| ADDRESS
// SDA |o o| -INT
// +--------+
// +--------+
// VCC |o |
// GND |o |
// SCL |o o| ADDRESS
// SDA |o o| -INT
// +--------+
//
// ADDRESS:
// 0 = 0x4A
// 1 = 0x4B
// ADDRESS:
// 0 = 0x4A
// 1 = 0x4B
//
// INT:
// Connect the INT pin to an pull up resistor
// 0 = interrupt
// 1 = no interrupt
// connect to an LED or an interrupt pin of an Arduino
// INT:
// Connect the INT pin to an pull up resistor
// 0 = interrupt
// 1 = no interrupt
// connect to an LED or an interrupt pin of an Arduino
//


#include "Wire.h"
#include "Arduino.h"


#define MAX44009_LIB_VERSION (F("0.5.2"))
#define MAX44009_LIB_VERSION (F("0.5.3"))

#define MAX44009_DEFAULT_ADDRESS 0x4A
#define MAX44009_ALT_ADDRESS 0x4B
Expand Down Expand Up @@ -67,59 +67,60 @@
class Max44009
{
public:
// enum class to prevent bool to be implicitly casted to int
// enum class to prevent bool to be implicitly casted to int
enum class Boolean { True, False };

#if defined(ESP8266) || defined(ESP32)
// dataPin and clockPin can be used for ESP8266
// dataPin and clockPin can be used for ESP8266
Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin);
#endif

// ctor for UNO
// constructor for UNO
Max44009(const uint8_t address, const Boolean begin = Boolean::True);
// default ctor with default address
// default constructor with default address
Max44009(const Boolean begin = Boolean::True);
// Change I2C interface and address
// Change I2C interface and address
void configure(const uint8_t address, TwoWire *wire, const Boolean begin = Boolean::True);

bool isConnected();
float getLux();
int getError();

// threshold must be between 0 and 188006
bool setHighThreshold(const float value); // returns false if value out of range
// threshold must be between 0 and 188006
bool setHighThreshold(const float value); // returns false if value out of range
float getHighThreshold(void);
bool setLowThreshold(const float value); // returns false if value out of range
bool setLowThreshold(const float value); // returns false if value out of range
float getLowThreshold(void);
void setThresholdTimer(const uint8_t value); // 2 seems practical minimum
void setThresholdTimer(const uint8_t value); // 2 seems practical minimum
uint8_t getThresholdTimer();

void enableInterrupt() { write(MAX44009_INTERRUPT_ENABLE, 1); };
void disableInterrupt() { write(MAX44009_INTERRUPT_ENABLE, 0); };
bool interruptEnabled() { return read(MAX44009_INTERRUPT_ENABLE) & 0x01; };
uint8_t getInterruptStatus() { return read(MAX44009_INTERRUPT_STATUS) & 0x01; };

// check datasheet for detailed behavior
// check datasheet for detailed behaviour
void setConfiguration(uint8_t);
uint8_t getConfiguration();
void setAutomaticMode();
void setContinuousMode(); // uses more power
void clrContinuousMode(); // uses less power
// CDR = Current Divisor Ratio
// CDR = 1 ==> only 1/8th is measured
// TIM = Time Integration Measurement (table)
// 000 800ms
// 001 400ms
// 010 200ms
// 011 100ms
// 100 50ms manual only
// 101 25ms manual only
// 110 12.5ms manual only
// 111 6.25ms manual only
void setContinuousMode(); // uses more power
void clrContinuousMode(); // uses less power

// CDR = Current Divisor Ratio
// CDR = 1 ==> only 1/8th is measured
// TIM = Time Integration Measurement (table)
// 000 800ms
// 001 400ms
// 010 200ms
// 011 100ms
// 100 50ms manual only
// 101 25ms manual only
// 110 12.5ms manual only
// 111 6.25ms manual only
void setManualMode(uint8_t CDR, uint8_t TIM);
int getIntegrationTime() { return 800 >> (getConfiguration() & 0x07); }; // ms
int getIntegrationTime() { return 800 >> (getConfiguration() & 0x07); }; // ms

// TEST the math
// TEST the math
float convertToLux(uint8_t datahigh, uint8_t datalow);


Expand All @@ -138,5 +139,5 @@ class Max44009
};


// -- END OF FILE --
// -- END OF FILE --

Loading

0 comments on commit d8eeff6

Please sign in to comment.