![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
TSL2591 high-dynamic-range digital light sensor (I2C), reading full-spectrum and IR channels to compute lux. More...
#include <TSL2591.h>
Public Member Functions | |
| TSL2591 (E_TSL2591_IntegrationTime integrationTimeMilliseconds=E_TSL2591_IntegrationTime::ATIME_100MS, E_TSL2591_AmplificationGain amplificationGain=E_TSL2591_AmplificationGain::GAIN_MED) | |
| Builds a TSL2591 with the given integration time and gain, and default light-level cutoffs. More... | |
| virtual | ~TSL2591 () |
| Destroys the sensor. More... | |
| virtual void | TurnOn () override |
| Initializes the sensor over I2C, powers on the ALS, applies the timing/gain, and lets the sensor wake up, reporting progress through the AlertManager. More... | |
| virtual void | TurnOff () override |
| Turns the sensor off by disabling it over I2C (if it was initialized). More... | |
| virtual void | ProcessRawValues () override |
| Reads the raw CH0/CH1 channels, auto-adjusts gain if the reading is saturated or too dark (re-reading after a gain change), and recomputes the cached lux. More... | |
| virtual std::string | ToString () const override |
| Serializes the raw CH0/CH1 readings, calculated lux, and current gain to a string. More... | |
| virtual bool | AdjustAndValidateSettings (const uint16_t ch0) |
| Auto-adjusts the amplification gain one step down when the channel is flooded (> 62000) or one step up when it is too dark (< 100), pushing any change to the hardware. More... | |
| virtual float | CalculateLux (const uint16_t ch0, const uint16_t ch1) |
| Computes lux from the full-spectrum and IR channels, normalizing by counts-per-lux and rejecting IR, with a visible-approximation fallback for high-IR indoor environments; returns -1 on saturation/overflow. More... | |
| virtual float | GetLux () const |
| Gets the most recently calculated lux value. More... | |
| virtual E_LightLevel | CalculateLightLevel () const |
| Maps the most recent lux reading onto a 0 (pitch dark) to 5 (very bright) level. More... | |
| virtual E_LightLevel | CalculateLightLevel (const float lux) const |
| Maps a given lux value onto a light level, treating the negative saturation sentinel as very bright. More... | |
| void | SetLightLevelCutoffs (float dark, float veryDim, float dim, float normal, float bright) |
| Sets the ascending lux cutoffs that define the dark/very-dim/dim/normal/bright light-level buckets. More... | |
| virtual std::string | DetermineLightCategory () const |
| Gets the short, human-readable light category for the current reading. More... | |
| virtual std::string | DetermineLightCategory (const float lux) const |
| Gets the short, human-readable light level for a given lux, for a compact UI label (the Summary tile and the Home scene). More... | |
| virtual void | SetTiming (const E_TSL2591_IntegrationTime integrationTimeMilliseconds, const E_TSL2591_AmplificationGain amplificationGain) |
| Writes the combined integration-time and gain byte to the sensor's control register, reporting through the AlertManager (or warning if the device was not initialized). More... | |
Public Member Functions inherited from RumPi::BaseComponent | |
| BaseComponent () | |
| Builds a base component with an unknown type and an empty name. More... | |
| virtual | ~BaseComponent () |
| Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More... | |
| virtual void | TurnOn ()=0 |
| Turns the component on (e.g. More... | |
| virtual void | TurnOff ()=0 |
| Turns the component off. More... | |
| virtual std::string | ToString () const =0 |
| Serializes the component's current readings to a string (usually JSON). More... | |
| virtual void | ProcessRawValues ()=0 |
| Reads and processes the component's latest raw values (called once per poll). More... | |
| virtual EComponentType | GetComponentType () const |
| Gets the component's type. More... | |
| const std::string & | GetName () const |
| Gets the component's unique per-instance name. More... | |
| void | SetName (const std::string &name) |
| Sets the component's unique per-instance name. More... | |
Static Public Member Functions | |
| static float | ConvertIntegrationTimeToDecimalMilliseconds (const E_TSL2591_IntegrationTime integrationTimeMilliseconds) |
| Converts an integration-time enum to its value in milliseconds. More... | |
| static E_TSL2591_IntegrationTime | ConvertDecimalMillisecondsToIntegrationTime (const float decimalMilliseconds) |
| Converts a millisecond value to the closest integration-time enum at or below it. More... | |
| static float | ConvertAmplificationGainToDecimalMultiplier (const E_TSL2591_AmplificationGain amplificationGain) |
| Converts an amplification-gain enum to its decimal multiplier. More... | |
| static E_TSL2591_AmplificationGain | ConvertDecimalMultiplierToAmplificationGain (const float decimalMultiplier) |
| Converts a decimal gain multiplier to the closest amplification-gain enum at or below it. More... | |
Static Public Member Functions inherited from RumPi::BaseComponent | |
| static std::string | ComponentTypeToString (const EComponentType theComponentTypeToConvert) |
| Maps an EComponentType to its string name. More... | |
| static EComponentType | StringToComponentType (const std::string &theComponentTypeName) |
| Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More... | |
Private Attributes | |
| int | myFileDescriptor |
| The open i2c device file descriptor. More... | |
| uint16_t | myRawChannel0Reading |
| The most recent raw full-spectrum (CH0) reading. More... | |
| uint16_t | myRawChannel1Reading |
| The most recent raw infrared (CH1) reading. More... | |
| float | myCalculatedLux |
| The most recently calculated lux value. More... | |
| E_TSL2591_IntegrationTime | myIntegrationTimeMilliseconds |
| How long the sensor integrates each reading. More... | |
| E_TSL2591_AmplificationGain | myAmplificationGain |
| The current amplification gain. More... | |
| float | myLightCutoffDark |
| Upper lux bound of the "Dark" bucket. More... | |
| float | myLightCutoffVeryDim |
| Upper lux bound of the "Very Dim" bucket. More... | |
| float | myLightCutoffDim |
| Upper lux bound of the "Dim" bucket. More... | |
| float | myLightCutoffNormal |
| Upper lux bound of the "Normal" bucket. More... | |
| float | myLightCutoffBright |
| Upper lux bound of the "Bright" bucket. More... | |
Additional Inherited Members | |
Protected Attributes inherited from RumPi::BaseComponent | |
| EComponentType | myComponentType |
| The kind of component this is (set by each concrete subclass). More... | |
| std::string | myName |
| A unique per-instance name, assigned when the component is added to the manager. More... | |
TSL2591 high-dynamic-range digital light sensor (I2C), reading full-spectrum and IR channels to compute lux.
| RumPi::TSL2591::TSL2591 | ( | E_TSL2591_IntegrationTime | integrationTimeMilliseconds = E_TSL2591_IntegrationTime::ATIME_100MS, |
| E_TSL2591_AmplificationGain | amplificationGain = E_TSL2591_AmplificationGain::GAIN_MED |
||
| ) |
Builds a TSL2591 with the given integration time and gain, and default light-level cutoffs.
| [in] | integrationTimeMilliseconds | How long the sensor integrates each reading. |
| [in] | amplificationGain | The amplification gain to start with. |
|
virtual |
|
virtual |
Auto-adjusts the amplification gain one step down when the channel is flooded (> 62000) or one step up when it is too dark (< 100), pushing any change to the hardware.
| [in] | ch0 | The most recent raw full-spectrum (CH0) reading. |
|
virtual |
Maps the most recent lux reading onto a 0 (pitch dark) to 5 (very bright) level.
The category name and anything that wants a numeric level both derive from this, so the thresholds live in exactly one place.
|
virtual |
Maps a given lux value onto a light level, treating the negative saturation sentinel as very bright.
| [in] | lux | The lux value to categorize. |
|
virtual |
Computes lux from the full-spectrum and IR channels, normalizing by counts-per-lux and rejecting IR, with a visible-approximation fallback for high-IR indoor environments; returns -1 on saturation/overflow.
| [in] | ch0 | The raw full-spectrum (CH0) reading. |
| [in] | ch1 | The raw infrared (CH1) reading. |
|
static |
Converts an amplification-gain enum to its decimal multiplier.
Output: 25
| [in] | amplificationGain | The amplification-gain enum to convert. |
|
static |
Converts a millisecond value to the closest integration-time enum at or below it.
| [in] | decimalMilliseconds | The integration time, in milliseconds. |
|
static |
Converts a decimal gain multiplier to the closest amplification-gain enum at or below it.
| [in] | decimalMultiplier | The gain as a decimal multiplier. |
|
static |
Converts an integration-time enum to its value in milliseconds.
Output: 100
| [in] | integrationTimeMilliseconds | The integration-time enum to convert. |
|
virtual |
Gets the short, human-readable light category for the current reading.
|
virtual |
Gets the short, human-readable light level for a given lux, for a compact UI label (the Summary tile and the Home scene).
| [in] | lux | The lux value to categorize. |
|
virtual |
Gets the most recently calculated lux value.
|
overridevirtual |
Reads the raw CH0/CH1 channels, auto-adjusts gain if the reading is saturated or too dark (re-reading after a gain change), and recomputes the cached lux.
Implements RumPi::BaseComponent.
| void RumPi::TSL2591::SetLightLevelCutoffs | ( | float | dark, |
| float | veryDim, | ||
| float | dim, | ||
| float | normal, | ||
| float | bright | ||
| ) |
Sets the ascending lux cutoffs that define the dark/very-dim/dim/normal/bright light-level buckets.
| [in] | dark | Upper lux bound of the "Dark" bucket. |
| [in] | veryDim | Upper lux bound of the "Very Dim" bucket. |
| [in] | dim | Upper lux bound of the "Dim" bucket. |
| [in] | normal | Upper lux bound of the "Normal" bucket. |
| [in] | bright | Upper lux bound of the "Bright" bucket. |
|
virtual |
Writes the combined integration-time and gain byte to the sensor's control register, reporting through the AlertManager (or warning if the device was not initialized).
| [in] | integrationTimeMilliseconds | The integration time to set. |
| [in] | amplificationGain | The amplification gain to set. |
|
overridevirtual |
Serializes the raw CH0/CH1 readings, calculated lux, and current gain to a string.
Implements RumPi::BaseComponent.
|
overridevirtual |
Turns the sensor off by disabling it over I2C (if it was initialized).
Implements RumPi::BaseComponent.
|
overridevirtual |
Initializes the sensor over I2C, powers on the ALS, applies the timing/gain, and lets the sensor wake up, reporting progress through the AlertManager.
Implements RumPi::BaseComponent.
|
private |
The current amplification gain.
|
private |
The most recently calculated lux value.
|
private |
The open i2c device file descriptor.
|
private |
How long the sensor integrates each reading.
|
private |
Upper lux bound of the "Bright" bucket.
|
private |
Upper lux bound of the "Dark" bucket.
|
private |
Upper lux bound of the "Dim" bucket.
|
private |
Upper lux bound of the "Normal" bucket.
|
private |
Upper lux bound of the "Very Dim" bucket.
|
private |
The most recent raw full-spectrum (CH0) reading.
|
private |
The most recent raw infrared (CH1) reading.