-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from brentru/add-tsl2591
Add TSL2591 Light Sensor
- 1.0.0-beta.97
- 1.0.0-beta.96
- 1.0.0-beta.95
- 1.0.0-beta.94
- 1.0.0-beta.93
- 1.0.0-beta.92
- 1.0.0-beta.91
- 1.0.0-beta.90
- 1.0.0-beta.89
- 1.0.0-beta.88
- 1.0.0-beta.87
- 1.0.0-beta.86
- 1.0.0-beta.85
- 1.0.0-beta.84
- 1.0.0-beta.83
- 1.0.0-beta.82
- 1.0.0-beta.78
- 1.0.0-beta.77
- 1.0.0-beta.76
- 1.0.0-beta.75
- 1.0.0-beta.74
- 1.0.0-beta.73
- 1.0.0-beta.72
- 1.0.0-beta.71
- 1.0.0-beta.70
- 1.0.0-beta.69
- 1.0.0-beta.68
- 1.0.0-beta.66
- 1.0.0-beta.65
- 1.0.0-beta.64
- 1.0.0-beta.63
- 1.0.0-beta.62
- 1.0.0-beta.61
- 1.0.0-beta.60
- 1.0.0-beta.59
- 1.0.0-beta.58
- 1.0.0-beta.57
- 1.0.0-beta.56
- 1.0.0-beta.55
- 1.0.0-beta.54
- 1.0.0-beta.53
- 1.0.0-beta.52
- 1.0.0-beta.51
- 1.0.0-beta.50
- 1.0.0-beta.49
- 1.0.0-beta.48
- 1.0.0-beta.47
- 1.0.0-beta.46
- 1.0.0-beta.45
- 1.0.0-beta.44
- 1.0.0-beta.43
- 1.0.0-beta.42
- 1.0.0-beta.41
- 1.0.0-beta.40
- 1.0.0-beta.39
- 1.0.0-beta.38
- 1.0.0-beta.37
- 1.0.0-beta.36
- 1.0.0-beta.35
- 1.0.0-beta.34
- 1.0.0-beta.33
- 1.0.0-beta.32
- 1.0.0-beta.31
- 1.0.0-beta.30
- 1.0.0-beta.29
- 1.0.0-alpha.89
- 1.0.0-alpha.82
- 1.0.0-alpha.81
- 1.0.0-alpha.80
- 1.0.0-alpha.79
- 1.0.0-alpha.75
- 1.0.0-alpha.74
Showing
6 changed files
with
235 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
name=Adafruit WipperSnapper Beta | ||
version=1.0.0-beta.28 | ||
version=1.0.0-beta.29 | ||
author=Adafruit | ||
maintainer=Adafruit <[email protected]> | ||
sentence=Arduino client for Adafruit.io WipperSnapper | ||
paragraph=Arduino client for Adafruit.io WipperSnapper | ||
category=Communication | ||
url=https://github.com/adafruit/Adafruit_IO_Arduino | ||
architectures=* | ||
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library, Adafruit MCP9600 Library | ||
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/components/i2c/drivers/WipperSnapper_I2C_Driver_TSL2591.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_TSL2591.h | ||
* | ||
* Device driver for the TSL2591 digital luminosity (light) sensor. | ||
* | ||
* Adafruit invests time and resources providing this open source code, | ||
* please support Adafruit and open-source hardware by purchasing | ||
* products from Adafruit! | ||
* | ||
* Copyright (c) Brent Rubell 2022 for Adafruit Industries. | ||
* | ||
* MIT license, all text here must be included in any redistribution. | ||
* | ||
*/ | ||
#ifndef WipperSnapper_I2C_Driver_TSL2591_H | ||
#define WipperSnapper_I2C_Driver_TSL2591_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include <Adafruit_TSL2591.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a driver interface for a TSL2591 sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_TSL2591 : public WipperSnapper_I2C_Driver { | ||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for a TSL2591 sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
The 7-bit I2C address of the sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_TSL2591(TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Destructor for an TSL2591 sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
~WipperSnapper_I2C_Driver_TSL2591() { delete _tsl; } | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the TSL2591 sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { | ||
_tsl = new Adafruit_TSL2591(); | ||
// Attempt to initialize TSL2591 | ||
if (!_tsl->begin()) | ||
return false; | ||
|
||
// Configure TSL2591 sensor | ||
// Note: This driver uses the default configuration from | ||
// https://github.com/adafruit/Adafruit_TSL2591_Library/blob/master/examples/tsl2591/tsl2591.ino | ||
_tsl->setGain(TSL2591_GAIN_MED); // 25x gain | ||
_tsl->setTiming(TSL2591_INTEGRATIONTIME_300MS); // 300ms integration time | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Performs a light sensor read using the Adafruit | ||
Unified Sensor API. | ||
@param lightEvent | ||
Light sensor reading, in lux. | ||
@returns True if the sensor event was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventLight(sensors_event_t *lightEvent) { | ||
// Get sensor event | ||
_tsl->getEvent(lightEvent); | ||
|
||
// If lightEvent->light = 0 lux the sensor is probably saturated and no | ||
// reliable data could be generated! or if lightEvent->light is +/- | ||
// 4294967040 there was a float over/underflow | ||
if ((lightEvent->light == 0) | (lightEvent->light > 4294966000.0) | | ||
(lightEvent->light < -4294966000.0)) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
protected: | ||
Adafruit_TSL2591 *_tsl; ///< Pointer to TSL2591 light sensor object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_TSL2591 |