|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
#include "amb_tsl2591.h"#include "i2c.h"#include "utils/mydefs.h"#include "mymems.h"#include <stdio.h>Go to the source code of this file.
Macros | |
| #define | AMBIENT_ADDR (0x29 << 1) |
| #define | TSL2591_COMMAND 0xA0 |
| #define | REG_ENABLE 0x00 |
| #define | REG_CONFIG 0x01 |
| #define | REG_C0DATAL 0x14 |
| #define | REG_C1DATAL 0x16 |
| #define | THRESH_MAX 60000 |
| #define | THRESH_MIN 500 |
Enumerations | |
| enum | TSL2591_Gain_t { TSL2591_GAIN_LOW = 0x00 , TSL2591_GAIN_MED = 0x10 , TSL2591_GAIN_HIGH = 0x20 , TSL2591_GAIN_MAX = 0x30 } |
Functions | |
| int8_t | amb_tsl2591_Is (I2C_HandleTypeDef *hi2c, int8_t tryInit) |
| |
| HAL_StatusTypeDef | amb_tsl2591_IsOn (I2C_HandleTypeDef *hi2c, uint8_t *onOff) |
| check if sensor is turned on or not | |
| HAL_StatusTypeDef | amb_tsl2591_On (I2C_HandleTypeDef *hi2c) |
| turn on sensor, read value 4x to automatically configure the sensor. | |
| HAL_StatusTypeDef | amb_tsl2591_Off (I2C_HandleTypeDef *hi2c) |
| turn off sensor | |
| HAL_StatusTypeDef | amb_tsl2591_Init (I2C_HandleTypeDef *hi2c) |
| initialization of light sensor, and check if sensor is present or not Subsequently the sensor is turned off so it doesn't run unnecessarily | |
| static HAL_StatusTypeDef | ambient_AdjustGain (I2C_HandleTypeDef *hi2c, uint16_t rawCH0) |
| This function checks the raw channel 0 value. If it is near the 16-bit limit (65535), it drops the gain. If it is too low, it boosts it. | |
| HAL_StatusTypeDef | amb_tsl2591_Read (I2C_HandleTypeDef *hi2c) |
| When calculating Lux, you must use the actual multiplier corresponding to the currentGain. | |
| void | amb_tsl2591_LogData (char *buf) |
| log data to buffer | |
Variables | |
| static TSL2591_Gain_t | _currentGain = TSL2591_GAIN_MED |
| static int8_t | _isAmbientSensor = 0 |
| amb_tsl2591_t | _amb_tsl2591Data = { } |
| Live measurement data from the TSL2591 sensor; updated by amb_tsl2591_Read(). | |
| amb_tsl2591_t | _bck_amb_tsl2591Data = {} |
| Snapshot copy of the last completed TSL2591 measurement; used for LoRaWAN transmission. | |
| #define AMBIENT_ADDR (0x29 << 1) |
Definition at line 10 of file amb_tsl2591.c.
Referenced by amb_tsl2591_Init(), amb_tsl2591_IsOn(), amb_tsl2591_Off(), amb_tsl2591_On(), amb_tsl2591_Read(), and ambient_AdjustGain().
| #define REG_C0DATAL 0x14 |
Definition at line 14 of file amb_tsl2591.c.
Referenced by amb_tsl2591_Read().
| #define REG_C1DATAL 0x16 |
Definition at line 15 of file amb_tsl2591.c.
| #define REG_CONFIG 0x01 |
Definition at line 13 of file amb_tsl2591.c.
Referenced by amb_tsl2591_On(), and ambient_AdjustGain().
| #define REG_ENABLE 0x00 |
Definition at line 12 of file amb_tsl2591.c.
Referenced by amb_tsl2591_IsOn(), amb_tsl2591_Off(), and amb_tsl2591_On().
| #define THRESH_MAX 60000 |
Definition at line 17 of file amb_tsl2591.c.
Referenced by amb_tsl2591_Read(), and ambient_AdjustGain().
| #define THRESH_MIN 500 |
Definition at line 18 of file amb_tsl2591.c.
Referenced by ambient_AdjustGain().
| #define TSL2591_COMMAND 0xA0 |
Definition at line 11 of file amb_tsl2591.c.
Referenced by amb_tsl2591_IsOn(), amb_tsl2591_Off(), amb_tsl2591_On(), amb_tsl2591_Read(), and ambient_AdjustGain().
| enum TSL2591_Gain_t |
| Enumerator | |
|---|---|
| TSL2591_GAIN_LOW | |
| TSL2591_GAIN_MED | |
| TSL2591_GAIN_HIGH | |
| TSL2591_GAIN_MAX | |
Definition at line 21 of file amb_tsl2591.c.
| HAL_StatusTypeDef amb_tsl2591_Init | ( | I2C_HandleTypeDef * | hi2c | ) |
initialization of light sensor, and check if sensor is present or not Subsequently the sensor is turned off so it doesn't run unnecessarily
| HAL_OK | - sensor is present, HAL_ERROR |
Definition at line 121 of file amb_tsl2591.c.
References _isAmbientSensor, amb_tsl2591_Off(), amb_tsl2591_On(), AMBIENT_ADDR, and I2C_IsDeviceReadyMT().
Referenced by amb_tsl2591_Is().
| int8_t amb_tsl2591_Is | ( | I2C_HandleTypeDef * | hi2c, |
| int8_t | tryInit ) |
| tryInit | - in case sensor is not yet initialized, 1 - attempt to initialize again, 0 - no |
| 1 | - is present, 0 - is not |
Definition at line 35 of file amb_tsl2591.c.
References _isAmbientSensor, and amb_tsl2591_Init().
| HAL_StatusTypeDef amb_tsl2591_IsOn | ( | I2C_HandleTypeDef * | hi2c, |
| uint8_t * | onOff ) |
check if sensor is turned on or not
| onOff | - on output contains 1-on 0-off, but only if status is HAL_OK |
| HAL_OK | - onOff contains sensor state, HAL_ERROR |
Definition at line 42 of file amb_tsl2591.c.
References _isAmbientSensor, AMBIENT_ADDR, REG_ENABLE, and TSL2591_COMMAND.
Referenced by amb_tsl2591_Read().
| void amb_tsl2591_LogData | ( | char * | buf | ) |
log data to buffer
Definition at line 248 of file amb_tsl2591.c.
References _amb_tsl2591Data, PRIf_02, and PRIf_02D.
| HAL_StatusTypeDef amb_tsl2591_Off | ( | I2C_HandleTypeDef * | hi2c | ) |
turn off sensor
| HAL_OK,HAL_ERROR |
Definition at line 101 of file amb_tsl2591.c.
References _isAmbientSensor, AMBIENT_ADDR, REG_ENABLE, and TSL2591_COMMAND.
Referenced by amb_tsl2591_Init().
| HAL_StatusTypeDef amb_tsl2591_On | ( | I2C_HandleTypeDef * | hi2c | ) |
turn on sensor, read value 4x to automatically configure the sensor.
| HAL_OK,HAL_ERROR |
Definition at line 57 of file amb_tsl2591.c.
References _amb_tsl2591Data, _currentGain, _isAmbientSensor, _memsMainBlock, amb_tsl2591_Read(), AMBIENT_ADDR, mems_WriteMainBlock(), REG_CONFIG, REG_ENABLE, TSL2591_COMMAND, and TSL2591_GAIN_MED.
Referenced by amb_tsl2591_Init().
| HAL_StatusTypeDef amb_tsl2591_Read | ( | I2C_HandleTypeDef * | hi2c | ) |
When calculating Lux, you must use the actual multiplier corresponding to the currentGain.
read value from sensor, the value is in _ambientData
Definition at line 179 of file amb_tsl2591.c.
References _amb_tsl2591Data, _currentGain, _isAmbientSensor, amb_tsl2591_IsOn(), AMBIENT_ADDR, ambient_AdjustGain(), REG_C0DATAL, THRESH_MAX, TSL2591_COMMAND, TSL2591_GAIN_HIGH, TSL2591_GAIN_LOW, TSL2591_GAIN_MAX, and TSL2591_GAIN_MED.
Referenced by amb_tsl2591_On().
|
static |
This function checks the raw channel 0 value. If it is near the 16-bit limit (65535), it drops the gain. If it is too low, it boosts it.
500)
Definition at line 142 of file amb_tsl2591.c.
References _currentGain, AMBIENT_ADDR, REG_CONFIG, THRESH_MAX, THRESH_MIN, TSL2591_COMMAND, TSL2591_GAIN_HIGH, TSL2591_GAIN_LOW, TSL2591_GAIN_MAX, and TSL2591_GAIN_MED.
Referenced by amb_tsl2591_Read().
| amb_tsl2591_t _amb_tsl2591Data = { } |
Live measurement data from the TSL2591 sensor; updated by amb_tsl2591_Read().
Definition at line 32 of file amb_tsl2591.c.
Referenced by amb_tsl2591_LogData(), amb_tsl2591_On(), amb_tsl2591_Read(), and sensors_CopyToBck().
| amb_tsl2591_t _bck_amb_tsl2591Data = {} |
Snapshot copy of the last completed TSL2591 measurement; used for LoRaWAN transmission.
Definition at line 33 of file amb_tsl2591.c.
Referenced by sensors_CayennelFromBckData(), sensors_CopyToBck(), sensors_ReadToBckFromDataBlock(), and sensors_WriteFromBckToDataBlock().
|
static |
Definition at line 30 of file amb_tsl2591.c.
Referenced by amb_tsl2591_On(), amb_tsl2591_Read(), and ambient_AdjustGain().
|
static |
Definition at line 31 of file amb_tsl2591.c.
Referenced by amb_tsl2591_Init(), amb_tsl2591_Is(), amb_tsl2591_IsOn(), amb_tsl2591_Off(), amb_tsl2591_On(), and amb_tsl2591_Read().