Skip to content

Commit

Permalink
v5.11.1j - Update TSL2561 driver (arendst#1825)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Feb 8, 2018
1 parent 0908c33 commit badaa57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Fix Arilux RF induced exception by moving interrupt handler to iram on non esp/arduino lib v2.3.0
* Add NTP sync based on chip id (#1773)
* Fix regression from 5.11.1h web console and http input max length from 100 to 254 characters (#1819)
* Update TSL2561 driver (#1825)
*
* 5.11.1i
* Update TasmotaSerial library to 1.1.0
Expand Down
30 changes: 23 additions & 7 deletions sonoff/xsns_16_tsl2561.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@

uint8_t tsl2561_address;
uint8_t tsl2561_addresses[] = { TSL2561_ADDR_LOW, TSL2561_ADDR_FLOAT, TSL2561_ADDR_HIGH };
uint8_t tsl2561_type = 0;

//TSL2561 tsl(TSL2561_ADDR_FLOAT);
TSL2561 *tsl;
TSL2561 *tsl = 0;

void Tsl2561Detect()
{
if (tsl2561_type) {
if (tsl) {
return;
}

Expand All @@ -49,10 +48,12 @@ void Tsl2561Detect()
if (tsl->begin()) {
tsl->setGain(TSL2561_GAIN_16X);
tsl->setTiming(TSL2561_INTEGRATIONTIME_101MS);
tsl2561_type = 1;
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "TSL2561", tsl2561_address);
AddLog(LOG_LEVEL_DEBUG);
break;
} else {
delete tsl;
tsl = 0;
}
}
}
Expand All @@ -65,8 +66,23 @@ const char HTTP_SNS_TSL2561[] PROGMEM =

void Tsl2561Show(boolean json)
{
if (tsl2561_type) {
uint16_t illuminance = tsl->getLuminosity(TSL2561_VISIBLE);
if (tsl) {
union {
uint32_t full;
struct { uint16_t both, ir; };
} light;
light.full = tsl->getFullLuminosity();
uint32_t illuminance = 0;
if ((light.full == 0 || light.full == 0xffffffff)) {
if (!I2cDevice(tsl2561_address)) {
delete tsl;
tsl = 0;
}
} else {
illuminance = tsl->calculateLux(light.both, light.ir);
}
snprintf(log_data, sizeof(log_data), PSTR(D_ILLUMINANCE " 0x%08lx = b 0x%04x, i 0x%04x -> %lu " D_UNIT_LUX), light.full, light.both, light.ir, illuminance);
AddLog(LOG_LEVEL_DEBUG);

if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"TSL2561\":{\"" D_JSON_ILLUMINANCE "\":%d}"), mqtt_data, illuminance);
Expand Down Expand Up @@ -110,4 +126,4 @@ boolean Xsns16(byte function)
}

#endif // USE_TSL2561
#endif // USE_I2C
#endif // USE_I2C

0 comments on commit badaa57

Please sign in to comment.