RocketLogger  1.1.5
sensor.c File Reference
#include <stdint.h>
#include <linux/i2c-dev.h>
#include "../log.h"
#include "bme280.h"
#include "tsl4531.h"
#include "sensor.h"
+ Include dependency graph for sensor.c:

Go to the source code of this file.

Functions

int Sensors_openBus (void)
 
int Sensors_closeBus (int bus)
 
int Sensors_initSharedBus (void)
 
int Sensors_getSharedBus (void)
 
int Sensors_initSharedComm (uint8_t device_address)
 
void Sensors_closeSharedBus (void)
 
int Sensors_scan (int sensors_available[])
 
void Sensors_close (int sensors_available[])
 

Variables

int sensor_bus = -1
 
const struct rl_sensor sensor_registry [SENSOR_REGISTRY_SIZE]
 

Function Documentation

void Sensors_close ( int  sensors_available[])

Close all sensors used on the I2C bus.

Parameters
sensors_availableList of available (previously initialized) sensors

Definition at line 196 of file sensor.c.

References rl_sensor::close, rl_sensor::identifier, and SENSOR_REGISTRY_SIZE.

Referenced by hw_close().

int Sensors_closeBus ( int  bus)

Close a I2C sensor bus.

Parameters
busThe I2C bus to close
Returns
Status (error) code

Definition at line 98 of file sensor.c.

References rl_sensor::close, ERROR, and rl_log().

Referenced by Sensors_closeSharedBus().

+ Here is the call graph for this function:

void Sensors_closeSharedBus ( void  )

Close the shared I2C sensor bus.

Returns
Status (error) code

Definition at line 134 of file sensor.c.

References sensor_bus, and Sensors_closeBus().

Referenced by hw_close().

+ Here is the call graph for this function:

int Sensors_getSharedBus ( void  )

Get the shared I2C bus handle.

Returns
The I2C bus handle

Definition at line 119 of file sensor.c.

References sensor_bus.

Referenced by BME280_getID(), BME280_init(), BME280_read(), BME280_readCalibration(), BME280_setParameters(), TSL4531_getID(), TSL4531_init(), TSL4531_read(), TSL4531_sendRange(), and TSL4531_setParameters().

int Sensors_initSharedBus ( void  )

Initialize the shared I2C sensor bus.

Returns
Status (error) code

Definition at line 110 of file sensor.c.

References sensor_bus, and Sensors_openBus().

Referenced by hw_init().

+ Here is the call graph for this function:

int Sensors_initSharedComm ( uint8_t  device_address)

Initiate an I2C communication with a device.

Parameters
sensor_addressThe I2C address of the device
Returns
Status (error) code

Definition at line 126 of file sensor.c.

References sensor_bus.

Referenced by BME280_init(), BME280_read(), TSL4531_init(), and TSL4531_read().

int Sensors_openBus ( void  )

Open a new handle of the I2C bus.

Returns
The bus handle

Definition at line 85 of file sensor.c.

References ERROR, I2C_BUS_FILENAME, and rl_log().

Referenced by Sensors_initSharedBus().

+ Here is the call graph for this function:

int Sensors_scan ( int  sensors_available[])

Scan the I2C sensor for sensor in the registry and initialize them.

Parameters
sensors_availableList of sensors of the registry available
Returns
Number of sensors from the regisry found on the bus

Definition at line 145 of file sensor.c.

References rl_sensor::identifier, INFO, rl_sensor::init, MAX_MESSAGE_LENGTH, rl_sensor::name, rl_log(), SENSOR_REGISTRY_SIZE, SUCCESS, and WARNING.

Referenced by hw_init().

+ Here is the call graph for this function:

Variable Documentation

int sensor_bus = -1

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 43 of file sensor.c.

Referenced by BME280_getID(), BME280_init(), BME280_read(), BME280_readCalibration(), BME280_setParameters(), Sensors_closeSharedBus(), Sensors_getSharedBus(), Sensors_initSharedBus(), Sensors_initSharedComm(), TSL4531_getID(), TSL4531_init(), TSL4531_read(), TSL4531_sendRange(), and TSL4531_setParameters().

const struct rl_sensor sensor_registry[SENSOR_REGISTRY_SIZE]
Initial value:
= {
{
},
{
},
{
},
{
},
{
},
}
int TSL4531_init(int sensor_identifier)
Definition: tsl4531.c:52
int BME280_read(int sensor_identifier)
Definition: bme280.c:99
Degree celcius (temperature)
Definition: rl_file.h:90
int BME280_init(int sensor_identifier)
Definition: bme280.c:49
int32_t TSL4531_getValue(int sensor_identifier, int channel)
Definition: tsl4531.c:167
#define BME280_CHANNEL_TEMPERATURE
Definition: bme280.h:55
#define TSL4531_CHANNEL_DEFAULT
Definition: tsl4531.h:56
int TSL4531_read(int sensor_identifier)
Definition: tsl4531.c:97
Pascal (preasure)
Definition: rl_file.h:93
#define TSL4531_I2C_ADDRESS_RIGHT
Definition: tsl4531.h:51
#define TSL4531_I2C_ADDRESS_LEFT
Definition: tsl4531.h:50
#define BME280_CHANNEL_HUMIDITY
Definition: bme280.h:56
Integer channel (numeric)
Definition: rl_file.h:91
void BME280_close(int sensor_identifier)
Definition: bme280.c:90
void TSL4531_close(int sensor_identifier)
Definition: tsl4531.c:88
Lux (illuminance)
Definition: rl_file.h:89
int32_t BME280_getValue(int sensor_identifier, int channel)
Definition: bme280.c:147
#define BME280_I2C_ADDRESS_LEFT
Definition: bme280.h:50
#define RL_SCALE_MILLI
Definition: rl_file.h:50
#define BME280_CHANNEL_PREASURE
Definition: bme280.h:57
#define RL_SCALE_MICRO
Definition: rl_file.h:49
#define RL_SCALE_NONE
Definition: rl_file.h:51

The sensor registry structure.

Register your sensor (channels) here. Multiple channels from the same sensor should be added as consecutive entries.

Note
The SENSOR_REGISTRY_SIZE needs to be adjusted accordingly.

Definition at line 53 of file sensor.c.

Referenced by ambient_setup_channels(), and ambient_store_data().