RocketLogger  2.0.2
tsl4531.c File Reference
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <i2c/smbus.h>
#include "../log.h"
#include "sensor.h"
#include "tsl4531.h"
+ Include dependency graph for tsl4531.c:

Go to the source code of this file.

Functions

int tsl4531_set_range (int sensor_identifier, int range)
 
int tsl4531_get_range (int sensor_identifier)
 
int tsl4531_get_id (void)
 
int tsl4531_set_parameters (int sensor_identifier)
 
int tsl4531_send_range (int sensor_identifier, int range)
 
int tsl4531_get_index (int sensor_identifier)
 
int tsl4531_init (int sensor_identifier)
 
void tsl4531_deinit (int sensor_identifier)
 
int tsl4531_read (int sensor_identifier)
 
int32_t tsl4531_get_value (int sensor_identifier, int channel)
 

Variables

const int tsl4531_sensors [] = TSL4531_I2C_ADDRESSES
 
tsl4531_range_t tsl4531_range [sizeof(tsl4531_sensors)] = {TSL4531_RANGE_AUTO}
 
tsl4531_range_t tsl4531_auto_range [sizeof(tsl4531_sensors)]
 
uint8_t tsl4531_multiplier [sizeof(tsl4531_sensors)] = {TSL4531_MULT_200}
 
int32_t tsl4531_values [sizeof(tsl4531_sensors)] = {0}
 

Function Documentation

◆ tsl4531_deinit()

void tsl4531_deinit ( int  sensor_identifier)

Deinitialize TSL sensor.

Parameters
sensor_identifierThe I2C address of the sensor

Definition at line 157 of file tsl4531.c.

◆ tsl4531_get_id()

int tsl4531_get_id ( void  )

Get the device ID.

Parameters
sensor_identifierThe I2C address of the sensor
Returns
Returns device ID on success, negative on failure with errno set accordingly

Definition at line 262 of file tsl4531.c.

References rl_log(), RL_LOG_ERROR, sensor_bus, sensors_get_bus(), TSL4531_COMMAND, and TSL4531_REG_ID.

Referenced by tsl4531_init().

+ Here is the call graph for this function:

◆ tsl4531_get_index()

int tsl4531_get_index ( int  sensor_identifier)

Get the index of the sensor with specified address.

Parameters
sensor_identifierThe sensor address used to look up the index
Returns
Returns 0 on success, or -1 if sensor with given index was not found

Definition at line 368 of file tsl4531.c.

References tsl4531_sensors.

Referenced by tsl4531_get_range(), tsl4531_get_value(), tsl4531_read(), tsl4531_send_range(), and tsl4531_set_range().

◆ tsl4531_get_range()

int tsl4531_get_range ( int  sensor_identifier)

Get current measurement range.

Parameters
sensor_identifierThe I2C address of the sensor
Returns
current range tsl4531_range

Definition at line 252 of file tsl4531.c.

References tsl4531_auto_range, tsl4531_get_index(), and TSL4531_RANGE_AUTO.

+ Here is the call graph for this function:

◆ tsl4531_get_value()

int32_t tsl4531_get_value ( int  sensor_identifier,
int  channel 
)

Get the values read from the sensor.

Parameters
sensor_identifierThe I2C address of the sensor
channelThe channel of the sensor to get
Returns
Sensor value in lux

Definition at line 227 of file tsl4531.c.

References tsl4531_get_index(), and tsl4531_values.

+ Here is the call graph for this function:

◆ tsl4531_init()

int tsl4531_init ( int  sensor_identifier)

Initialize the light sensor.

Parameters
sensor_identifierThe I2C address of the sensor
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 120 of file tsl4531.c.

References rl_log(), RL_LOG_ERROR, sensor_bus, sensors_get_bus(), sensors_init_comm(), tsl4531_get_id(), TSL4531_ID, and tsl4531_set_parameters().

+ Here is the call graph for this function:

◆ tsl4531_read()

int tsl4531_read ( int  sensor_identifier)

Read the sensor values.

Parameters
sensor_identifierThe I2C address of the sensor
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 161 of file tsl4531.c.

References data, ERROR, rl_log(), RL_LOG_ERROR, sensor_bus, sensors_get_bus(), sensors_init_comm(), tsl4531_auto_range, TSL4531_COMMAND, tsl4531_get_index(), tsl4531_multiplier, TSL4531_RANGE_AUTO, TSL4531_RANGE_HIGH, TSL4531_RANGE_HYSTERESIS, TSL4531_RANGE_LOW, TSL4531_RANGE_LOW_MAX, TSL4531_RANGE_MEDIUM, TSL4531_RANGE_MEDIUM_MAX, TSL4531_REG_DATALOW, tsl4531_send_range(), and tsl4531_values.

+ Here is the call graph for this function:

◆ tsl4531_send_range()

int tsl4531_send_range ( int  sensor_identifier,
int  range 
)

Configure the range of the sensor.

Parameters
sensor_identifierThe I2C address of the sensor
rangeThe range tsl4531_range to set
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 299 of file tsl4531.c.

References rl_log(), RL_LOG_ERROR, sensor_bus, sensors_get_bus(), tsl4531_auto_range, TSL4531_COMMAND, tsl4531_get_index(), TSL4531_INT_TIME_100, TSL4531_INT_TIME_200, TSL4531_INT_TIME_400, TSL4531_LOW_POWER, TSL4531_MULT_100, TSL4531_MULT_200, TSL4531_MULT_400, tsl4531_multiplier, TSL4531_RANGE_AUTO, TSL4531_RANGE_HIGH, TSL4531_RANGE_LOW, TSL4531_RANGE_MEDIUM, and TSL4531_REG_CONFIG.

Referenced by tsl4531_read(), and tsl4531_set_range().

+ Here is the call graph for this function:

◆ tsl4531_set_parameters()

int tsl4531_set_parameters ( int  sensor_identifier)

Set the sensor parameter to default for continuous sensing.

Parameters
sensor_identifierThe I2C address of the sensor
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 274 of file tsl4531.c.

References rl_log(), RL_LOG_ERROR, sensor_bus, sensors_get_bus(), TSL4531_COMMAND, TSL4531_RANGE_AUTO, TSL4531_REG_CONTROL, TSL4531_SAMPLE_CONTINUOUS, and tsl4531_set_range().

Referenced by tsl4531_init().

+ Here is the call graph for this function:

◆ tsl4531_set_range()

int tsl4531_set_range ( int  sensor_identifier,
int  range 
)

Set mesurement range of light sensor.

Parameters
sensor_identifierThe I2C address of the sensor
rangeThe range tsl4531_range to set
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 237 of file tsl4531.c.

References rl_log(), RL_LOG_ERROR, tsl4531_get_index(), and tsl4531_send_range().

Referenced by tsl4531_set_parameters().

+ Here is the call graph for this function:

Variable Documentation

◆ tsl4531_auto_range

tsl4531_range_t tsl4531_auto_range[sizeof(tsl4531_sensors)]
Initial value:
= {
@ TSL4531_RANGE_MEDIUM
Definition: tsl4531.h:76

Dynamic sensor range currently set if auto ranging is used.

Definition at line 107 of file tsl4531.c.

Referenced by tsl4531_get_range(), tsl4531_read(), and tsl4531_send_range().

◆ tsl4531_multiplier

uint8_t tsl4531_multiplier[sizeof(tsl4531_sensors)] = {TSL4531_MULT_200}

The measurement range dependent sensor value multiplier to use.

Definition at line 113 of file tsl4531.c.

Referenced by tsl4531_read(), and tsl4531_send_range().

◆ tsl4531_range

The currently configured measurement range.

Definition at line 102 of file tsl4531.c.

◆ tsl4531_sensors

const int tsl4531_sensors[] = TSL4531_I2C_ADDRESSES

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. List of potentially connected TSL4531 sensors.

Definition at line 46 of file tsl4531.c.

Referenced by tsl4531_get_index().

◆ tsl4531_values

int32_t tsl4531_values[sizeof(tsl4531_sensors)] = {0}

The sensor value data buffer.

Definition at line 118 of file tsl4531.c.

Referenced by tsl4531_get_value(), and tsl4531_read().