mirror of https://github.com/arendst/Tasmota.git
Update library Joba_Tsl2561 from 2.0.7 to 2.0.10
Update library Joba_Tsl2561 from 2.0.7 to 2.0.10
This commit is contained in:
parent
e8e7b25b80
commit
b800db4bac
|
@ -0,0 +1,8 @@
|
|||
.pioenvs
|
||||
.piolibdeps
|
||||
.clang_complete
|
||||
.gcc-flags.json
|
||||
examples/*/platformio.ini
|
||||
examples/*/lib
|
||||
examples/*/.gitignore
|
||||
examples/*/.travis.yml
|
|
@ -0,0 +1,4 @@
|
|||
.pioenvs
|
||||
.piolibdeps
|
||||
.clang_complete
|
||||
.gcc-flags.json
|
|
@ -0,0 +1,55 @@
|
|||
# Continuous Integration (CI) is the practice, in software
|
||||
# engineering, of merging all developer working copies with a shared mainline
|
||||
# several times a day < http://docs.platformio.org/page/ci/index.html >
|
||||
#
|
||||
# Documentation:
|
||||
#
|
||||
# * Travis CI Embedded Builds with PlatformIO
|
||||
# < https://docs.travis-ci.com/user/integration/platformio/ >
|
||||
#
|
||||
# * PlatformIO integration with Travis CI
|
||||
# < http://docs.platformio.org/page/ci/travis.html >
|
||||
#
|
||||
# * User Guide for `platformio ci` command
|
||||
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
|
||||
#
|
||||
#
|
||||
# Please choice one of the following templates (proposed below) and uncomment
|
||||
# it (remove "# " before each line) or use own configuration according to the
|
||||
# Travis CI documentation (see above).
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# Template #1: General project. Test it using existing `platformio.ini`.
|
||||
#
|
||||
|
||||
# language: python
|
||||
# python:
|
||||
# - "2.7"
|
||||
#
|
||||
# install:
|
||||
# - pip install -U platformio
|
||||
#
|
||||
# script:
|
||||
# - platformio run
|
||||
|
||||
|
||||
#
|
||||
# Template #2: The project is intended to by used as a library with examples
|
||||
#
|
||||
|
||||
# language: python
|
||||
# python:
|
||||
# - "2.7"
|
||||
#
|
||||
# env:
|
||||
# - PLATFORMIO_CI_SRC=path/to/test/file.c
|
||||
# - PLATFORMIO_CI_SRC=examples/file.ino
|
||||
# - PLATFORMIO_CI_SRC=path/to/test/directory
|
||||
#
|
||||
# install:
|
||||
# - pip install -U platformio
|
||||
#
|
||||
# script:
|
||||
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
|
|
@ -1,4 +1,4 @@
|
|||
This is a library for the TSL2561 digital luminosity sensors from Ams (Taos).
|
||||
This is an Arduino library for the TSL2561 digital luminosity sensors from Ams (Taos).
|
||||
|
||||
Design goals:
|
||||
* It is modularized so you can use only what you need if space/ram is constrained.
|
||||
|
@ -18,3 +18,5 @@ The library has 3 classes:
|
|||
Tsl2561 All register access as described in the datasheet, except for interrupts
|
||||
Tsl2561Util Convenience functions like lux calculation or automatic gain
|
||||
Tsl2561Int TODO, Interrupt related stuff (not needed if int pin unconnected)
|
||||
|
||||
Tested with boards Nano, ESP8266 and ESP32
|
|
@ -21,7 +21,7 @@ This file is part of the Joba_Tsl2561 Library.
|
|||
|
||||
#include <Tsl2561Util.h>
|
||||
|
||||
// to mimic Serial.printf() of esp8266 core for other platforms
|
||||
// to mimic Serial.printf() of esp cores for other platforms
|
||||
char *format( const char *fmt, ... ) {
|
||||
static char buf[128];
|
||||
va_list arg;
|
||||
|
@ -37,7 +37,7 @@ uint8_t id;
|
|||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Wire.begin();
|
||||
Wire.begin(TSL2561_SDA, TSL2561_SCL);
|
||||
while( !Tsl.begin() )
|
||||
; // wait until chip detected or wdt reset
|
||||
Serial.println("\nStarting Tsl2561Util autogain loop");
|
|
@ -21,7 +21,7 @@ This file is part of the Joba_Tsl2561 Library.
|
|||
|
||||
#include <Tsl2561.h>
|
||||
|
||||
// to mimic Serial.printf() of esp8266 core for other platforms
|
||||
// to mimic Serial.printf() of esp cores for other platforms
|
||||
char *format( const char *fmt, ... ) {
|
||||
static char buf[128];
|
||||
va_list arg;
|
||||
|
@ -36,7 +36,7 @@ Tsl2561 Tsl(Wire);
|
|||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Wire.begin();
|
||||
Wire.begin(TSL2561_SDA, TSL2561_SCL);
|
||||
Serial.println("\nStarting Tsl2561 simple loop");
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ void loop() {
|
|||
Tsl.off();
|
||||
}
|
||||
else {
|
||||
Serial.println("No Tsl2561 found. Check wiring.");
|
||||
Serial.print(format("No Tsl2561 found. Check wiring: SCL=%u, SDA=%u\n", TSL2561_SCL, TSL2561_SDA));
|
||||
}
|
||||
|
||||
delay(5000);
|
|
@ -22,7 +22,7 @@ This file is part of the Joba_Tsl2561 Library.
|
|||
|
||||
#include <Tsl2561.h>
|
||||
|
||||
// to mimic Serial.printf() of esp8266 core for other platforms
|
||||
// to mimic Serial.printf() of esp cores for other platforms
|
||||
char *format( const char *fmt, ... ) {
|
||||
static char buf[128];
|
||||
va_list arg;
|
||||
|
@ -158,7 +158,7 @@ void test( Tsl2561 &tsl ) {
|
|||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Wire.begin();
|
||||
Wire.begin(TSL2561_SDA, TSL2561_SCL);
|
||||
Serial.println("\nStarting Tsl2561 testing loop");
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ This file is part of the Joba_Tsl2561 Library.
|
|||
|
||||
#include <Tsl2561Util.h>
|
||||
|
||||
// to mimic Serial.printf() of esp8266 core for other platforms
|
||||
// to mimic Serial.printf() of esp cores for other platforms
|
||||
char *format( const char *fmt, ... ) {
|
||||
static char buf[128];
|
||||
va_list arg;
|
||||
|
@ -37,7 +37,7 @@ Tsl2561 Tsl(Wire);
|
|||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Wire.begin();
|
||||
Wire.begin(TSL2561_SDA, TSL2561_SCL);
|
||||
Serial.println("\nStarting Tsl2561Util loop");
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ void loop() {
|
|||
}
|
||||
|
||||
if( !found ) {
|
||||
Serial.println("No Tsl2561 found. Check wiring.");
|
||||
Serial.print(format("No Tsl2561 found. Check wiring: SCL=%u, SDA=%u\n", TSL2561_SCL, TSL2561_SDA));
|
||||
}
|
||||
|
||||
delay(5000);
|
|
@ -18,9 +18,13 @@
|
|||
|
||||
|
||||
[platformio]
|
||||
src_dir = .
|
||||
lib_dir = ../..
|
||||
|
||||
; uncomment one, if you want to build only one
|
||||
; env_default = nodemcuv2
|
||||
; env_default = nano328
|
||||
; env_default = espressif32
|
||||
|
||||
|
||||
[env:nodemcuv2]
|
||||
|
@ -28,12 +32,12 @@
|
|||
; ------------
|
||||
; GND <-> GND
|
||||
; VCC <-> 3V
|
||||
; SCL <-> D1
|
||||
; SDA <-> D2
|
||||
; SCL <-> D1 (other pin can be defined below)
|
||||
; SDA <-> D2 (other pin can be defined below)
|
||||
platform = espressif8266
|
||||
board = nodemcuv2
|
||||
framework = arduino
|
||||
build_flags = -Wall
|
||||
build_flags = -Wall -DTSL2561_SCL=D1 -DTSL2561_SDA=D2
|
||||
|
||||
monitor_speed = 115200
|
||||
|
||||
|
@ -53,6 +57,25 @@ upload_resetmethod = nodemcu
|
|||
platform = atmelavr
|
||||
board = nanoatmega328
|
||||
framework = arduino
|
||||
build_flags = -Wall
|
||||
build_flags = -Wall -DTSL2561_SCL=A5 -DTSL2561_SDA=A4
|
||||
|
||||
monitor_speed = 115200
|
||||
;upload_port = /dev/ttyUSB[1-9]
|
||||
|
||||
|
||||
[env:espressif32]
|
||||
; TSL <-> ESP32
|
||||
; ------------
|
||||
; GND <-> GND
|
||||
; VCC <-> 3V
|
||||
; SCL <-> IO22 (other pin can be defined below)
|
||||
; SDA <-> IO21 (other pin can be defined below)
|
||||
platform = espressif32
|
||||
board = mhetesp32minikit
|
||||
framework = arduino
|
||||
build_flags = -Wall -DTSL2561_SCL=22 -DTSL2561_SDA=21
|
||||
|
||||
monitor_speed = 115200
|
||||
|
||||
upload_speed = 921600
|
||||
;upload_port = /dev/ttyUSB[1-9]
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"name": "Joba_Tsl2561",
|
||||
"version": "2.0.7",
|
||||
"version": "2.0.10",
|
||||
"keywords": "twowire, i2c, bus, sensor, luminosity, illuminance, lux",
|
||||
"description": "Arduino Library for ams (taos) luminance chip Tsl2561 with autogain",
|
||||
"description": "Arduino library for ams (taos) luminance chip Tsl2561 with autogain. Tested with Nano, Esp8266 and Esp32.",
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
|
@ -1,9 +1,9 @@
|
|||
name=Joba Tsl2561 Library
|
||||
version=2.0.7
|
||||
version=2.0.10
|
||||
author=joba-1
|
||||
maintainer=joba-1 <joban123.psn@gmail.com>
|
||||
sentence=IoT library for using the Tsl2561 luminosity sensor
|
||||
paragraph=Luminosity measurement in lux with autogain
|
||||
paragraph=Luminosity measurement in lux with autogain. Tested with Nano, Esp8266 and Esp32.
|
||||
category=Sensors
|
||||
url=https://github.com/joba-1/Joba_Tsl2561
|
||||
architectures=*
|
|
@ -18,20 +18,19 @@
|
|||
|
||||
|
||||
[platformio]
|
||||
src_dir = .
|
||||
lib_dir = ../..
|
||||
|
||||
; uncomment one, if you want to build only one
|
||||
; env_default = nodemcuv2
|
||||
; env_default = nano328
|
||||
; env_default = espressif32
|
||||
|
||||
|
||||
[env:nodemcuv2]
|
||||
; TSL <-> ESP8266
|
||||
; ------------
|
||||
; GND <-> GND
|
||||
; VCC <-> 3V
|
||||
; SCL <-> D1
|
||||
; SDA <-> D2
|
||||
; SCL <-> D1 (other pin can be defined below)
|
||||
; SDA <-> D2 (other pin can be defined below)
|
||||
platform = espressif8266
|
||||
board = nodemcuv2
|
||||
framework = arduino
|
||||
|
@ -58,4 +57,21 @@ framework = arduino
|
|||
build_flags = -Wall
|
||||
|
||||
monitor_speed = 115200
|
||||
|
||||
|
||||
[env:espressif32]
|
||||
; TSL <-> ESP32
|
||||
; ------------
|
||||
; GND <-> GND
|
||||
; VCC <-> 3V
|
||||
; SCL <-> IO22 (other pin can be defined below)
|
||||
; SDA <-> IO21 (other pin can be defined below)
|
||||
platform = espressif32
|
||||
board = mhetesp32minikit
|
||||
framework = arduino
|
||||
build_flags = -Wall -DTSL2561_SCL=22 -DTSL2561_SDA=21
|
||||
|
||||
monitor_speed = 115200
|
||||
|
||||
upload_speed = 921600
|
||||
;upload_port = /dev/ttyUSB[1-9]
|
|
@ -23,6 +23,14 @@ This file is part of the Joba_Tsl2561 Library.
|
|||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// To be able to override pin definitions in build flags (used in examples)
|
||||
#ifndef TSL2561_SDA
|
||||
#define TSL2561_SDA SDA
|
||||
#endif
|
||||
#ifndef TSL2561_SCL
|
||||
#define TSL2561_SCL SCL
|
||||
#endif
|
||||
|
||||
class Tsl2561 {
|
||||
|
||||
public:
|
|
@ -22,9 +22,10 @@ This file is part of the Joba_Tsl2561 Library.
|
|||
namespace Tsl2561Util {
|
||||
|
||||
// Tsl2561Util::normalizedLuminosity returncode false can mean:
|
||||
// - saturation: full and/or ir have value ~0 (aka -1)
|
||||
// - saturation: full and/or ir have value ~0 (aka -1) and not shortest exposure
|
||||
// - manual exposure time: full and ir are corrected only for gain
|
||||
// If true, full and ir have values as if exposure was 402 and gain 16.
|
||||
// If true, full and ir have values as if exposure was 402 and gain 16
|
||||
// or ~0 if saturated even at shortest exposure
|
||||
bool normalizedLuminosity( bool gain, Tsl2561::exposure_t exposure, uint32_t &full, uint32_t &ir ) {
|
||||
|
||||
uint16_t scaledFull = (uint16_t)full;
|
||||
|
@ -39,8 +40,8 @@ bool normalizedLuminosity( bool gain, Tsl2561::exposure_t exposure, uint32_t &fu
|
|||
|
||||
switch( exposure ) {
|
||||
case Tsl2561::EXP_14:
|
||||
full = (scaledFull >= 5047/4*3) ? 0xffffffff : ((full + 5) * 322) / 11;
|
||||
ir = (scaledIr >= 5047/4*3) ? 0xffffffff : ((ir + 5) * 322) / 11;
|
||||
full = (scaledFull == 5047) ? 0xffffffff : ((full + 5) * 322) / 11;
|
||||
ir = (scaledIr == 5047) ? 0xffffffff : ((ir + 5) * 322) / 11;
|
||||
break;
|
||||
case Tsl2561::EXP_101:
|
||||
full = (scaledFull >= 37177/4*3) ? 0xffffffff : ((full + 40) * 322) / 81;
|
||||
|
@ -54,7 +55,7 @@ bool normalizedLuminosity( bool gain, Tsl2561::exposure_t exposure, uint32_t &fu
|
|||
return false;
|
||||
}
|
||||
|
||||
return full != 0xffffffff && ir != 0xffffffff;
|
||||
return exposure == Tsl2561::EXP_14 || (full != 0xffffffff && ir != 0xffffffff);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -93,6 +94,8 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t
|
|||
{ true, Tsl2561::EXP_402 } // max
|
||||
};
|
||||
|
||||
// Serial.printf("autoGain start: gain=%u, expo=%u\n", gain, exposure);
|
||||
|
||||
// get current sensitivity
|
||||
if( !tsl.getSensitivity(gain, exposure) ) {
|
||||
return false; // I2C error
|
||||
|
@ -110,9 +113,10 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t
|
|||
return false; // should not happen...
|
||||
}
|
||||
|
||||
// in a loop wait for next sample, get values and adjust sensitivity if needed
|
||||
// sometimes sensor reports high brightness although it is darker.
|
||||
uint8_t retryOnSaturated = 10;
|
||||
|
||||
// in a loop wait for next sample, get values and adjust sensitivity if needed
|
||||
while( true ) {
|
||||
waitNext(exposure);
|
||||
|
||||
|
@ -122,11 +126,14 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t
|
|||
|
||||
uint16_t limit = getLimit(exposure);
|
||||
if( full >= 1000 && full <= limit ) {
|
||||
return true; // new value within limits
|
||||
// Serial.printf("autoGain normal full=%u, limits=1000-%u, curr=%u\n", full, limit, curr);
|
||||
return true; // new value within limits of good accuracy
|
||||
}
|
||||
|
||||
// adjust sensitivity, if possible
|
||||
if( (full < 1000 && ++curr < sizeof(sensitivity)/sizeof(sensitivity[0]))
|
||||
|| (full > limit && curr-- > 0) ) {
|
||||
// Serial.printf("autoGain adjust full=%u, limits=1000-%u, curr=%u\n", full, limit, curr);
|
||||
if( !tsl.setSensitivity(sensitivity[curr].gain, sensitivity[curr].exposure) ) {
|
||||
return false; // I2C error
|
||||
}
|
||||
|
@ -134,7 +141,10 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t
|
|||
exposure = sensitivity[curr].exposure;
|
||||
}
|
||||
else {
|
||||
if( ++curr > 0 && retryOnSaturated-- == 0 ) {
|
||||
// sensitivity already is at minimum or maximum
|
||||
if( ++curr > 0 || retryOnSaturated-- == 0 ) {
|
||||
// Serial.printf("autoGain limit full=%u, ir=%u, limits=1000-%u, curr=%u, retry=%u\n", full, ir, limit, curr, retryOnSaturated);
|
||||
// dark, or repeatedly confirmed high brightness
|
||||
return true; // saturated, but best we can do
|
||||
}
|
||||
}
|
||||
|
@ -176,6 +186,11 @@ bool milliLux( uint32_t full, uint32_t ir, uint32_t &mLux, bool csType, uint8_t
|
|||
return true;
|
||||
}
|
||||
|
||||
if( full == 0xffffffff || ir == 0xffffffff ) {
|
||||
mLux = 99999999; // indicates saturation at shortest exposure
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t milliRatio = ir * 1000 / full;
|
||||
|
||||
if( csType ) {
|
Loading…
Reference in New Issue