RocketLogger  1.1.6
tsl4531.h File Reference
#include <errno.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "../log.h"
#include "../types.h"
+ Include dependency graph for tsl4531.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TSL4531_I2C_ADDRESS_LEFT   0x29
 
#define TSL4531_I2C_ADDRESS_RIGHT   0x28
 
#define TSL4531_I2C_ADDRESSES   { (TSL4531_I2C_ADDRESS_LEFT), (TSL4531_I2C_ADDRESS_RIGHT) }
 
#define TSL4531_CHANNEL_DEFAULT   0
 
#define TSL4531_ID   162
 
#define TSL4531_COMMAND   0x80
 
#define TSL4531_REG_CONTROL   0x00
 
#define TSL4531_REG_CONFIG   0x01
 
#define TSL4531_REG_DATALOW   0x04
 
#define TSL4531_REG_DATAHIGH   0x05
 
#define TSL4531_REG_ID   0x0A
 
#define TSL4531_SAMPLE_OFF   0x00
 
#define TSL4531_SAMPLE_SINGLE   0x2
 
#define TSL4531_SAMPLE_CONTINUOUS   0x03
 
#define TSL4531_HIGH_POWER   0x08
 
#define TSL4531_LOW_POWER   0x00
 
#define TSL4531_INT_TIME_100   0x02
 
#define TSL4531_INT_TIME_200   0x01
 
#define TSL4531_INT_TIME_400   0x00
 
#define TSL4531_MULT_100   4
 
#define TSL4531_MULT_200   2
 
#define TSL4531_MULT_400   1
 
#define TSL4531_RANGE_LOW_MAX   65000
 
#define TSL4531_RANGE_MEDIUM_MAX   130000
 
#define TSL4531_RANGE_HYSTERESIS   5000
 

Enumerations

enum  TSL4531_range { TSL4531_RANGE_LOW, TSL4531_RANGE_MEDIUM, TSL4531_RANGE_HIGH, TSL4531_RANGE_AUTO }
 

Functions

int TSL4531_init (int)
 
void TSL4531_close (int)
 
int TSL4531_read (int)
 
int32_t TSL4531_getValue (int, int)
 
int TSL4531_setRange (int, int)
 
int TSL4531_getRange (int)
 
int TSL4531_getID (void)
 
int TSL4531_setParameters (int)
 
int TSL4531_sendRange (int, int)
 
int TSL4531_getIndex (int)
 

Macro Definition Documentation

#define TSL4531_CHANNEL_DEFAULT   0

Definition at line 56 of file tsl4531.h.

#define TSL4531_COMMAND   0x80

Definition at line 61 of file tsl4531.h.

Referenced by TSL4531_getID(), TSL4531_read(), TSL4531_sendRange(), and TSL4531_setParameters().

#define TSL4531_HIGH_POWER   0x08

Definition at line 73 of file tsl4531.h.

#define TSL4531_I2C_ADDRESS_LEFT   0x29

Copyright (c) 2016-2019, Swiss Federal Institute of Technology (ETH Zurich) 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.

Definition at line 50 of file tsl4531.h.

#define TSL4531_I2C_ADDRESS_RIGHT   0x28

Definition at line 51 of file tsl4531.h.

#define TSL4531_I2C_ADDRESSES   { (TSL4531_I2C_ADDRESS_LEFT), (TSL4531_I2C_ADDRESS_RIGHT) }

Definition at line 53 of file tsl4531.h.

#define TSL4531_ID   162

Definition at line 59 of file tsl4531.h.

Referenced by TSL4531_init().

#define TSL4531_INT_TIME_100   0x02

Definition at line 76 of file tsl4531.h.

Referenced by TSL4531_sendRange().

#define TSL4531_INT_TIME_200   0x01

Definition at line 77 of file tsl4531.h.

Referenced by TSL4531_sendRange().

#define TSL4531_INT_TIME_400   0x00

Definition at line 78 of file tsl4531.h.

Referenced by TSL4531_sendRange().

#define TSL4531_LOW_POWER   0x00

Definition at line 74 of file tsl4531.h.

Referenced by TSL4531_sendRange().

#define TSL4531_MULT_100   4

Definition at line 80 of file tsl4531.h.

Referenced by TSL4531_sendRange().

#define TSL4531_MULT_200   2

Definition at line 81 of file tsl4531.h.

Referenced by TSL4531_sendRange().

#define TSL4531_MULT_400   1

Definition at line 82 of file tsl4531.h.

Referenced by TSL4531_sendRange().

#define TSL4531_RANGE_HYSTERESIS   5000

Definition at line 95 of file tsl4531.h.

Referenced by TSL4531_read().

#define TSL4531_RANGE_LOW_MAX   65000

Definition at line 93 of file tsl4531.h.

Referenced by TSL4531_read().

#define TSL4531_RANGE_MEDIUM_MAX   130000

Definition at line 94 of file tsl4531.h.

Referenced by TSL4531_read().

#define TSL4531_REG_CONFIG   0x01

Definition at line 64 of file tsl4531.h.

Referenced by TSL4531_sendRange().

#define TSL4531_REG_CONTROL   0x00

Definition at line 63 of file tsl4531.h.

Referenced by TSL4531_setParameters().

#define TSL4531_REG_DATAHIGH   0x05

Definition at line 66 of file tsl4531.h.

#define TSL4531_REG_DATALOW   0x04

Definition at line 65 of file tsl4531.h.

Referenced by TSL4531_read().

#define TSL4531_REG_ID   0x0A

Definition at line 67 of file tsl4531.h.

Referenced by TSL4531_getID().

#define TSL4531_SAMPLE_CONTINUOUS   0x03

Definition at line 71 of file tsl4531.h.

Referenced by TSL4531_setParameters().

#define TSL4531_SAMPLE_OFF   0x00

Definition at line 69 of file tsl4531.h.

#define TSL4531_SAMPLE_SINGLE   0x2

Definition at line 70 of file tsl4531.h.

Enumeration Type Documentation

Ranges

Enumerator
TSL4531_RANGE_LOW 
TSL4531_RANGE_MEDIUM 
TSL4531_RANGE_HIGH 
TSL4531_RANGE_AUTO 

Definition at line 87 of file tsl4531.h.

Function Documentation

void TSL4531_close ( int  sensor_identifier)

Close TSL sensor.

Parameters
sensor_identifierThe I2C address of the sensor

Definition at line 88 of file tsl4531.c.

int TSL4531_getID ( void  )

Get the device ID

Parameters
sensor_identifierThe I2C address of the sensor
Returns
Devie ID or negative status code

Definition at line 217 of file tsl4531.c.

References ERROR, rl_log(), sensor_bus, Sensors_getSharedBus(), TSL4531_COMMAND, and TSL4531_REG_ID.

Referenced by TSL4531_init().

+ Here is the call graph for this function:

int TSL4531_getIndex ( int  sensor_identifier)

Get the index of the sensor with specified address.

Parameters
sensor_identifierThe sensor address used to look up the index
Returns
The index of the sensor, or if not found -1

Definition at line 323 of file tsl4531.c.

References TSL4531_sensors.

Referenced by TSL4531_getRange(), TSL4531_getValue(), TSL4531_read(), TSL4531_sendRange(), and TSL4531_setRange().

int TSL4531_getRange ( int  sensor_identifier)

Get current range

Parameters
sensor_identifierThe I2C address of the sensor
Returns
current range TSL4531_range

Definition at line 202 of file tsl4531.c.

References TSL4531_auto_range, TSL4531_getIndex(), and TSL4531_RANGE_AUTO.

+ Here is the call graph for this function:

int32_t TSL4531_getValue ( 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 167 of file tsl4531.c.

References TSL4531_getIndex(), and TSL4531_values.

+ Here is the call graph for this function:

int TSL4531_init ( int  sensor_identifier)

Initialize the light sensor

Parameters
sensor_identifierThe I2C address of the sensor
Returns
return Status code

Definition at line 52 of file tsl4531.c.

References ERROR, FAILURE, rl_log(), sensor_bus, Sensors_getSharedBus(), Sensors_initSharedComm(), SUCCESS, TSL4531_getID(), TSL4531_ID, and TSL4531_setParameters().

+ Here is the call graph for this function:

int TSL4531_read ( int  sensor_identifier)

Read the sensor values.

Parameters
sensor_identifierThe I2C address of the sensor
Returns
return Status code

Definition at line 97 of file tsl4531.c.

References ERROR, FAILURE, rl_log(), sensor_bus, Sensors_getSharedBus(), Sensors_initSharedComm(), SUCCESS, TSL4531_auto_range, TSL4531_COMMAND, TSL4531_getIndex(), 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_sendRange(), and TSL4531_values.

+ Here is the call graph for this function:

int TSL4531_sendRange ( 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
Status code

Definition at line 262 of file tsl4531.c.

References ERROR, FAILURE, rl_log(), sensor_bus, Sensors_getSharedBus(), SUCCESS, TSL4531_auto_range, TSL4531_COMMAND, TSL4531_getIndex(), 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_setRange().

+ Here is the call graph for this function:

int TSL4531_setParameters ( int  sensor_identifier)

Set the sensor parameter to default for continuous sensing.

Parameters
sensor_identifierThe I2C address of the sensor
Returns
Status code

Definition at line 234 of file tsl4531.c.

References ERROR, FAILURE, rl_log(), sensor_bus, Sensors_getSharedBus(), SUCCESS, TSL4531_COMMAND, TSL4531_RANGE_AUTO, TSL4531_REG_CONTROL, TSL4531_SAMPLE_CONTINUOUS, and TSL4531_setRange().

Referenced by TSL4531_init().

+ Here is the call graph for this function:

int TSL4531_setRange ( int  sensor_identifier,
int  range 
)

Set range of light sensor

Parameters
sensor_identifierThe I2C address of the sensor
rangeThe range TSL4531_range to set
Returns
Status code

Definition at line 183 of file tsl4531.c.

References ERROR, FAILURE, rl_log(), SUCCESS, TSL4531_getIndex(), and TSL4531_sendRange().

Referenced by TSL4531_setParameters().

+ Here is the call graph for this function: