mirror of
https://github.com/eclipse/upm.git
synced 2025-03-23 17:00:03 +03:00
bme280: added missing return in non-void function
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
a88ec4237d
commit
102d86870a
@ -31,7 +31,7 @@
|
|||||||
#include "bme280.h"
|
#include "bme280.h"
|
||||||
#include "bme280driver.h"
|
#include "bme280driver.h"
|
||||||
/************** I2C buffer length ******/
|
/************** I2C buffer length ******/
|
||||||
#define I2C_BUFFER_LEN 26
|
#define I2C_BUFFER_LEN 26
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -41,13 +41,13 @@ using namespace upm;
|
|||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*
|
/*----------------------------------------------------------------------------*
|
||||||
* struct bme280_t parameters can be accessed by using bme280
|
* struct bme280_t parameters can be accessed by using bme280
|
||||||
* bme280_t having the following parameters
|
* bme280_t having the following parameters
|
||||||
* Bus write function pointer: BME280_WR_FUNC_PTR
|
* Bus write function pointer: BME280_WR_FUNC_PTR
|
||||||
Bus read function pointer: BME280_RD_FUNC_PTR
|
Bus read function pointer: BME280_RD_FUNC_PTR
|
||||||
* Delay function pointer: delay_msec
|
* Delay function pointer: delay_msec
|
||||||
* I2C address: dev_addr
|
* I2C address: dev_addr
|
||||||
* Chip id of the sensor: chip_id
|
* Chip id of the sensor: chip_id
|
||||||
*---------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
struct bme280_t bme280;
|
struct bme280_t bme280;
|
||||||
@ -57,23 +57,23 @@ mraa::I2c* BME280::m_i2c = NULL;
|
|||||||
int BME280::m_bus = 0;
|
int BME280::m_bus = 0;
|
||||||
|
|
||||||
BME280::BME280 (int bus, int devAddr) {
|
BME280::BME280 (int bus, int devAddr) {
|
||||||
m_bus = bus;
|
m_bus = bus;
|
||||||
if( m_i2c == NULL)
|
if( m_i2c == NULL)
|
||||||
{
|
{
|
||||||
m_i2c = new mraa::I2c(m_bus);
|
m_i2c = new mraa::I2c(m_bus);
|
||||||
m_i2c->address(BME280_I2C_ADDRESS1);
|
m_i2c->address(BME280_I2C_ADDRESS1);
|
||||||
//Based on the requirement, configure I2C interface.
|
//Based on the requirement, configure I2C interface.
|
||||||
I2C_routine();
|
I2C_routine();
|
||||||
/*--------------------------------------------------------------------------*
|
/*--------------------------------------------------------------------------*
|
||||||
* This function used to assign the value/reference of
|
* This function used to assign the value/reference of
|
||||||
* the following parameters
|
* the following parameters
|
||||||
* I2C address
|
* I2C address
|
||||||
* Bus Write
|
* Bus Write
|
||||||
* Bus read
|
* Bus read
|
||||||
* Chip id
|
* Chip id
|
||||||
*-------------------------------------------------------------------------*/
|
*-------------------------------------------------------------------------*/
|
||||||
bme280_init(&bme280);
|
bme280_init(&bme280);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BME280::~BME280() {
|
BME280::~BME280() {
|
||||||
@ -81,21 +81,21 @@ BME280::~BME280() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This function is an example for reading sensor temperature
|
/* This function is an example for reading sensor temperature
|
||||||
* \param: None
|
* \param: None
|
||||||
* \return: compensated temperature
|
* \return: compensated temperature
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t BME280::getTemperatureInternal(void)
|
int32_t BME280::getTemperatureInternal(void)
|
||||||
{
|
{
|
||||||
/* The variable used to read uncompensated temperature*/
|
/* The variable used to read uncompensated temperature*/
|
||||||
int32_t v_data_uncomp_tem_int32 = getTemperatureRawInternal();
|
int32_t v_data_uncomp_tem_int32 = getTemperatureRawInternal();
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
************ START READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY DATA ********
|
************ START READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY DATA ********
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
/* API is used to read the true temperature*/
|
/* API is used to read the true temperature*/
|
||||||
/* Input value as uncompensated temperature and output format*/
|
/* Input value as uncompensated temperature and output format*/
|
||||||
int32_t v_actual_temp_int32 = bme280_compensate_temperature_int32(v_data_uncomp_tem_int32);
|
int32_t v_actual_temp_int32 = bme280_compensate_temperature_int32(v_data_uncomp_tem_int32);
|
||||||
/*--------------------------------------------------------------------*
|
/*--------------------------------------------------------------------*
|
||||||
************ END READ TRUE TEMPERATURE ********
|
************ END READ TRUE TEMPERATURE ********
|
||||||
*-------------------------------------------------------------------------*/
|
*-------------------------------------------------------------------------*/
|
||||||
@ -104,22 +104,22 @@ return v_actual_temp_int32;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This function is an example for reading sensor pressure
|
/* This function is an example for reading sensor pressure
|
||||||
* \param: None
|
* \param: None
|
||||||
* \return: compensated pressure
|
* \return: compensated pressure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t BME280::getPressureInternal(void)
|
int32_t BME280::getPressureInternal(void)
|
||||||
{
|
{
|
||||||
/* The variable used to read uncompensated pressure*/
|
/* The variable used to read uncompensated pressure*/
|
||||||
int32_t v_data_uncomp_pres_int32 = getPressureRawInternal();
|
int32_t v_data_uncomp_pres_int32 = getPressureRawInternal();
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
************ START READ TRUE PRESSURE DATA ********
|
************ START READ TRUE PRESSURE DATA ********
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
/* API is used to read the true pressure*/
|
/* API is used to read the true pressure*/
|
||||||
/* Input value as uncompensated pressure */
|
/* Input value as uncompensated pressure */
|
||||||
uint32_t v_actual_press_uint32 = bme280_compensate_pressure_int32(v_data_uncomp_pres_int32);
|
uint32_t v_actual_press_uint32 = bme280_compensate_pressure_int32(v_data_uncomp_pres_int32);
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
/*--------------------------------------------------------------------*
|
||||||
************ END READ TRUE PRESSURE ********
|
************ END READ TRUE PRESSURE ********
|
||||||
@ -130,21 +130,21 @@ return v_actual_press_uint32;
|
|||||||
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor humidity
|
/* This function is an example for reading sensor humidity
|
||||||
* \param: None
|
* \param: None
|
||||||
* \return: compensated humidity
|
* \return: compensated humidity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t BME280::getHumidityInternal(void)
|
int32_t BME280::getHumidityInternal(void)
|
||||||
{
|
{
|
||||||
/* The variable used to read uncompensated pressure*/
|
/* The variable used to read uncompensated pressure*/
|
||||||
int32_t v_data_uncomp_hum_int32 = getHumidityRawInternal();
|
int32_t v_data_uncomp_hum_int32 = getHumidityRawInternal();
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
************ START READ TRUE HUMIDITY DATA ********
|
************ START READ TRUE HUMIDITY DATA ********
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
/* API is used to read the true humidity*/
|
/* API is used to read the true humidity*/
|
||||||
/* Input value as uncompensated humidity and output format*/
|
/* Input value as uncompensated humidity and output format*/
|
||||||
uint32_t v_actual_humity_uint32 = bme280_compensate_humidity_int32(v_data_uncomp_hum_int32);
|
uint32_t v_actual_humity_uint32 = bme280_compensate_humidity_int32(v_data_uncomp_hum_int32);
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
/*--------------------------------------------------------------------*
|
||||||
************ END READ TRUE HUMIDITY ********
|
************ END READ TRUE HUMIDITY ********
|
||||||
@ -156,37 +156,37 @@ return v_actual_humity_uint32;
|
|||||||
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor temperature
|
/* This function is an example for reading sensor temperature
|
||||||
* \param: None
|
* \param: None
|
||||||
* \return: uncompensated temperature
|
* \return: uncompensated temperature
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t BME280::getTemperatureRawInternal(void)
|
int32_t BME280::getTemperatureRawInternal(void)
|
||||||
{
|
{
|
||||||
/* The variable used to read uncompensated temperature*/
|
/* The variable used to read uncompensated temperature*/
|
||||||
int32_t v_data_uncomp_tem_int32 = BME280_INIT_VALUE;
|
int32_t v_data_uncomp_tem_int32 = BME280_INIT_VALUE;
|
||||||
|
|
||||||
/* For initialization it is required to set the mode of
|
/* For initialization it is required to set the mode of
|
||||||
* the sensor as "NORMAL"
|
* the sensor as "NORMAL"
|
||||||
* data acquisition/read/write is possible in this mode
|
* data acquisition/read/write is possible in this mode
|
||||||
* by using the below API able to set the power mode as NORMAL*/
|
* by using the below API able to set the power mode as NORMAL*/
|
||||||
/* Set the power mode as NORMAL*/
|
/* Set the power mode as NORMAL*/
|
||||||
bme280_set_power_mode(BME280_NORMAL_MODE);
|
bme280_set_power_mode(BME280_NORMAL_MODE);
|
||||||
/* For reading the temperature data it is required to
|
/* For reading the temperature data it is required to
|
||||||
* set the OSS setting of temperature
|
* set the OSS setting of temperature
|
||||||
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
||||||
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
||||||
* the "BME280_CTRLMEAS_REG" register in the function*/
|
* the "BME280_CTRLMEAS_REG" register in the function*/
|
||||||
|
|
||||||
/* set the temperature oversampling*/
|
/* set the temperature oversampling*/
|
||||||
bme280_set_oversamp_temperature(BME280_OVERSAMP_4X);
|
bme280_set_oversamp_temperature(BME280_OVERSAMP_4X);
|
||||||
|
|
||||||
/************************* END INITIALIZATION *************************/
|
/************************* END INITIALIZATION *************************/
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
************ START READ UNCOMPENSATED TEMPERATURE DATA ********
|
************ START READ UNCOMPENSATED TEMPERATURE DATA ********
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
/* API is used to read the uncompensated temperature*/
|
/* API is used to read the uncompensated temperature*/
|
||||||
bme280_read_uncomp_temperature(&v_data_uncomp_tem_int32);
|
bme280_read_uncomp_temperature(&v_data_uncomp_tem_int32);
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
/*--------------------------------------------------------------------*
|
||||||
@ -196,14 +196,14 @@ int32_t BME280::getTemperatureRawInternal(void)
|
|||||||
/*-----------------------------------------------------------------------*
|
/*-----------------------------------------------------------------------*
|
||||||
************************* START DE-INITIALIZATION ***********************
|
************************* START DE-INITIALIZATION ***********************
|
||||||
*-------------------------------------------------------------------------*/
|
*-------------------------------------------------------------------------*/
|
||||||
/* For de-initialization it is required to set the mode of
|
/* For de-initialization it is required to set the mode of
|
||||||
* the sensor as "SLEEP"
|
* the sensor as "SLEEP"
|
||||||
* the device reaches the lowest power consumption only
|
* the device reaches the lowest power consumption only
|
||||||
* In SLEEP mode no measurements are performed
|
* In SLEEP mode no measurements are performed
|
||||||
* All registers are accessible
|
* All registers are accessible
|
||||||
* by using the below API able to set the power mode as SLEEP*/
|
* by using the below API able to set the power mode as SLEEP*/
|
||||||
/* Set the power mode as SLEEP*/
|
/* Set the power mode as SLEEP*/
|
||||||
bme280_set_power_mode(BME280_SLEEP_MODE);
|
bme280_set_power_mode(BME280_SLEEP_MODE);
|
||||||
/*---------------------------------------------------------------------*
|
/*---------------------------------------------------------------------*
|
||||||
************************* END DE-INITIALIZATION **********************
|
************************* END DE-INITIALIZATION **********************
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
@ -211,34 +211,34 @@ return v_data_uncomp_tem_int32;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This function is an example for reading sensor pressure
|
/* This function is an example for reading sensor pressure
|
||||||
* \param: None
|
* \param: None
|
||||||
* \return: uncompensated pressure
|
* \return: uncompensated pressure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t BME280::getPressureRawInternal(void)
|
int32_t BME280::getPressureRawInternal(void)
|
||||||
{
|
{
|
||||||
/* The variable used to read uncompensated pressure*/
|
/* The variable used to read uncompensated pressure*/
|
||||||
int32_t v_data_uncomp_pres_int32 = BME280_INIT_VALUE;
|
int32_t v_data_uncomp_pres_int32 = BME280_INIT_VALUE;
|
||||||
|
|
||||||
|
|
||||||
/* For initialization it is required to set the mode of
|
/* For initialization it is required to set the mode of
|
||||||
* the sensor as "NORMAL"
|
* the sensor as "NORMAL"
|
||||||
* data acquisition/read/write is possible in this mode
|
* data acquisition/read/write is possible in this mode
|
||||||
* by using the below API able to set the power mode as NORMAL*/
|
* by using the below API able to set the power mode as NORMAL*/
|
||||||
/* Set the power mode as NORMAL*/
|
/* Set the power mode as NORMAL*/
|
||||||
bme280_set_power_mode(BME280_NORMAL_MODE);
|
bme280_set_power_mode(BME280_NORMAL_MODE);
|
||||||
/* For reading the pressure data it is required to
|
/* For reading the pressure data it is required to
|
||||||
* set the OSS setting of humidity, pressure and temperature
|
* set the OSS setting of humidity, pressure and temperature
|
||||||
* The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
|
* The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
|
||||||
* data acquisition options of the device.
|
* data acquisition options of the device.
|
||||||
* changes to this registers only become effective after a write operation to
|
* changes to this registers only become effective after a write operation to
|
||||||
* "BME280_CTRLMEAS_REG" register.
|
* "BME280_CTRLMEAS_REG" register.
|
||||||
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
||||||
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
||||||
* the "BME280_CTRLMEAS_REG" register in the function*/
|
* the "BME280_CTRLMEAS_REG" register in the function*/
|
||||||
|
|
||||||
/* set the pressure oversampling*/
|
/* set the pressure oversampling*/
|
||||||
bme280_set_oversamp_pressure(BME280_OVERSAMP_2X);
|
bme280_set_oversamp_pressure(BME280_OVERSAMP_2X);
|
||||||
|
|
||||||
/************************* END INITIALIZATION *************************/
|
/************************* END INITIALIZATION *************************/
|
||||||
|
|
||||||
@ -246,8 +246,8 @@ int32_t BME280::getPressureRawInternal(void)
|
|||||||
************ START READ UNCOMPENSATED PRESSURE DATA ********
|
************ START READ UNCOMPENSATED PRESSURE DATA ********
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* API is used to read the uncompensated pressure*/
|
/* API is used to read the uncompensated pressure*/
|
||||||
bme280_read_uncomp_pressure(&v_data_uncomp_pres_int32);
|
bme280_read_uncomp_pressure(&v_data_uncomp_pres_int32);
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
/*--------------------------------------------------------------------*
|
||||||
************ END READ UNCOMPENSATED PRESSURE ********
|
************ END READ UNCOMPENSATED PRESSURE ********
|
||||||
@ -257,14 +257,14 @@ int32_t BME280::getPressureRawInternal(void)
|
|||||||
/*-----------------------------------------------------------------------*
|
/*-----------------------------------------------------------------------*
|
||||||
************************* START DE-INITIALIZATION ***********************
|
************************* START DE-INITIALIZATION ***********************
|
||||||
*-------------------------------------------------------------------------*/
|
*-------------------------------------------------------------------------*/
|
||||||
/* For de-initialization it is required to set the mode of
|
/* For de-initialization it is required to set the mode of
|
||||||
* the sensor as "SLEEP"
|
* the sensor as "SLEEP"
|
||||||
* the device reaches the lowest power consumption only
|
* the device reaches the lowest power consumption only
|
||||||
* In SLEEP mode no measurements are performed
|
* In SLEEP mode no measurements are performed
|
||||||
* All registers are accessible
|
* All registers are accessible
|
||||||
* by using the below API able to set the power mode as SLEEP*/
|
* by using the below API able to set the power mode as SLEEP*/
|
||||||
/* Set the power mode as SLEEP*/
|
/* Set the power mode as SLEEP*/
|
||||||
bme280_set_power_mode(BME280_SLEEP_MODE);
|
bme280_set_power_mode(BME280_SLEEP_MODE);
|
||||||
/*---------------------------------------------------------------------*
|
/*---------------------------------------------------------------------*
|
||||||
************************* END DE-INITIALIZATION **********************
|
************************* END DE-INITIALIZATION **********************
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
@ -273,31 +273,31 @@ return v_data_uncomp_pres_int32;
|
|||||||
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor humidity
|
/* This function is an example for reading sensor humidity
|
||||||
* \param: None
|
* \param: None
|
||||||
* \return: uncompensated humidity
|
* \return: uncompensated humidity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t BME280::getHumidityRawInternal(void)
|
int32_t BME280::getHumidityRawInternal(void)
|
||||||
{
|
{
|
||||||
/* The variable used to read uncompensated pressure*/
|
/* The variable used to read uncompensated pressure*/
|
||||||
int32_t v_data_uncomp_hum_int32 = BME280_INIT_VALUE;
|
int32_t v_data_uncomp_hum_int32 = BME280_INIT_VALUE;
|
||||||
|
|
||||||
/* For initialization it is required to set the mode of
|
/* For initialization it is required to set the mode of
|
||||||
* the sensor as "NORMAL"
|
* the sensor as "NORMAL"
|
||||||
* data acquisition/read/write is possible in this mode
|
* data acquisition/read/write is possible in this mode
|
||||||
* by using the below API able to set the power mode as NORMAL*/
|
* by using the below API able to set the power mode as NORMAL*/
|
||||||
/* Set the power mode as NORMAL*/
|
/* Set the power mode as NORMAL*/
|
||||||
bme280_set_power_mode(BME280_NORMAL_MODE);
|
bme280_set_power_mode(BME280_NORMAL_MODE);
|
||||||
/* For reading humidity data it is required to
|
/* For reading humidity data it is required to
|
||||||
* set the OSS setting of humidity
|
* set the OSS setting of humidity
|
||||||
* The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
|
* The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
|
||||||
* data acquisition options of the device.
|
* data acquisition options of the device.
|
||||||
* changes to this registers only become effective after a write operation to
|
* changes to this registers only become effective after a write operation to
|
||||||
* "BME280_CTRLMEAS_REG" register.
|
* "BME280_CTRLMEAS_REG" register.
|
||||||
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
||||||
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
||||||
* the "BME280_CTRLMEAS_REG" register in the function*/
|
* the "BME280_CTRLMEAS_REG" register in the function*/
|
||||||
bme280_set_oversamp_humidity(BME280_OVERSAMP_1X);
|
bme280_set_oversamp_humidity(BME280_OVERSAMP_1X);
|
||||||
|
|
||||||
|
|
||||||
/************************* END INITIALIZATION *************************/
|
/************************* END INITIALIZATION *************************/
|
||||||
@ -305,7 +305,7 @@ int32_t BME280::getHumidityRawInternal(void)
|
|||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
************ START READ HUMIDITY DATA ********
|
************ START READ HUMIDITY DATA ********
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
/* API is used to read the uncompensated humidity*/
|
/* API is used to read the uncompensated humidity*/
|
||||||
bme280_read_uncomp_humidity(&v_data_uncomp_hum_int32);
|
bme280_read_uncomp_humidity(&v_data_uncomp_hum_int32);
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
/*--------------------------------------------------------------------*
|
||||||
@ -316,14 +316,14 @@ int32_t BME280::getHumidityRawInternal(void)
|
|||||||
/*-----------------------------------------------------------------------*
|
/*-----------------------------------------------------------------------*
|
||||||
************************* START DE-INITIALIZATION ***********************
|
************************* START DE-INITIALIZATION ***********************
|
||||||
*-------------------------------------------------------------------------*/
|
*-------------------------------------------------------------------------*/
|
||||||
/* For de-initialization it is required to set the mode of
|
/* For de-initialization it is required to set the mode of
|
||||||
* the sensor as "SLEEP"
|
* the sensor as "SLEEP"
|
||||||
* the device reaches the lowest power consumption only
|
* the device reaches the lowest power consumption only
|
||||||
* In SLEEP mode no measurements are performed
|
* In SLEEP mode no measurements are performed
|
||||||
* All registers are accessible
|
* All registers are accessible
|
||||||
* by using the below API able to set the power mode as SLEEP*/
|
* by using the below API able to set the power mode as SLEEP*/
|
||||||
/* Set the power mode as SLEEP*/
|
/* Set the power mode as SLEEP*/
|
||||||
bme280_set_power_mode(BME280_SLEEP_MODE);
|
bme280_set_power_mode(BME280_SLEEP_MODE);
|
||||||
/*---------------------------------------------------------------------*
|
/*---------------------------------------------------------------------*
|
||||||
************************* END DE-INITIALIZATION **********************
|
************************* END DE-INITIALIZATION **********************
|
||||||
*---------------------------------------------------------------------*/
|
*---------------------------------------------------------------------*/
|
||||||
@ -335,120 +335,118 @@ return v_data_uncomp_hum_int32;
|
|||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*
|
/*--------------------------------------------------------------------------*
|
||||||
* The following function is used to map the I2C bus read, write, delay and
|
* The following function is used to map the I2C bus read, write, delay and
|
||||||
* device address with global structure bme280
|
* device address with global structure bme280
|
||||||
*-------------------------------------------------------------------------*/
|
*-------------------------------------------------------------------------*/
|
||||||
int8_t BME280::I2C_routine()
|
int8_t BME280::I2C_routine()
|
||||||
{
|
{
|
||||||
/*--------------------------------------------------------------------------*
|
/*--------------------------------------------------------------------------*
|
||||||
* By using bme280 the following structure parameter can be accessed
|
* By using bme280 the following structure parameter can be accessed
|
||||||
* Bus write function pointer: BME280_WR_FUNC_PTR
|
* Bus write function pointer: BME280_WR_FUNC_PTR
|
||||||
* Bus read function pointer: BME280_RD_FUNC_PTR
|
* Bus read function pointer: BME280_RD_FUNC_PTR
|
||||||
* Delay function pointer: delay_msec
|
* Delay function pointer: delay_msec
|
||||||
* I2C address: dev_addr
|
* I2C address: dev_addr
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
// bme280.bus_write = &BME280::BME280_I2C_bus_write;
|
// bme280.bus_write = &BME280::BME280_I2C_bus_write;
|
||||||
bme280.bus_write = BME280_I2C_bus_write;
|
bme280.bus_write = BME280_I2C_bus_write;
|
||||||
|
|
||||||
//bme280.bus_write = BME280_I2C_bus_write_dummy;
|
//bme280.bus_write = BME280_I2C_bus_write_dummy;
|
||||||
bme280.bus_read = BME280_I2C_bus_read;
|
bme280.bus_read = BME280_I2C_bus_read;
|
||||||
bme280.dev_addr = BME280_I2C_ADDRESS1;
|
bme280.dev_addr = BME280_I2C_ADDRESS1;
|
||||||
bme280.delay_msec = BME280_delay_msek;
|
bme280.delay_msec = BME280_delay_msek;
|
||||||
|
|
||||||
return BME280_INIT_VALUE;
|
return BME280_INIT_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------*
|
/*-------------------------------------------------------------------*
|
||||||
* The device address defined in the bme280.h file
|
* The device address defined in the bme280.h file
|
||||||
*-----------------------------------------------------------------------*/
|
*-----------------------------------------------------------------------*/
|
||||||
int32_t BME280::i2c_write_string(uint8_t dev_addr,uint8_t* ptr, uint8_t cnt)
|
int32_t BME280::i2c_write_string(uint8_t dev_addr,uint8_t* ptr, uint8_t cnt)
|
||||||
{
|
{
|
||||||
mraa::Result ret;
|
mraa::Result ret;
|
||||||
m_i2c->address(dev_addr);
|
m_i2c->address(dev_addr);
|
||||||
|
|
||||||
if((ret = m_i2c->write((const uint8_t*) (ptr), cnt)) != 0)
|
|
||||||
{
|
|
||||||
UPM_THROW("I2C write error");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if((ret = m_i2c->write((const uint8_t*) (ptr), cnt)) != 0)
|
||||||
|
{
|
||||||
|
UPM_THROW("I2C write error");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* \Brief: The function is used as I2C bus write
|
/* \Brief: The function is used as I2C bus write
|
||||||
* \Return : Status of the I2C write
|
* \Return : Status of the I2C write
|
||||||
* \param dev_addr : The device address of the sensor
|
* \param dev_addr : The device address of the sensor
|
||||||
* \param reg_addr : Address of the first register, will data is going to be written
|
* \param reg_addr : Address of the first register, will data is going to be written
|
||||||
* \param reg_data : It is a value hold in the array,
|
* \param reg_data : It is a value hold in the array,
|
||||||
* will be used for write the value into the register
|
* will be used for write the value into the register
|
||||||
* \param cnt : The no of byte of data to be write
|
* \param cnt : The no of byte of data to be write
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int8_t BME280::BME280_I2C_bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
|
int8_t BME280::BME280_I2C_bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
|
||||||
|
|
||||||
{
|
{
|
||||||
int32_t iError = BME280_INIT_VALUE;
|
int32_t iError = BME280_INIT_VALUE;
|
||||||
static uint8_t array[I2C_BUFFER_LEN];
|
static uint8_t array[I2C_BUFFER_LEN];
|
||||||
for (int i=0; i<I2C_BUFFER_LEN; i++) array[i]=0;
|
for (int i=0; i<I2C_BUFFER_LEN; i++) array[i]=0;
|
||||||
|
|
||||||
uint8_t stringpos = BME280_INIT_VALUE;
|
uint8_t stringpos = BME280_INIT_VALUE;
|
||||||
array[BME280_INIT_VALUE] = reg_addr;
|
array[BME280_INIT_VALUE] = reg_addr;
|
||||||
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
|
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
|
||||||
array[stringpos + BME280_ONE_U8X] = *(reg_data + stringpos);
|
array[stringpos + BME280_ONE_U8X] = *(reg_data + stringpos);
|
||||||
}
|
}
|
||||||
iError = i2c_write_string(dev_addr,array, cnt+1);
|
iError = i2c_write_string(dev_addr,array, cnt+1);
|
||||||
return (int8_t)iError;
|
return (int8_t)iError;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t BME280::i2c_write_read_string(uint8_t dev_addr,uint8_t reg_addr , uint8_t * ptr, uint8_t cnt)
|
int32_t BME280::i2c_write_read_string(uint8_t dev_addr,uint8_t reg_addr , uint8_t * ptr, uint8_t cnt)
|
||||||
{
|
{
|
||||||
mraa::Result ret;
|
mraa::Result ret;
|
||||||
|
|
||||||
m_i2c->address(dev_addr);
|
m_i2c->address(dev_addr);
|
||||||
|
|
||||||
if( m_i2c->readBytesReg(reg_addr, ptr, cnt) != cnt)
|
if( m_i2c->readBytesReg(reg_addr, ptr, cnt) != cnt)
|
||||||
{
|
{
|
||||||
UPM_THROW("bme280 register read failed");
|
UPM_THROW("bme280 register read failed");
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* \Brief: The function is used as I2C bus read
|
/* \Brief: The function is used as I2C bus read
|
||||||
* \Return : Status of the I2C read
|
* \Return : Status of the I2C read
|
||||||
* \param dev_addr : The device address of the sensor
|
* \param dev_addr : The device address of the sensor
|
||||||
* \param reg_addr : Address of the first register, will data is going to be read
|
* \param reg_addr : Address of the first register, will data is going to be read
|
||||||
* \param reg_data : This data read from the sensor, which is hold in an array
|
* \param reg_data : This data read from the sensor, which is hold in an array
|
||||||
* \param cnt : The no of data byte of to be read
|
* \param cnt : The no of data byte of to be read
|
||||||
*/
|
*/
|
||||||
int8_t BME280::BME280_I2C_bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
|
int8_t BME280::BME280_I2C_bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
|
||||||
{
|
{
|
||||||
int32_t iError = BME280_INIT_VALUE;
|
int32_t iError = BME280_INIT_VALUE;
|
||||||
uint8_t array[I2C_BUFFER_LEN] = {BME280_INIT_VALUE};
|
uint8_t array[I2C_BUFFER_LEN] = {BME280_INIT_VALUE};
|
||||||
uint8_t stringpos = BME280_INIT_VALUE;
|
uint8_t stringpos = BME280_INIT_VALUE;
|
||||||
array[BME280_INIT_VALUE] = reg_addr;
|
array[BME280_INIT_VALUE] = reg_addr;
|
||||||
i2c_write_read_string(dev_addr,reg_addr,array,cnt);
|
i2c_write_read_string(dev_addr,reg_addr,array,cnt);
|
||||||
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
|
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
|
||||||
*(reg_data + stringpos) = array[stringpos];
|
*(reg_data + stringpos) = array[stringpos];
|
||||||
}
|
}
|
||||||
return (int8_t)iError;
|
return (int8_t)iError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Brief : The delay routine
|
/* Brief : The delay routine
|
||||||
* \param : delay in ms
|
* \param : delay in ms
|
||||||
*/
|
*/
|
||||||
void BME280::BME280_delay_msek(uint16_t mseconds)
|
void BME280::BME280_delay_msek(uint16_t mseconds)
|
||||||
{
|
{
|
||||||
struct timespec sleepTime;
|
struct timespec sleepTime;
|
||||||
|
|
||||||
sleepTime.tv_sec = mseconds / 1000; // Number of seconds
|
sleepTime.tv_sec = mseconds / 1000; // Number of seconds
|
||||||
sleepTime.tv_nsec = ( mseconds % 1000 ) * 1000000; // Convert fractional seconds to nanoseconds
|
sleepTime.tv_nsec = ( mseconds % 1000 ) * 1000000; // Convert fractional seconds to nanoseconds
|
||||||
|
|
||||||
// Iterate nanosleep in a loop until the total sleep time is the original
|
|
||||||
// value of the seconds parameter
|
|
||||||
while ( ( nanosleep( &sleepTime, &sleepTime ) != 0 ) && ( errno == EINTR ) );
|
|
||||||
|
|
||||||
|
// Iterate nanosleep in a loop until the total sleep time is the original
|
||||||
|
// value of the seconds parameter
|
||||||
|
while ( ( nanosleep( &sleepTime, &sleepTime ) != 0 ) && ( errno == EINTR ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user