IoT Drivers  v3.3.0 (S2022)
Engineering in Software Technology
Basic TSL2591 driver functions

Commonly used functions. Here you you will find the functions you normally will need. More...

Collaboration diagram for Basic TSL2591 driver functions:

Functions

tsl2591_returnCode_t tsl2591_enable (void)
 Enable/Power up the TSL2591 sensor. More...
 
tsl2591_returnCode_t tsl2591_disable (void)
 Disable/Power down the TSL2591 sensor. More...
 
tsl2591_returnCode_t tsl2591_fetchDeviceId (void)
 Start fetching the TSL2591 sensor's device ID. More...
 
uint8_t tsl2591_getDeviceId (void)
 Retrieve the TSL2591 sensor's device ID. More...
 
tsl2591_returnCode_t tsl2591_setGainAndIntegrationTime (tsl2591_gain_t gain, tsl2591_integrationTime_t integrationTime)
 Sets the TSL2591 sensor's Gain and Integration time. More...
 
tsl2591_gain_t tsl2591_getGain (void)
 Retrieve the TSL2591 sensor's current gain setting. More...
 
tsl2591_integrationTime_t tsl2591_getIntegrationTime (void)
 Retrieve the TSL2591 sensor's current integration time. More...
 
tsl2591_returnCode_t tsl2591_fetchData (void)
 Start fetching the TSL2591 sensor's light data. More...
 
tsl2591_returnCode_t tsl259_getVisibleRaw (uint16_t *visible)
 Retrieve the latest visible light spectrum as raw data fetched from the TSL2591 sensor. More...
 
tsl2591_returnCode_t tsl2591_getInfraredRaw (uint16_t *infrared)
 Retrieve the latest infrared light spectrum as raw data fetched from the TSL2591 sensor. More...
 
tsl2591_returnCode_t tsl2591_getFullSpectrumRaw (uint16_t *fullSpectrum)
 Retrieve the latest full light spectrum as raw data fetched from the TSL2591 sensor. More...
 
tsl2591_returnCode_t tsl2591_getCombinedDataRaw (tsl2591_combinedData_t *combinedData)
 Retrieve the latest combined light spectrum's as raw data fetched from the TSL2591 sensor. More...
 
tsl2591_returnCode_t tsl2591_getLux (float *lux)
 Retrieve the latest visible light spectrum as lux fetched from the TSL2591 sensor. More...
 

Detailed Description

Commonly used functions. Here you you will find the functions you normally will need.

Note
Interrupt must be enabled with sei() before any of the functions in this section must be called!!

Function Documentation

◆ tsl2591_disable()

tsl2591_returnCode_t tsl2591_disable ( void  )

Disable/Power down the TSL2591 sensor.

Note
The sensor is not powered down before the driver calls the call-back function with TSL2591_OK as argument.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe disable sensor/powered down command is send to the sensor.
TSL2591_BUSYThe driver is busy.
TSL2591_DRIVER_NOT_INITIALISEDThe driver is not initialised - and can not be used!!

◆ tsl2591_enable()

tsl2591_returnCode_t tsl2591_enable ( void  )

Enable/Power up the TSL2591 sensor.

Note
The sensor is not ready before the driver calls the call-back function with TSL2591_OK as argument.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe enable sensor/powered up command is send to the sensor.
TSL2591_BUSYThe driver is busy.
TSL2591_DRIVER_NOT_INITIALISEDThe driver is not initialised - and can not be used!!

◆ tsl2591_fetchData()

tsl2591_returnCode_t tsl2591_fetchData ( void  )

Start fetching the TSL2591 sensor's light data.

Note
The sensors data is not ready before the driver calls the call-back function with TSL2591_DATA_READY as argument.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe fetch command is send to the sensor. Await the callback before the light data is retrieved with tsl259_getVisibleRaw, tsl2591_getInfraredRaw, tsl2591_getFullSpectrumRaw, tsl2591_getCombinedDataRaw or tsl2591_getLux.
TSL2591_BUSYThe driver is busy.
TSL2591_DRIVER_NOT_INITIALISEDThe driver is not initialised - and can not be used!!

◆ tsl2591_fetchDeviceId()

tsl2591_returnCode_t tsl2591_fetchDeviceId ( void  )

Start fetching the TSL2591 sensor's device ID.

Note
The ID is not available before the driver calls the call-back function with TSL2591_DEV_ID_READY as argument.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe fetch command is send to the sensor. Await the callback before the ID is retrieved with tsl2591_getDeviceId.
TSL2591_BUSYThe driver is busy.
TSL2591_DRIVER_NOT_INITIALISEDThe driver is not initialised - and can not be used!!

◆ tsl2591_getCombinedDataRaw()

tsl2591_returnCode_t tsl2591_getCombinedDataRaw ( tsl2591_combinedData_t combinedData)

Retrieve the latest combined light spectrum's as raw data fetched from the TSL2591 sensor.

Parameters
[out]*combinedDatapointer to the struct variable where the data will be stored tsl2591_combinedData_t.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe light data retrieved OK.
TSL2591_OVERFLOWThe last measuring is in overflow - consider a lower gain.
TSL2591_UNDERFLOWThe last measuring is in underflow - consider a higher gain.

◆ tsl2591_getDeviceId()

uint8_t tsl2591_getDeviceId ( void  )

Retrieve the TSL2591 sensor's device ID.

Note
The sensors ID will always be 0x50.
Returns
The sensor's latest fetched device ID.

◆ tsl2591_getFullSpectrumRaw()

tsl2591_returnCode_t tsl2591_getFullSpectrumRaw ( uint16_t *  fullSpectrum)

Retrieve the latest full light spectrum as raw data fetched from the TSL2591 sensor.

Parameters
[out]*fullSpectrumpointer to the variable where the data will be stored.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe light data retrieved OK.
TSL2591_OVERFLOWThe last measuring is in overflow - consider a lower gain.
TSL2591_UNDERFLOWThe last measuring is in underflow - consider a higher gain.

◆ tsl2591_getGain()

tsl2591_gain_t tsl2591_getGain ( void  )

Retrieve the TSL2591 sensor's current gain setting.

Returns
The sensor's current gain.

◆ tsl2591_getInfraredRaw()

tsl2591_returnCode_t tsl2591_getInfraredRaw ( uint16_t *  infrared)

Retrieve the latest infrared light spectrum as raw data fetched from the TSL2591 sensor.

Parameters
[out]*infraredpointer to the variable where the data will be stored.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe light data retrieved OK.
TSL2591_OVERFLOWThe last measuring is in overflow - consider a lower gain.
TSL2591_UNDERFLOWThe last measuring is in underflow - consider a higher gain.

◆ tsl2591_getIntegrationTime()

tsl2591_integrationTime_t tsl2591_getIntegrationTime ( void  )

Retrieve the TSL2591 sensor's current integration time.

Returns
The sensor's current integration time.

◆ tsl2591_getLux()

tsl2591_returnCode_t tsl2591_getLux ( float *  lux)

Retrieve the latest visible light spectrum as lux fetched from the TSL2591 sensor.

Note
Fetch of the TSL2591 sensor's light data must be performed tsl2591_fetchData before this function can be used.
Parameters
[out]*luxpointer to the variable where the data will be stored.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe light data retrieved OK.
TSL2591_OVERFLOWThe last measuring is in overflow - consider a lower gain.

◆ tsl2591_setGainAndIntegrationTime()

tsl2591_returnCode_t tsl2591_setGainAndIntegrationTime ( tsl2591_gain_t  gain,
tsl2591_integrationTime_t  integrationTime 
)

Sets the TSL2591 sensor's Gain and Integration time.

The sensor supports four gain and six different integration times settings.

Gain
Gain Value Use When
x1 TSL2591_GAIN_LOW Bright light (default)
x25 TSL2591_GAIN_MED Medium light
x428 TSL2591_GAIN_HIGH Very dimmed light
x9876 TSL2591_GAIN_MAX Darkness
Integration Times (measuring time)
Integration time Value Use When
100 ms TSL2591_INTEGRATION_TIME_100MS Bright light (default)
200 ms TSL2591_INTEGRATION_TIME_200MS Medium light
300 ms TSL2591_INTEGRATION_TIME_300MS Medium light
400 ms TSL2591_INTEGRATION_TIME_400MS Dim light
500 ms TSL2591_INTEGRATION_TIME_500MS Dim light
600 ms TSL2591_INTEGRATION_TIME_600MS Darkness

The sensor's gain and integration time are set to TSL2591_GAIN_LOW (x1) and TSL2591_INTEGRATION_TIME_100MS on Power On Reset (POR).

Note
The gain and integration time is not set before before the driver calls the call-back function with TSL2591_OK as argument.
Parameters
[in]gainthe wanted gain tsl2591_gain_t.
[in]integrationTimethe wanted integration time tsl2591_integrationTime_t.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe set gain and integration time command is send to the sensor.
TSL2591_BUSYThe driver is busy.
TSL2591_DRIVER_NOT_INITIALISEDThe driver is not initialised - and can not be used!!

◆ tsl259_getVisibleRaw()

tsl2591_returnCode_t tsl259_getVisibleRaw ( uint16_t *  visible)

Retrieve the latest visible light spectrum as raw data fetched from the TSL2591 sensor.

Parameters
[out]*visiblepointer to the variable where the data will be stored.
Returns
tsl2591_returnCode_t
Return values
TSL2591_OKThe light data retrieved OK.
TSL2591_OVERFLOWThe last measuring is in overflow - consider a lower gain.
TSL2591_UNDERFLOWThe last measuring is in underflow - consider a higher gain.