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

Go to the source code of this file.

Functions

int bme280_get_id (void)
 
int bme280_read_calibration (int sensor_identifier)
 
int bme280_set_parameters (int sensor_identifier)
 
int bme280_get_index (int sensor_identifier)
 
int bme280_init (int sensor_identifier)
 
void bme280_deinit (int sensor_identifier)
 
int bme280_read (int sensor_identifier)
 
int32_t bme280_get_value (int sensor_identifier, int channel)
 

Variables

const int bme280_sensors [] = BME280_I2C_ADDRESSES
 
int32_t bme280_temperature [sizeof(bme280_sensors)] = {0}
 
int32_t bme280_humidity [sizeof(bme280_sensors)] = {0}
 
int32_t bme280_pressure [sizeof(bme280_sensors)] = {0}
 
bme280_calibration_t bme280_calibration [sizeof(bme280_sensors)]
 

Function Documentation

◆ bme280_deinit()

void bme280_deinit ( int  sensor_identifier)

Deinitialize BME280 ambient sensor.

Parameters
sensor_identifierThe I2C address of the sensor

Definition at line 190 of file bme280.c.

◆ bme280_get_id()

int bme280_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 256 of file bme280.c.

References BME280_REG_ID, rl_log(), RL_LOG_ERROR, sensor_bus, and sensors_get_bus().

Referenced by bme280_init().

+ Here is the call graph for this function:

◆ bme280_get_index()

int bme280_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 379 of file bme280.c.

References bme280_sensors.

Referenced by bme280_get_value(), bme280_read(), and bme280_read_calibration().

◆ bme280_get_value()

int32_t bme280_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 238 of file bme280.c.

References BME280_CHANNEL_HUMIDITY, BME280_CHANNEL_PRESSURE, BME280_CHANNEL_TEMPERATURE, bme280_get_index(), bme280_humidity, bme280_pressure, and bme280_temperature.

+ Here is the call graph for this function:

◆ bme280_init()

int bme280_init ( int  sensor_identifier)

Initialize the BME280 ambient sensor.

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

Definition at line 145 of file bme280.c.

References bme280_get_id(), BME280_ID, bme280_read_calibration(), bme280_set_parameters(), rl_log(), RL_LOG_ERROR, sensor_bus, sensors_get_bus(), and sensors_init_comm().

+ Here is the call graph for this function:

◆ bme280_read()

int bme280_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 194 of file bme280.c.

References BME280_DATA_BLOCK_SIZE, bme280_get_index(), BME280_REG_PRESSURE_MSB, bme280_temperature, data, rl_log(), RL_LOG_ERROR, sensor_bus, sensors_get_bus(), and sensors_init_comm().

+ Here is the call graph for this function:

◆ bme280_read_calibration()

◆ bme280_set_parameters()

int bme280_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 336 of file bme280.c.

References BME280_FILTER_OFF, BME280_MODE_NORMAL, BME280_OVERSAMPLE_HUMIDITY_1, BME280_OVERSAMPLE_PRESSURE_1, BME280_OVERSAMPLE_TEMPERATURE_1, BME280_REG_CONFIG, BME280_REG_CONTROL_HUMIDITY, BME280_REG_CONTROL_MEASURE, BME280_STANDBY_DURATION_250, rl_log(), RL_LOG_ERROR, sensor_bus, and sensors_get_bus().

Referenced by bme280_init().

+ Here is the call graph for this function:

Variable Documentation

◆ bme280_calibration

Sensor specific calibration data buffer.

Definition at line 143 of file bme280.c.

◆ bme280_humidity

int32_t bme280_humidity[sizeof(bme280_sensors)] = {0}

Humidity sensor data buffer.

Definition at line 133 of file bme280.c.

Referenced by bme280_get_value().

◆ bme280_pressure

int32_t bme280_pressure[sizeof(bme280_sensors)] = {0}

Pressure sensor data buffer.

Definition at line 138 of file bme280.c.

Referenced by bme280_get_value().

◆ bme280_sensors

const int bme280_sensors[] = BME280_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 BME280 sensors.

Definition at line 46 of file bme280.c.

Referenced by bme280_get_index().

◆ bme280_temperature

int32_t bme280_temperature[sizeof(bme280_sensors)] = {0}

Temperature sensor data buffer.

Definition at line 128 of file bme280.c.

Referenced by bme280_get_value(), and bme280_read().