commit dc6b42962790e60914bf21ae650cacf9b965c207 Author: szune Date: Mon Nov 11 12:27:36 2019 +0000 Move other projects under "projects" repository. diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..864de8e --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 19 + buildToolsVersion "28.0.3" + + externalNativeBuild { + ndkBuild { + path "src/main/jni/Android.mk" + } + + cmake { + version "3.10.2" + } + } + + defaultConfig { + applicationId "com.hardkernel.odroid.weatherboard" + minSdkVersion 19 + targetSdkVersion 19 + + ndk { + moduleName "weather" + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..c978025 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/hardkernel/odroid/weatherboard/MainActivity.java b/app/src/main/java/com/hardkernel/odroid/weatherboard/MainActivity.java new file mode 100644 index 0000000..c1aa986 --- /dev/null +++ b/app/src/main/java/com/hardkernel/odroid/weatherboard/MainActivity.java @@ -0,0 +1,120 @@ +package com.hardkernel.odroid.weatherboard; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.util.Log; +import android.widget.CompoundButton; +import android.widget.TextView; +import android.widget.ToggleButton; + +public class MainActivity extends Activity { + + private final static String TAG = "weather"; + private final static String I2C_1_NODE = "/dev/i2c-1"; + private boolean mStopWeather; + private ToggleButton mBtn_Weather; + private TextView mTV_Temperature; + private TextView mTV_Humidity; + private TextView mTV_Pressure; + private TextView mTV_Altitude; + private Handler handler = new Handler(); + Runnable mRunnableWeather = new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + updateWeather(); + } + }; + + private TextView mTV_UV_index; + private TextView mTV_Visible; + private TextView mTV_IR; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mBtn_Weather = (ToggleButton) findViewById(R.id.tb_weather); + mBtn_Weather.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // TODO Auto-generated method stub + if (isChecked) { + if (openWeatherBoard(I2C_1_NODE) == -1) { + Log.e(TAG, "failed"); + return; + } + mStopWeather = false; + handler.postDelayed(mRunnableWeather, 300); + } else { + mStopWeather = true; + closeWeatherBoard(); + mTV_Temperature.setText("Temperature :"); + mTV_Humidity.setText("Humidity :"); + mTV_Pressure.setText("Pressure :"); + mTV_Altitude.setText("Altitude :"); + mTV_UV_index.setText("UV index :"); + mTV_Visible.setText("Visible :"); + mTV_IR.setText("IR :"); + } + } + }); + + mTV_Temperature = (TextView) findViewById(R.id.tv_temperature); + mTV_Humidity = (TextView) findViewById(R.id.tv_humidity); + mTV_Pressure = (TextView) findViewById(R.id.tv_pressure); + mTV_Altitude = (TextView) findViewById(R.id.tv_altitude); + + mTV_UV_index = (TextView) findViewById(R.id.tv_uv_index); + mTV_Visible = (TextView) findViewById(R.id.tv_visible); + mTV_IR = (TextView) findViewById(R.id.tv_ir); + } + + @Override + protected void onPause() { + // TODO Auto-generated method stub + super.onPause(); + mBtn_Weather.setChecked(false); + } + + private void updateWeather() { + if (mStopWeather == true) + return; + mTV_UV_index.setText("UV index : " + + String.format("%.2f", (double)getUVindex() / 100.0)); + mTV_Visible.setText("Visible : " + + String.format("%.0f", (double)getVisible()) + " Lux"); + mTV_IR.setText("IR : " + + String.format("%.0f", (double)getIR()) + " Lux"); + readyData(); + mTV_Temperature.setText("Temperature : " + + String.format("%.2f", getTemperature() / 100.0) + " °C"); + mTV_Humidity.setText("Humidity : " + + String.format("%.2f", getHumidity() / 1024.0) + " %"); + mTV_Pressure.setText("Pressure : " + + String.format("%.2f", getPressure() / 100.0) + " hPa"); + mTV_Altitude.setText("Altitude : " + getAltitude() + " m"); + + if (!mStopWeather) + handler.postDelayed(mRunnableWeather, 1000); + } + + public native int openWeatherBoard(String dev); + public native int closeWeatherBoard(); + public native void readyData(); + public native int getUVindex(); + public native float getVisible(); + public native float getIR(); + public native int getTemperature(); + public native int getPressure(); + public native int getHumidity(); + public native int getAltitude(); + + static { + System.loadLibrary("weather"); + } +} diff --git a/app/src/main/jni/Android.mk b/app/src/main/jni/Android.mk new file mode 100644 index 0000000..ac584b9 --- /dev/null +++ b/app/src/main/jni/Android.mk @@ -0,0 +1,15 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_C_INCLUDES += \ + $(NDK_PATH)/platforms/android-21/arch-arm/usr/include + +LOCAL_MODULE := weather +LOCAL_SRC_FILES := \ + weather.c \ + bme280-i2c.c \ + bme280.c \ + si1132.c +LOCAL_LDLIBS := -ldl -llog + +include $(BUILD_SHARED_LIBRARY) diff --git a/app/src/main/jni/bme280-i2c.c b/app/src/main/jni/bme280-i2c.c new file mode 100644 index 0000000..d7fc6ec --- /dev/null +++ b/app/src/main/jni/bme280-i2c.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include + +#include "bme280-i2c.h" +#include +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) +#define LOG_TAG "wpi_android" + + +s32 bme280_begin(const char *device) +{ + int status = 0; + s32 com_rslt = 0; + bme280Fd = -1; + + bme280Fd = open(device, O_RDWR); + if (bme280Fd < 0) { + printf("ERROR: bme280 open failed\n"); + return -1; + } + status = ioctl(bme280Fd, I2C_SLAVE, BME280_I2C_ADDRESS1); + if (status < 0) { + printf("ERROR: bme280 ioctl error\n"); + close(bme280Fd); + return -1; + } + + I2C_routine(); + + if (bme280_init(&bme280) < 0) { + return -1; + } + + com_rslt += bme280_set_power_mode(BME280_NORMAL_MODE); + com_rslt += bme280_set_oversamp_humidity(BME280_OVERSAMP_2X); + com_rslt += bme280_set_oversamp_pressure(BME280_OVERSAMP_2X); + com_rslt += bme280_set_oversamp_temperature(BME280_OVERSAMP_2X); + usleep(100000); + + return com_rslt; +} + +void bme280_end() +{ + if (bme280Fd) + close(bme280Fd); +} + +void bme280_readAltitude(int pressure, float *seaLevel, int *result) +{ + float atmospheric = (float)pressure/100.0; + *result = (int)(44330.0 * (1.0 - pow(atmospheric/ *seaLevel, 0.1903))); +} + +s8 BME280_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt) +{ + s32 iError = BME280_INIT_VALUE; + u8 stringpos = BME280_INIT_VALUE; + unsigned char wbuf[2]; + for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) { + wbuf[1] = *(reg_data + stringpos); + wbuf[0] = reg_addr + stringpos; + write(bme280Fd, wbuf, 2); + } + return (s8)iError; +} + +s8 BME280_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt) +{ + s32 iError = BME280_INIT_VALUE; + u8 stringpos = BME280_INIT_VALUE; + unsigned char rbuf[2]; + int i; + for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) { + rbuf[0] = reg_addr + stringpos; + write(bme280Fd, rbuf, 1); + read(bme280Fd, rbuf, 1); + if (rbuf[0] < 0) iError = -1; + else *(reg_data + stringpos) = rbuf[0]; + } + return (s8)iError; +} + +void BME280_delay_msek(u16 msek) +{ + usleep(msek*1000); +} + +s8 I2C_routine(void) { + bme280.bus_write = BME280_I2C_bus_write; + bme280.bus_read = BME280_I2C_bus_read; + bme280.dev_addr = BME280_I2C_ADDRESS1; + bme280.delay_msec = BME280_delay_msek; + + return BME280_INIT_VALUE; +} diff --git a/app/src/main/jni/bme280-i2c.h b/app/src/main/jni/bme280-i2c.h new file mode 100644 index 0000000..017c51a --- /dev/null +++ b/app/src/main/jni/bme280-i2c.h @@ -0,0 +1,16 @@ +#include "bme280.h" + +int bme280Fd; + +struct bme280_t bme280; + +s32 bme280_begin(const char *device); +void bme280_end(); +void bme280_readAltitude(int pressure, float *seaLevelult, int *result); + +s8 I2C_routine(void); + +s8 BME280_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt); +s8 BME280_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt); + +void BME280_delay_msek(u16 msek); diff --git a/app/src/main/jni/bme280.c b/app/src/main/jni/bme280.c new file mode 100644 index 0000000..cd60891 --- /dev/null +++ b/app/src/main/jni/bme280.c @@ -0,0 +1,2215 @@ +/* +**************************************************************************** +* Copyright (C) 2013 - 2015 Bosch Sensortec GmbH +* +* bme280.c +* Date: 2015/03/27 +* Revision: 2.0.4(Pressure and Temperature compensation code revision is 1.1 +* and Humidity compensation code revision is 1.0) +* +* Usage: Sensor Driver file for BME280 sensor +* +**************************************************************************** +* License: +* +* 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 the +* 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 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 +* +* The information provided is believed to be accurate and reliable. +* The copyright holder assumes no responsibility +* for the consequences of use +* of such information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of the copyright holder. +**************************************************************************/ + +#include "bme280.h" +static struct bme280_t *p_bme280; /**< pointer to BME280 */ + +/*! + * @brief This function is used for initialize + * the bus read and bus write functions + * and assign the chip id and I2C address of the BME280 sensor + * chip id is read in the register 0xD0 bit from 0 to 7 + * + * @param bme280 structure pointer. + * + * @note While changing the parameter of the bme280_t + * @note consider the following point: + * Changing the reference value of the parameter + * will changes the local copy or local reference + * make sure your changes will not + * affect the reference value of the parameter + * (Better case don't change the reference value of the parameter) + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_init(struct bme280_t *bme280) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + + p_bme280 = bme280; + /* assign BME280 ptr */ + com_rslt = p_bme280->BME280_BUS_READ_FUNC(p_bme280->dev_addr, + BME280_CHIP_ID_REG, &v_data_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* read Chip Id */ + p_bme280->chip_id = v_data_u8; + if (p_bme280->chip_id != 0x60) { + return -1; + } + + com_rslt += bme280_get_calib_param(); + /* readout bme280 calibparam structure */ + return com_rslt; +} +/*! + * @brief This API is used to read uncompensated temperature + * in the registers 0xFA, 0xFB and 0xFC + * @note 0xFA -> MSB -> bit from 0 to 7 + * @note 0xFB -> LSB -> bit from 0 to 7 + * @note 0xFC -> LSB -> bit from 4 to 7 + * + * @param v_uncomp_temperature_s32 : The value of uncompensated temperature + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_temperature( +s32 *v_uncomp_temperature_s32) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + /* Array holding the MSB and LSb value + a_data_u8r[0] - Temperature MSB + a_data_u8r[1] - Temperature LSB + a_data_u8r[2] - Temperature XLSB + */ + u8 a_data_u8r[BME280_TEMPERATURE_DATA_SIZE] = { + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE}; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_TEMPERATURE_MSB_REG, + a_data_u8r, + BME280_TEMPERATURE_DATA_LENGTH); + *v_uncomp_temperature_s32 = (s32)((( + (u32) (a_data_u8r[BME280_TEMPERATURE_MSB_DATA])) + << BME280_SHIFT_BIT_POSITION_BY_12_BITS) | + (((u32)(a_data_u8r[BME280_TEMPERATURE_LSB_DATA])) + << BME280_SHIFT_BIT_POSITION_BY_04_BITS) + | ((u32)a_data_u8r[BME280_TEMPERATURE_XLSB_DATA] >> + BME280_SHIFT_BIT_POSITION_BY_04_BITS)); + } + return com_rslt; +} +/*! + * @brief Reads actual temperature from uncompensated temperature + * @note Returns the value in 0.01 degree Centigrade + * Output value of "5123" equals 51.23 DegC. + * + * + * + * @param v_uncomp_temperature_s32 : value of uncompensated temperature + * + * + * @return Returns the actual temperature + * +*/ +s32 bme280_compensate_temperature_int32(s32 v_uncomp_temperature_s32) +{ + s32 v_x1_u32r = BME280_INIT_VALUE; + s32 v_x2_u32r = BME280_INIT_VALUE; + s32 temperature = BME280_INIT_VALUE; + + /* calculate x1*/ + v_x1_u32r = + ((((v_uncomp_temperature_s32 + >> BME280_SHIFT_BIT_POSITION_BY_03_BITS) - + ((s32)p_bme280->cal_param.dig_T1 + << BME280_SHIFT_BIT_POSITION_BY_01_BIT))) * + ((s32)p_bme280->cal_param.dig_T2)) >> + BME280_SHIFT_BIT_POSITION_BY_11_BITS; + /* calculate x2*/ + v_x2_u32r = (((((v_uncomp_temperature_s32 + >> BME280_SHIFT_BIT_POSITION_BY_04_BITS) - + ((s32)p_bme280->cal_param.dig_T1)) + * ((v_uncomp_temperature_s32 >> BME280_SHIFT_BIT_POSITION_BY_04_BITS) - + ((s32)p_bme280->cal_param.dig_T1))) + >> BME280_SHIFT_BIT_POSITION_BY_12_BITS) * + ((s32)p_bme280->cal_param.dig_T3)) + >> BME280_SHIFT_BIT_POSITION_BY_14_BITS; + /* calculate t_fine*/ + p_bme280->cal_param.t_fine = v_x1_u32r + v_x2_u32r; + /* calculate temperature*/ + temperature = (p_bme280->cal_param.t_fine * 5 + 128) + >> BME280_SHIFT_BIT_POSITION_BY_08_BITS; + return temperature; +} +/*! + * @brief Reads actual temperature from uncompensated temperature + * @note Returns the value with 500LSB/DegC centred around 24 DegC + * output value of "5123" equals(5123/500)+24 = 34.246DegC + * + * + * @param v_uncomp_temperature_s32: value of uncompensated temperature + * + * + * + * @return Return the actual temperature as s16 output + * +*/ +s16 bme280_compensate_temperature_int32_sixteen_bit_output( +s32 v_uncomp_temperature_s32) +{ + s16 temperature = BME280_INIT_VALUE; + + bme280_compensate_temperature_int32( + v_uncomp_temperature_s32); + temperature = (s16)(((( + p_bme280->cal_param.t_fine - 122880) * 25) + 128) + >> BME280_SHIFT_BIT_POSITION_BY_08_BITS); + + return temperature; +} +/*! + * @brief This API is used to read uncompensated pressure. + * in the registers 0xF7, 0xF8 and 0xF9 + * @note 0xF7 -> MSB -> bit from 0 to 7 + * @note 0xF8 -> LSB -> bit from 0 to 7 + * @note 0xF9 -> LSB -> bit from 4 to 7 + * + * + * + * @param v_uncomp_pressure_s32 : The value of uncompensated pressure + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure( +s32 *v_uncomp_pressure_s32) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + /* Array holding the MSB and LSb value + a_data_u8[0] - Pressure MSB + a_data_u8[1] - Pressure LSB + a_data_u8[2] - Pressure XLSB + */ + u8 a_data_u8[BME280_PRESSURE_DATA_SIZE] = { + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE}; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_PRESSURE_MSB_REG, + a_data_u8, BME280_PRESSURE_DATA_LENGTH); + *v_uncomp_pressure_s32 = (s32)(( + ((u32)(a_data_u8[BME280_PRESSURE_MSB_DATA])) + << BME280_SHIFT_BIT_POSITION_BY_12_BITS) | + (((u32)(a_data_u8[BME280_PRESSURE_LSB_DATA])) + << BME280_SHIFT_BIT_POSITION_BY_04_BITS) | + ((u32)a_data_u8[BME280_PRESSURE_XLSB_DATA] >> + BME280_SHIFT_BIT_POSITION_BY_04_BITS)); + } + return com_rslt; +} +/*! + * @brief Reads actual pressure from uncompensated pressure + * @note Returns the value in Pascal(Pa) + * Output value of "96386" equals 96386 Pa = + * 963.86 hPa = 963.86 millibar + * + * + * + * @param v_uncomp_pressure_s32 : value of uncompensated pressure + * + * + * + * @return Return the actual pressure output as u32 + * +*/ +u32 bme280_compensate_pressure_int32(s32 v_uncomp_pressure_s32) +{ + s32 v_x1_u32 = BME280_INIT_VALUE; + s32 v_x2_u32 = BME280_INIT_VALUE; + u32 v_pressure_u32 = BME280_INIT_VALUE; + + /* calculate x1*/ + v_x1_u32 = (((s32)p_bme280->cal_param.t_fine) + >> BME280_SHIFT_BIT_POSITION_BY_01_BIT) - (s32)64000; + /* calculate x2*/ + v_x2_u32 = (((v_x1_u32 >> BME280_SHIFT_BIT_POSITION_BY_02_BITS) + * (v_x1_u32 >> BME280_SHIFT_BIT_POSITION_BY_02_BITS) + ) >> BME280_SHIFT_BIT_POSITION_BY_11_BITS) + * ((s32)p_bme280->cal_param.dig_P6); + /* calculate x2*/ + v_x2_u32 = v_x2_u32 + ((v_x1_u32 * + ((s32)p_bme280->cal_param.dig_P5)) + << BME280_SHIFT_BIT_POSITION_BY_01_BIT); + /* calculate x2*/ + v_x2_u32 = (v_x2_u32 >> BME280_SHIFT_BIT_POSITION_BY_02_BITS) + + (((s32)p_bme280->cal_param.dig_P4) + << BME280_SHIFT_BIT_POSITION_BY_16_BITS); + /* calculate x1*/ + v_x1_u32 = (((p_bme280->cal_param.dig_P3 * + (((v_x1_u32 >> BME280_SHIFT_BIT_POSITION_BY_02_BITS) * + (v_x1_u32 >> BME280_SHIFT_BIT_POSITION_BY_02_BITS)) + >> BME280_SHIFT_BIT_POSITION_BY_13_BITS)) + >> BME280_SHIFT_BIT_POSITION_BY_03_BITS) + + ((((s32)p_bme280->cal_param.dig_P2) * + v_x1_u32) >> BME280_SHIFT_BIT_POSITION_BY_01_BIT)) + >> BME280_SHIFT_BIT_POSITION_BY_18_BITS; + /* calculate x1*/ + v_x1_u32 = ((((32768 + v_x1_u32)) * + ((s32)p_bme280->cal_param.dig_P1)) + >> BME280_SHIFT_BIT_POSITION_BY_15_BITS); + /* calculate pressure*/ + v_pressure_u32 = + (((u32)(((s32)1048576) - v_uncomp_pressure_s32) + - (v_x2_u32 >> BME280_SHIFT_BIT_POSITION_BY_12_BITS))) * 3125; + if (v_pressure_u32 + < 0x80000000) + /* Avoid exception caused by division by zero */ + if (v_x1_u32 != BME280_INIT_VALUE) + v_pressure_u32 = + (v_pressure_u32 + << BME280_SHIFT_BIT_POSITION_BY_01_BIT) / + ((u32)v_x1_u32); + else + return BME280_INVALID_DATA; + else + /* Avoid exception caused by division by zero */ + if (v_x1_u32 != BME280_INIT_VALUE) + v_pressure_u32 = (v_pressure_u32 + / (u32)v_x1_u32) * 2; + else + return BME280_INVALID_DATA; + + v_x1_u32 = (((s32)p_bme280->cal_param.dig_P9) * + ((s32)(((v_pressure_u32 >> BME280_SHIFT_BIT_POSITION_BY_03_BITS) + * (v_pressure_u32 >> BME280_SHIFT_BIT_POSITION_BY_03_BITS)) + >> BME280_SHIFT_BIT_POSITION_BY_13_BITS))) + >> BME280_SHIFT_BIT_POSITION_BY_12_BITS; + v_x2_u32 = (((s32)(v_pressure_u32 + >> BME280_SHIFT_BIT_POSITION_BY_02_BITS)) * + ((s32)p_bme280->cal_param.dig_P8)) + >> BME280_SHIFT_BIT_POSITION_BY_13_BITS; + v_pressure_u32 = (u32)((s32)v_pressure_u32 + + ((v_x1_u32 + v_x2_u32 + p_bme280->cal_param.dig_P7) + >> BME280_SHIFT_BIT_POSITION_BY_04_BITS)); + + return v_pressure_u32; +} +/*! + * @brief This API is used to read uncompensated humidity. + * in the registers 0xF7, 0xF8 and 0xF9 + * @note 0xFD -> MSB -> bit from 0 to 7 + * @note 0xFE -> LSB -> bit from 0 to 7 + * + * + * + * @param v_uncomp_humidity_s32 : The value of uncompensated humidity + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_humidity( +s32 *v_uncomp_humidity_s32) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + /* Array holding the MSB and LSb value + a_data_u8[0] - Humidity MSB + a_data_u8[1] - Humidity LSB + */ + u8 a_data_u8[BME280_HUMIDITY_DATA_SIZE] = { + BME280_INIT_VALUE, BME280_INIT_VALUE}; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_HUMIDITY_MSB_REG, a_data_u8, + BME280_HUMIDITY_DATA_LENGTH); + *v_uncomp_humidity_s32 = (s32)( + (((u32)(a_data_u8[BME280_HUMIDITY_MSB_DATA])) + << BME280_SHIFT_BIT_POSITION_BY_08_BITS)| + ((u32)(a_data_u8[BME280_HUMIDITY_LSB_DATA]))); + } + return com_rslt; +} +/*! + * @brief Reads actual humidity from uncompensated humidity + * @note Returns the value in %rH as unsigned 32bit integer + * in Q22.10 format(22 integer 10 fractional bits). + * @note An output value of 42313 + * represents 42313 / 1024 = 41.321 %rH + * + * + * + * @param v_uncomp_humidity_s32: value of uncompensated humidity + * + * @return Return the actual relative humidity output as u32 + * +*/ +u32 bme280_compensate_humidity_int32(s32 v_uncomp_humidity_s32) +{ + s32 v_x1_u32 = BME280_INIT_VALUE; + + /* calculate x1*/ + v_x1_u32 = (p_bme280->cal_param.t_fine - ((s32)76800)); + /* calculate x1*/ + v_x1_u32 = (((((v_uncomp_humidity_s32 + << BME280_SHIFT_BIT_POSITION_BY_14_BITS) - + (((s32)p_bme280->cal_param.dig_H4) + << BME280_SHIFT_BIT_POSITION_BY_20_BITS) - + (((s32)p_bme280->cal_param.dig_H5) * v_x1_u32)) + + ((s32)16384)) >> BME280_SHIFT_BIT_POSITION_BY_15_BITS) + * (((((((v_x1_u32 * + ((s32)p_bme280->cal_param.dig_H6)) + >> BME280_SHIFT_BIT_POSITION_BY_10_BITS) * + (((v_x1_u32 * ((s32)p_bme280->cal_param.dig_H3)) + >> BME280_SHIFT_BIT_POSITION_BY_11_BITS) + ((s32)32768))) + >> BME280_SHIFT_BIT_POSITION_BY_10_BITS) + ((s32)2097152)) * + ((s32)p_bme280->cal_param.dig_H2) + 8192) >> 14)); + v_x1_u32 = (v_x1_u32 - (((((v_x1_u32 + >> BME280_SHIFT_BIT_POSITION_BY_15_BITS) * + (v_x1_u32 >> BME280_SHIFT_BIT_POSITION_BY_15_BITS)) + >> BME280_SHIFT_BIT_POSITION_BY_07_BITS) * + ((s32)p_bme280->cal_param.dig_H1)) + >> BME280_SHIFT_BIT_POSITION_BY_04_BITS)); + v_x1_u32 = (v_x1_u32 < 0 ? 0 : v_x1_u32); + v_x1_u32 = (v_x1_u32 > 419430400 ? + 419430400 : v_x1_u32); + return (u32)(v_x1_u32 >> BME280_SHIFT_BIT_POSITION_BY_12_BITS); +} +/*! + * @brief Reads actual humidity from uncompensated humidity + * @note Returns the value in %rH as unsigned 16bit integer + * @note An output value of 42313 + * represents 42313/512 = 82.643 %rH + * + * + * + * @param v_uncomp_humidity_s32: value of uncompensated humidity + * + * + * @return Return the actual relative humidity output as u16 + * +*/ +u16 bme280_compensate_humidity_int32_sixteen_bit_output( +s32 v_uncomp_humidity_s32) +{ + u32 v_x1_u32 = BME280_INIT_VALUE; + u16 v_x2_u32 = BME280_INIT_VALUE; + + v_x1_u32 = bme280_compensate_humidity_int32(v_uncomp_humidity_s32); + v_x2_u32 = (u16)(v_x1_u32 >> BME280_SHIFT_BIT_POSITION_BY_01_BIT); + return v_x2_u32; +} +/*! + * @brief This API used to read uncompensated + * pressure,temperature and humidity + * + * + * + * + * @param v_uncomp_pressure_s32: The value of uncompensated pressure. + * @param v_uncomp_temperature_s32: The value of uncompensated temperature + * @param v_uncomp_humidity_s32: The value of uncompensated humidity. + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure_temperature_humidity( +s32 *v_uncomp_pressure_s32, +s32 *v_uncomp_temperature_s32, s32 *v_uncomp_humidity_s32) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + /* Array holding the MSB and LSb value of + a_data_u8[0] - Pressure MSB + a_data_u8[1] - Pressure LSB + a_data_u8[1] - Pressure LSB + a_data_u8[1] - Temperature MSB + a_data_u8[1] - Temperature LSB + a_data_u8[1] - Temperature LSB + a_data_u8[1] - Humidity MSB + a_data_u8[1] - Humidity LSB + */ + u8 a_data_u8[BME280_DATA_FRAME_SIZE] = { + BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE}; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_PRESSURE_MSB_REG, + a_data_u8, BME280_ALL_DATA_FRAME_LENGTH); + /*Pressure*/ + *v_uncomp_pressure_s32 = (s32)(( + ((u32)(a_data_u8[ + BME280_DATA_FRAME_PRESSURE_MSB_BYTE])) + << BME280_SHIFT_BIT_POSITION_BY_12_BITS) | + (((u32)(a_data_u8[ + BME280_DATA_FRAME_PRESSURE_LSB_BYTE])) + << BME280_SHIFT_BIT_POSITION_BY_04_BITS) | + ((u32)a_data_u8[ + BME280_DATA_FRAME_PRESSURE_XLSB_BYTE] >> + BME280_SHIFT_BIT_POSITION_BY_04_BITS)); + + /* Temperature */ + *v_uncomp_temperature_s32 = (s32)((( + (u32) (a_data_u8[ + BME280_DATA_FRAME_TEMPERATURE_MSB_BYTE])) + << BME280_SHIFT_BIT_POSITION_BY_12_BITS) | + (((u32)(a_data_u8[ + BME280_DATA_FRAME_TEMPERATURE_LSB_BYTE])) + << BME280_SHIFT_BIT_POSITION_BY_04_BITS) + | ((u32)a_data_u8[ + BME280_DATA_FRAME_TEMPERATURE_XLSB_BYTE] + >> BME280_SHIFT_BIT_POSITION_BY_04_BITS)); + + /*Humidity*/ + *v_uncomp_humidity_s32 = (s32)(( + ((u32)(a_data_u8[ + BME280_DATA_FRAME_HUMIDITY_MSB_BYTE])) + << BME280_SHIFT_BIT_POSITION_BY_08_BITS)| + ((u32)(a_data_u8[ + BME280_DATA_FRAME_HUMIDITY_LSB_BYTE]))); + } + return com_rslt; +} +/*! + * @brief This API used to read true pressure, temperature and humidity + * + * + * + * + * @param v_pressure_u32 : The value of compensated pressure. + * @param v_temperature_s32 : The value of compensated temperature. + * @param v_humidity_u32 : The value of compensated humidity. + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_pressure_temperature_humidity( +u32 *v_pressure_u32, s32 *v_temperature_s32, u32 *v_humidity_u32) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + s32 v_uncomp_pressure_s32 = BME280_INIT_VALUE; + s32 v_uncom_temperature_s32 = BME280_INIT_VALUE; + s32 v_uncom_humidity_s32 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + /* read the uncompensated pressure, + temperature and humidity*/ + com_rslt = + bme280_read_uncomp_pressure_temperature_humidity( + &v_uncomp_pressure_s32, &v_uncom_temperature_s32, + &v_uncom_humidity_s32); + /* read the true pressure, temperature and humidity*/ + *v_temperature_s32 = + bme280_compensate_temperature_int32( + v_uncom_temperature_s32); + *v_pressure_u32 = bme280_compensate_pressure_int32( + v_uncomp_pressure_s32); + *v_humidity_u32 = bme280_compensate_humidity_int32( + v_uncom_humidity_s32); + } + return com_rslt; +} +/*! + * @brief This API is used to + * calibration parameters used for calculation in the registers + * + * parameter | Register address | bit + *------------|------------------|---------------- + * dig_T1 | 0x88 and 0x89 | from 0 : 7 to 8: 15 + * dig_T2 | 0x8A and 0x8B | from 0 : 7 to 8: 15 + * dig_T3 | 0x8C and 0x8D | from 0 : 7 to 8: 15 + * dig_P1 | 0x8E and 0x8F | from 0 : 7 to 8: 15 + * dig_P2 | 0x90 and 0x91 | from 0 : 7 to 8: 15 + * dig_P3 | 0x92 and 0x93 | from 0 : 7 to 8: 15 + * dig_P4 | 0x94 and 0x95 | from 0 : 7 to 8: 15 + * dig_P5 | 0x96 and 0x97 | from 0 : 7 to 8: 15 + * dig_P6 | 0x98 and 0x99 | from 0 : 7 to 8: 15 + * dig_P7 | 0x9A and 0x9B | from 0 : 7 to 8: 15 + * dig_P8 | 0x9C and 0x9D | from 0 : 7 to 8: 15 + * dig_P9 | 0x9E and 0x9F | from 0 : 7 to 8: 15 + * dig_H1 | 0xA1 | from 0 to 7 + * dig_H2 | 0xE1 and 0xE2 | from 0 : 7 to 8: 15 + * dig_H3 | 0xE3 | from 0 to 7 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_calib_param(void) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 a_data_u8[BME280_CALIB_DATA_SIZE] = { + BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE, + BME280_INIT_VALUE, BME280_INIT_VALUE, BME280_INIT_VALUE}; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_TEMPERATURE_CALIB_DIG_T1_LSB_REG, + a_data_u8, + BME280_PRESSURE_TEMPERATURE_CALIB_DATA_LENGTH); + + p_bme280->cal_param.dig_T1 = (u16)((( + (u16)((u8)a_data_u8[ + BME280_TEMPERATURE_CALIB_DIG_T1_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_TEMPERATURE_CALIB_DIG_T1_LSB]); + p_bme280->cal_param.dig_T2 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_TEMPERATURE_CALIB_DIG_T2_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_TEMPERATURE_CALIB_DIG_T2_LSB]); + p_bme280->cal_param.dig_T3 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_TEMPERATURE_CALIB_DIG_T3_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_TEMPERATURE_CALIB_DIG_T3_LSB]); + p_bme280->cal_param.dig_P1 = (u16)((( + (u16)((u8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P1_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_PRESSURE_CALIB_DIG_P1_LSB]); + p_bme280->cal_param.dig_P2 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P2_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_PRESSURE_CALIB_DIG_P2_LSB]); + p_bme280->cal_param.dig_P3 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P3_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P3_LSB]); + p_bme280->cal_param.dig_P4 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P4_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_PRESSURE_CALIB_DIG_P4_LSB]); + p_bme280->cal_param.dig_P5 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P5_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_PRESSURE_CALIB_DIG_P5_LSB]); + p_bme280->cal_param.dig_P6 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P6_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_PRESSURE_CALIB_DIG_P6_LSB]); + p_bme280->cal_param.dig_P7 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P7_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_PRESSURE_CALIB_DIG_P7_LSB]); + p_bme280->cal_param.dig_P8 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P8_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_PRESSURE_CALIB_DIG_P8_LSB]); + p_bme280->cal_param.dig_P9 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_PRESSURE_CALIB_DIG_P9_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_PRESSURE_CALIB_DIG_P9_LSB]); + p_bme280->cal_param.dig_H1 = + a_data_u8[BME280_HUMIDITY_CALIB_DIG_H1]; + com_rslt += p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_HUMIDITY_CALIB_DIG_H2_LSB_REG, a_data_u8, + BME280_HUMIDITY_CALIB_DATA_LENGTH); + p_bme280->cal_param.dig_H2 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_HUMIDITY_CALIB_DIG_H2_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[BME280_HUMIDITY_CALIB_DIG_H2_LSB]); + p_bme280->cal_param.dig_H3 = + a_data_u8[BME280_HUMIDITY_CALIB_DIG_H3]; + p_bme280->cal_param.dig_H4 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_HUMIDITY_CALIB_DIG_H4_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_04_BITS) | + (((u8)BME280_MASK_DIG_H4) & + a_data_u8[BME280_HUMIDITY_CALIB_DIG_H4_LSB])); + p_bme280->cal_param.dig_H5 = (s16)((( + (s16)((s8)a_data_u8[ + BME280_HUMIDITY_CALIB_DIG_H5_MSB])) << + BME280_SHIFT_BIT_POSITION_BY_04_BITS) | + (a_data_u8[BME280_HUMIDITY_CALIB_DIG_H4_LSB] >> + BME280_SHIFT_BIT_POSITION_BY_04_BITS)); + p_bme280->cal_param.dig_H6 = + (s8)a_data_u8[BME280_HUMIDITY_CALIB_DIG_H6]; + } + return com_rslt; +} +/*! + * @brief This API is used to get + * the temperature oversampling setting in the register 0xF4 + * bits from 5 to 7 + * + * value | Temperature oversampling + * ---------------------|--------------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of temperature over sampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_temperature( +u8 *v_value_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + *v_value_u8 = BME280_GET_BITSLICE(v_data_u8, + BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE); + + p_bme280->oversamp_temperature = *v_value_u8; + } + return com_rslt; +} +/*! + * @brief This API is used to set + * the temperature oversampling setting in the register 0xF4 + * bits from 5 to 7 + * + * value | Temperature oversampling + * ---------------------|--------------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of temperature over sampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_temperature( +u8 v_value_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + u8 v_prev_pow_mode_u8 = BME280_INIT_VALUE; + u8 v_pre_ctrl_hum_value_u8 = BME280_INIT_VALUE; + u8 v_pre_config_value_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + v_data_u8 = p_bme280->ctrl_meas_reg; + v_data_u8 = + BME280_SET_BITSLICE(v_data_u8, + BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE, v_value_u8); + com_rslt = bme280_get_power_mode(&v_prev_pow_mode_u8); + if (v_prev_pow_mode_u8 != BME280_SLEEP_MODE) { + com_rslt += bme280_set_soft_rst(); + p_bme280->delay_msec(BME280_3MS_DELAY); + /* write previous value + of configuration register*/ + v_pre_config_value_u8 = p_bme280->config_reg; + com_rslt += bme280_write_register( + BME280_CONFIG_REG, + &v_pre_config_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value + of humidity oversampling*/ + v_pre_ctrl_hum_value_u8 = + p_bme280->ctrl_hum_reg; + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_pre_ctrl_hum_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous and updated value + of configuration register*/ + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + } else { + com_rslt = p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + } + p_bme280->oversamp_temperature = v_value_u8; + /* read the control measurement register value*/ + com_rslt = bme280_read_register( + BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_meas_reg = v_data_u8; + /* read the control humidity register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_hum_reg = v_data_u8; + /* read the control + configuration register value*/ + com_rslt += bme280_read_register( + BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->config_reg = v_data_u8; + } + return com_rslt; +} +/*! + * @brief This API is used to get + * the pressure oversampling setting in the register 0xF4 + * bits from 2 to 4 + * + * value | Pressure oversampling + * --------------------|-------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of pressure oversampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_pressure( +u8 *v_value_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + *v_value_u8 = BME280_GET_BITSLICE( + v_data_u8, + BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE); + + p_bme280->oversamp_pressure = *v_value_u8; + } + return com_rslt; +} +/*! + * @brief This API is used to set + * the pressure oversampling setting in the register 0xF4 + * bits from 2 to 4 + * + * value | Pressure oversampling + * --------------------|-------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of pressure oversampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_pressure( +u8 v_value_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + u8 v_prev_pow_mode_u8 = BME280_INIT_VALUE; + u8 v_pre_ctrl_hum_value_u8 = BME280_INIT_VALUE; + u8 v_pre_config_value_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + v_data_u8 = p_bme280->ctrl_meas_reg; + v_data_u8 = + BME280_SET_BITSLICE(v_data_u8, + BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE, v_value_u8); + com_rslt = bme280_get_power_mode(&v_prev_pow_mode_u8); + if (v_prev_pow_mode_u8 != BME280_SLEEP_MODE) { + com_rslt += bme280_set_soft_rst(); + p_bme280->delay_msec(BME280_3MS_DELAY); + /* write previous value of + configuration register*/ + v_pre_config_value_u8 = p_bme280->config_reg; + com_rslt = bme280_write_register( + BME280_CONFIG_REG, + &v_pre_config_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + humidity oversampling*/ + v_pre_ctrl_hum_value_u8 = + p_bme280->ctrl_hum_reg; + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_pre_ctrl_hum_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous and updated value of + control measurement register*/ + bme280_write_register( + BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + } else { + com_rslt = p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + } + p_bme280->oversamp_pressure = v_value_u8; + /* read the control measurement register value*/ + com_rslt = bme280_read_register( + BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_meas_reg = v_data_u8; + /* read the control humidity register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_hum_reg = v_data_u8; + /* read the control + configuration register value*/ + com_rslt += bme280_read_register( + BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->config_reg = v_data_u8; + } + return com_rslt; +} +/*! + * @brief This API is used to get + * the humidity oversampling setting in the register 0xF2 + * bits from 0 to 2 + * + * value | Humidity oversampling + * ---------------------|------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of humidity over sampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_humidity( +u8 *v_value_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + *v_value_u8 = BME280_GET_BITSLICE( + v_data_u8, + BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY); + + p_bme280->oversamp_humidity = *v_value_u8; + } + return com_rslt; +} +/*! + * @brief This API is used to set + * the humidity oversampling setting in the register 0xF2 + * bits from 0 to 2 + * + * value | Humidity oversampling + * ---------------------|------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of humidity over sampling + * + * + * + * @note The "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" + * register sets the humidity + * data acquisition options of the device. + * @note changes to this registers only become + * effective after a write operation to + * "BME280_CTRL_MEAS_REG" register. + * @note In the code automated reading and writing of + * "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" + * @note register first set the + * "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" + * and then read and write + * the "BME280_CTRL_MEAS_REG" register in the function. + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_humidity( +u8 v_value_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + u8 pre_ctrl_meas_value = BME280_INIT_VALUE; + u8 v_pre_config_value_u8 = BME280_INIT_VALUE; + u8 v_prev_pow_mode_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + /* write humidity oversampling*/ + v_data_u8 = p_bme280->ctrl_hum_reg; + v_data_u8 = + BME280_SET_BITSLICE(v_data_u8, + BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY, v_value_u8); + com_rslt = bme280_get_power_mode(&v_prev_pow_mode_u8); + if (v_prev_pow_mode_u8 != BME280_SLEEP_MODE) { + com_rslt += bme280_set_soft_rst(); + p_bme280->delay_msec(BME280_3MS_DELAY); + /* write previous value of + configuration register*/ + v_pre_config_value_u8 = p_bme280->config_reg; + com_rslt += bme280_write_register( + BME280_CONFIG_REG, + &v_pre_config_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write the value of control humidity*/ + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + control measurement register*/ + pre_ctrl_meas_value = + p_bme280->ctrl_meas_reg; + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &pre_ctrl_meas_value, + BME280_GEN_READ_WRITE_DATA_LENGTH); + } else { + com_rslt += + p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + /* Control humidity write will effective only + after the control measurement register*/ + pre_ctrl_meas_value = + p_bme280->ctrl_meas_reg; + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &pre_ctrl_meas_value, + BME280_GEN_READ_WRITE_DATA_LENGTH); + } + p_bme280->oversamp_humidity = v_value_u8; + /* read the control measurement register value*/ + com_rslt += bme280_read_register(BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_meas_reg = v_data_u8; + /* read the control humidity register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_hum_reg = v_data_u8; + /* read the control configuration register value*/ + com_rslt += bme280_read_register(BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->config_reg = v_data_u8; + } + return com_rslt; +} +/*! + * @brief This API used to get the + * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 + * + * + * + * @param v_power_mode_u8 : The value of power mode + * value | mode + * -----------------|------------------ + * 0x00 | BME280_SLEEP_MODE + * 0x01 and 0x02 | BME280_FORCED_MODE + * 0x03 | BME280_NORMAL_MODE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_power_mode(u8 *v_power_mode_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_mode_u8r = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_CTRL_MEAS_REG_POWER_MODE__REG, + &v_mode_u8r, BME280_GEN_READ_WRITE_DATA_LENGTH); + *v_power_mode_u8 = BME280_GET_BITSLICE(v_mode_u8r, + BME280_CTRL_MEAS_REG_POWER_MODE); + } + return com_rslt; +} +/*! + * @brief This API used to set the + * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 + * + * + * + * @param v_power_mode_u8 : The value of power mode + * value | mode + * -----------------|------------------ + * 0x00 | BME280_SLEEP_MODE + * 0x01 and 0x02 | BME280_FORCED_MODE + * 0x03 | BME280_NORMAL_MODE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_power_mode(u8 v_power_mode_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_mode_u8r = BME280_INIT_VALUE; + u8 v_prev_pow_mode_u8 = BME280_INIT_VALUE; + u8 v_pre_ctrl_hum_value_u8 = BME280_INIT_VALUE; + u8 v_pre_config_value_u8 = BME280_INIT_VALUE; + u8 v_data_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + if (v_power_mode_u8 <= BME280_NORMAL_MODE) { + v_mode_u8r = p_bme280->ctrl_meas_reg; + v_mode_u8r = + BME280_SET_BITSLICE(v_mode_u8r, + BME280_CTRL_MEAS_REG_POWER_MODE, + v_power_mode_u8); + com_rslt = bme280_get_power_mode( + &v_prev_pow_mode_u8); + if (v_prev_pow_mode_u8 != BME280_SLEEP_MODE) { + com_rslt += bme280_set_soft_rst(); + p_bme280->delay_msec(BME280_3MS_DELAY); + /* write previous value of + configuration register*/ + v_pre_config_value_u8 = + p_bme280->config_reg; + com_rslt = bme280_write_register( + BME280_CONFIG_REG, + &v_pre_config_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + humidity oversampling*/ + v_pre_ctrl_hum_value_u8 = + p_bme280->ctrl_hum_reg; + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_pre_ctrl_hum_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous and updated value of + control measurement register*/ + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &v_mode_u8r, + BME280_GEN_READ_WRITE_DATA_LENGTH); + } else { + com_rslt = + p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + BME280_CTRL_MEAS_REG_POWER_MODE__REG, + &v_mode_u8r, + BME280_GEN_READ_WRITE_DATA_LENGTH); + } + /* read the control measurement register value*/ + com_rslt = bme280_read_register( + BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_meas_reg = v_data_u8; + /* read the control humidity register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_hum_reg = v_data_u8; + /* read the config register value*/ + com_rslt += bme280_read_register( + BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->config_reg = v_data_u8; + } else { + com_rslt = E_BME280_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! + * @brief Used to reset the sensor + * The value 0xB6 is written to the 0xE0 + * register the device is reset using the + * complete power-on-reset procedure. + * @note Soft reset can be easily set using bme280_set_softreset(). + * @note Usage Hint : bme280_set_softreset() + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_soft_rst(void) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_SOFT_RESET_CODE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + BME280_RST_REG, &v_data_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} +/*! + * @brief This API used to get the sensor + * SPI mode(communication type) in the register 0xF5 bit 0 + * + * + * + * @param v_enable_disable_u8 : The value of SPI enable + * value | Description + * --------|-------------- + * 0 | Disable + * 1 | Enable + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_spi3(u8 *v_enable_disable_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_CONFIG_REG_SPI3_ENABLE__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + *v_enable_disable_u8 = BME280_GET_BITSLICE( + v_data_u8, + BME280_CONFIG_REG_SPI3_ENABLE); + } + return com_rslt; +} +/*! + * @brief This API used to set the sensor + * SPI mode(communication type) in the register 0xF5 bit 0 + * + * + * + * @param v_enable_disable_u8 : The value of SPI enable + * value | Description + * --------|-------------- + * 0 | Disable + * 1 | Enable + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_spi3(u8 v_enable_disable_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + u8 pre_ctrl_meas_value = BME280_INIT_VALUE; + u8 v_prev_pow_mode_u8 = BME280_INIT_VALUE; + u8 v_pre_ctrl_hum_value_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + v_data_u8 = p_bme280->config_reg; + v_data_u8 = + BME280_SET_BITSLICE(v_data_u8, + BME280_CONFIG_REG_SPI3_ENABLE, v_enable_disable_u8); + com_rslt = bme280_get_power_mode(&v_prev_pow_mode_u8); + if (v_prev_pow_mode_u8 != BME280_SLEEP_MODE) { + com_rslt += bme280_set_soft_rst(); + p_bme280->delay_msec(BME280_3MS_DELAY); + /* write previous and updated value of + configuration register*/ + com_rslt += bme280_write_register( + BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + humidity oversampling*/ + v_pre_ctrl_hum_value_u8 = + p_bme280->ctrl_hum_reg; + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_pre_ctrl_hum_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + control measurement register*/ + pre_ctrl_meas_value = + p_bme280->ctrl_meas_reg; + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &pre_ctrl_meas_value, + BME280_GEN_READ_WRITE_DATA_LENGTH); + } else { + com_rslt = + p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + BME280_CONFIG_REG_SPI3_ENABLE__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + } + /* read the control measurement register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_meas_reg = v_data_u8; + /* read the control humidity register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_hum_reg = v_data_u8; + /* read the control configuration register value*/ + com_rslt += bme280_read_register( + BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->config_reg = v_data_u8; + } + return com_rslt; +} +/*! + * @brief This API is used to reads filter setting + * in the register 0xF5 bit 3 and 4 + * + * + * + * @param v_value_u8 : The value of IIR filter coefficient + * + * value | Filter coefficient + * -------------|------------------------- + * 0x00 | BME280_FILTER_COEFF_OFF + * 0x01 | BME280_FILTER_COEFF_2 + * 0x02 | BME280_FILTER_COEFF_4 + * 0x03 | BME280_FILTER_COEFF_8 + * 0x04 | BME280_FILTER_COEFF_16 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_filter(u8 *v_value_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_CONFIG_REG_FILTER__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + *v_value_u8 = BME280_GET_BITSLICE(v_data_u8, + BME280_CONFIG_REG_FILTER); + } + return com_rslt; +} +/*! + * @brief This API is used to write filter setting + * in the register 0xF5 bit 3 and 4 + * + * + * + * @param v_value_u8 : The value of IIR filter coefficient + * + * value | Filter coefficient + * -------------|------------------------- + * 0x00 | BME280_FILTER_COEFF_OFF + * 0x01 | BME280_FILTER_COEFF_2 + * 0x02 | BME280_FILTER_COEFF_4 + * 0x03 | BME280_FILTER_COEFF_8 + * 0x04 | BME280_FILTER_COEFF_16 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_filter(u8 v_value_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + u8 pre_ctrl_meas_value = BME280_INIT_VALUE; + u8 v_prev_pow_mode_u8 = BME280_INIT_VALUE; + u8 v_pre_ctrl_hum_value_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + v_data_u8 = p_bme280->config_reg; + v_data_u8 = + BME280_SET_BITSLICE(v_data_u8, + BME280_CONFIG_REG_FILTER, v_value_u8); + com_rslt = bme280_get_power_mode(&v_prev_pow_mode_u8); + if (v_prev_pow_mode_u8 != BME280_SLEEP_MODE) { + com_rslt += bme280_set_soft_rst(); + p_bme280->delay_msec(BME280_3MS_DELAY); + /* write previous and updated value of + configuration register*/ + com_rslt += bme280_write_register( + BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + humidity oversampling*/ + v_pre_ctrl_hum_value_u8 = + p_bme280->ctrl_hum_reg; + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_pre_ctrl_hum_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + control measurement register*/ + pre_ctrl_meas_value = + p_bme280->ctrl_meas_reg; + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &pre_ctrl_meas_value, + BME280_GEN_READ_WRITE_DATA_LENGTH); + } else { + com_rslt = + p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + BME280_CONFIG_REG_FILTER__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + } + /* read the control measurement register value*/ + com_rslt += bme280_read_register(BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_meas_reg = v_data_u8; + /* read the control humidity register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_hum_reg = v_data_u8; + /* read the configuration register value*/ + com_rslt += bme280_read_register(BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->config_reg = v_data_u8; + } + return com_rslt; +} +/*! + * @brief This API used to Read the + * standby duration time from the sensor in the register 0xF5 bit 5 to 7 + * + * @param v_standby_durn_u8 : The value of standby duration time value. + * value | standby duration + * -------------|----------------------- + * 0x00 | BME280_STANDBY_TIME_1_MS + * 0x01 | BME280_STANDBY_TIME_63_MS + * 0x02 | BME280_STANDBY_TIME_125_MS + * 0x03 | BME280_STANDBY_TIME_250_MS + * 0x04 | BME280_STANDBY_TIME_500_MS + * 0x05 | BME280_STANDBY_TIME_1000_MS + * 0x06 | BME280_STANDBY_TIME_2000_MS + * 0x07 | BME280_STANDBY_TIME_4000_MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_standby_durn(u8 *v_standby_durn_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + BME280_CONFIG_REG_TSB__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + *v_standby_durn_u8 = BME280_GET_BITSLICE( + v_data_u8, BME280_CONFIG_REG_TSB); + } + return com_rslt; +} +/*! + * @brief This API used to write the + * standby duration time from the sensor in the register 0xF5 bit 5 to 7 + * + * @param v_standby_durn_u8 : The value of standby duration time value. + * value | standby duration + * -------------|----------------------- + * 0x00 | BME280_STANDBY_TIME_1_MS + * 0x01 | BME280_STANDBY_TIME_63_MS + * 0x02 | BME280_STANDBY_TIME_125_MS + * 0x03 | BME280_STANDBY_TIME_250_MS + * 0x04 | BME280_STANDBY_TIME_500_MS + * 0x05 | BME280_STANDBY_TIME_1000_MS + * 0x06 | BME280_STANDBY_TIME_2000_MS + * 0x07 | BME280_STANDBY_TIME_4000_MS + * + * @note Normal mode comprises an automated perpetual + * cycling between an (active) + * Measurement period and an (inactive) standby period. + * @note The standby time is determined by + * the contents of the register t_sb. + * Standby time can be set using BME280_STANDBY_TIME_125_MS. + * + * @note Usage Hint : bme280_set_standby_durn(BME280_STANDBY_TIME_125_MS) + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_standby_durn(u8 v_standby_durn_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + u8 pre_ctrl_meas_value = BME280_INIT_VALUE; + u8 v_prev_pow_mode_u8 = BME280_INIT_VALUE; + u8 v_pre_ctrl_hum_value_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + v_data_u8 = p_bme280->config_reg; + v_data_u8 = + BME280_SET_BITSLICE(v_data_u8, + BME280_CONFIG_REG_TSB, v_standby_durn_u8); + com_rslt = bme280_get_power_mode(&v_prev_pow_mode_u8); + if (v_prev_pow_mode_u8 != BME280_SLEEP_MODE) { + com_rslt += bme280_set_soft_rst(); + p_bme280->delay_msec(BME280_3MS_DELAY); + /* write previous and updated value of + configuration register*/ + com_rslt += bme280_write_register( + BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + humidity oversampling*/ + v_pre_ctrl_hum_value_u8 = + p_bme280->ctrl_hum_reg; + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_pre_ctrl_hum_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of control + measurement register*/ + pre_ctrl_meas_value = + p_bme280->ctrl_meas_reg; + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &pre_ctrl_meas_value, + BME280_GEN_READ_WRITE_DATA_LENGTH); + } else { + com_rslt = + p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + BME280_CONFIG_REG_TSB__REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + } + /* read the control measurement register value*/ + com_rslt += bme280_read_register(BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_meas_reg = v_data_u8; + /* read the control humidity register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_hum_reg = v_data_u8; + /* read the configuration register value*/ + com_rslt += bme280_read_register(BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->config_reg = v_data_u8; + } + return com_rslt; +} +/* + * @brief Writes the working mode to the sensor + * + * + * + * + * @param v_work_mode_u8 : Mode to be set + * value | Working mode + * ----------|-------------------- + * 0 | BME280_ULTRALOWPOWER_MODE + * 1 | BME280_LOWPOWER_MODE + * 2 | BME280_STANDARDRESOLUTION_MODE + * 3 | BME280_HIGHRESOLUTION_MODE + * 4 | BME280_ULTRAHIGHRESOLUTION_MODE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +/*BME280_RETURN_FUNCTION_TYPE bme280_set_work_mode(u8 v_work_mode_u8) +{ +BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; +u8 v_data_u8 = BME280_INIT_VALUE; +if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; +} else { + if (v_work_mode_u8 <= BME280_ULTRAHIGHRESOLUTION_MODE) { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + switch (v_work_mode_u8) { + case BME280_ULTRALOWPOWER_MODE: + p_bme280->oversamp_temperature = + BME280_ULTRALOWPOWER_OSRS_T; + p_bme280->osrs_p = + BME280_ULTRALOWPOWER_OSRS_P; + break; + case BME280_LOWPOWER_MODE: + p_bme280->oversamp_temperature = + BME280_LOWPOWER_OSRS_T; + p_bme280->osrs_p = BME280_LOWPOWER_OSRS_P; + break; + case BME280_STANDARDRESOLUTION_MODE: + p_bme280->oversamp_temperature = + BME280_STANDARDRESOLUTION_OSRS_T; + p_bme280->osrs_p = + BME280_STANDARDRESOLUTION_OSRS_P; + break; + case BME280_HIGHRESOLUTION_MODE: + p_bme280->oversamp_temperature = + BME280_HIGHRESOLUTION_OSRS_T; + p_bme280->osrs_p = BME280_HIGHRESOLUTION_OSRS_P; + break; + case BME280_ULTRAHIGHRESOLUTION_MODE: + p_bme280->oversamp_temperature = + BME280_ULTRAHIGHRESOLUTION_OSRS_T; + p_bme280->osrs_p = + BME280_ULTRAHIGHRESOLUTION_OSRS_P; + break; + } + v_data_u8 = BME280_SET_BITSLICE(v_data_u8, + BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE, + p_bme280->oversamp_temperature); + v_data_u8 = BME280_SET_BITSLICE(v_data_u8, + BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE, + p_bme280->osrs_p); + com_rslt += p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BME280_OUT_OF_RANGE; + } +} +return com_rslt; +}*/ +/*! + * @brief This API used to read uncompensated + * temperature,pressure and humidity in forced mode + * + * + * @param v_uncom_pressure_s32: The value of uncompensated pressure + * @param v_uncom_temperature_s32: The value of uncompensated temperature + * @param v_uncom_humidity_s32: The value of uncompensated humidity + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE +bme280_get_forced_uncomp_pressure_temperature_humidity( +s32 *v_uncom_pressure_s32, +s32 *v_uncom_temperature_s32, s32 *v_uncom_humidity_s32) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + u8 v_data_u8 = BME280_INIT_VALUE; + u8 v_waittime_u8r = BME280_INIT_VALUE; + u8 v_prev_pow_mode_u8 = BME280_INIT_VALUE; + u8 v_mode_u8r = BME280_INIT_VALUE; + u8 pre_ctrl_config_value = BME280_INIT_VALUE; + u8 v_pre_ctrl_hum_value_u8 = BME280_INIT_VALUE; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + v_mode_u8r = p_bme280->ctrl_meas_reg; + v_mode_u8r = + BME280_SET_BITSLICE(v_mode_u8r, + BME280_CTRL_MEAS_REG_POWER_MODE, BME280_FORCED_MODE); + com_rslt = bme280_get_power_mode(&v_prev_pow_mode_u8); + if (v_prev_pow_mode_u8 != BME280_SLEEP_MODE) { + com_rslt += bme280_set_soft_rst(); + p_bme280->delay_msec(BME280_3MS_DELAY); + /* write previous and updated value of + configuration register*/ + pre_ctrl_config_value = p_bme280->config_reg; + com_rslt += bme280_write_register( + BME280_CONFIG_REG, + &pre_ctrl_config_value, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write previous value of + humidity oversampling*/ + v_pre_ctrl_hum_value_u8 = + p_bme280->ctrl_hum_reg; + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_pre_ctrl_hum_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write the force mode */ + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &v_mode_u8r, BME280_GEN_READ_WRITE_DATA_LENGTH); + } else { + /* write previous value of + humidity oversampling*/ + v_pre_ctrl_hum_value_u8 = + p_bme280->ctrl_hum_reg; + com_rslt += bme280_write_register( + BME280_CTRL_HUMIDITY_REG, + &v_pre_ctrl_hum_value_u8, + BME280_GEN_READ_WRITE_DATA_LENGTH); + /* write the force mode */ + com_rslt += bme280_write_register( + BME280_CTRL_MEAS_REG, + &v_mode_u8r, BME280_GEN_READ_WRITE_DATA_LENGTH); + } + bme280_compute_wait_time(&v_waittime_u8r); + p_bme280->delay_msec(v_waittime_u8r); + /* read the force-mode value of pressure + temperature and humidity*/ + com_rslt += + bme280_read_uncomp_pressure_temperature_humidity( + v_uncom_pressure_s32, v_uncom_temperature_s32, + v_uncom_humidity_s32); + + /* read the control humidity register value*/ + com_rslt += bme280_read_register( + BME280_CTRL_HUMIDITY_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_hum_reg = v_data_u8; + /* read the configuration register value*/ + com_rslt += bme280_read_register(BME280_CONFIG_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->config_reg = v_data_u8; + + /* read the control measurement register value*/ + com_rslt += bme280_read_register(BME280_CTRL_MEAS_REG, + &v_data_u8, BME280_GEN_READ_WRITE_DATA_LENGTH); + p_bme280->ctrl_meas_reg = v_data_u8; + } + return com_rslt; +} +/*! + * @brief + * This API write the data to + * the given register + * + * + * @param v_addr_u8 -> Address of the register + * @param v_data_u8 -> The data from the register + * @param v_len_u8 -> no of bytes to read + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BME280_RETURN_FUNCTION_TYPE bme280_write_register(u8 v_addr_u8, +u8 *v_data_u8, u8 v_len_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_WRITE_FUNC( + p_bme280->dev_addr, + v_addr_u8, v_data_u8, v_len_u8); + } + return com_rslt; +} +/*! + * @brief + * This API reads the data from + * the given register + * + * + * @param v_addr_u8 -> Address of the register + * @param v_data_u8 -> The data from the register + * @param v_len_u8 -> no of bytes to read + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BME280_RETURN_FUNCTION_TYPE bme280_read_register(u8 v_addr_u8, +u8 *v_data_u8, u8 v_len_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = ERROR; + /* check the p_bme280 structure pointer as NULL*/ + if (p_bme280 == BME280_NULL) { + return E_BME280_NULL_PTR; + } else { + com_rslt = p_bme280->BME280_BUS_READ_FUNC( + p_bme280->dev_addr, + v_addr_u8, v_data_u8, v_len_u8); + } + return com_rslt; +} +#ifdef BME280_ENABLE_FLOAT +/*! + * @brief Reads actual temperature from uncompensated temperature + * @note returns the value in Degree centigrade + * @note Output value of "51.23" equals 51.23 DegC. + * + * + * + * @param v_uncom_temperature_s32 : value of uncompensated temperature + * + * + * + * @return Return the actual temperature in floating point + * +*/ +double bme280_compensate_temperature_double(s32 v_uncom_temperature_s32) +{ + double v_x1_u32 = BME280_INIT_VALUE; + double v_x2_u32 = BME280_INIT_VALUE; + double temperature = BME280_INIT_VALUE; + + v_x1_u32 = (((double)v_uncom_temperature_s32) / 16384.0 - + ((double)p_bme280->cal_param.dig_T1) / 1024.0) * + ((double)p_bme280->cal_param.dig_T2); + v_x2_u32 = ((((double)v_uncom_temperature_s32) / 131072.0 - + ((double)p_bme280->cal_param.dig_T1) / 8192.0) * + (((double)v_uncom_temperature_s32) / 131072.0 - + ((double)p_bme280->cal_param.dig_T1) / 8192.0)) * + ((double)p_bme280->cal_param.dig_T3); + p_bme280->cal_param.t_fine = (s32)(v_x1_u32 + v_x2_u32); + temperature = (v_x1_u32 + v_x2_u32) / 5120.0; + + + return temperature; +} +/*! + * @brief Reads actual pressure from uncompensated pressure + * @note Returns pressure in Pa as double. + * @note Output value of "96386.2" + * equals 96386.2 Pa = 963.862 hPa. + * + * + * @param v_uncom_pressure_s32 : value of uncompensated pressure + * + * + * @return Return the actual pressure in floating point + * +*/ +double bme280_compensate_pressure_double(s32 v_uncom_pressure_s32) +{ + double v_x1_u32 = BME280_INIT_VALUE; + double v_x2_u32 = BME280_INIT_VALUE; + double pressure = BME280_INIT_VALUE; + + v_x1_u32 = ((double)p_bme280->cal_param.t_fine / + 2.0) - 64000.0; + v_x2_u32 = v_x1_u32 * v_x1_u32 * + ((double)p_bme280->cal_param.dig_P6) / 32768.0; + v_x2_u32 = v_x2_u32 + v_x1_u32 * + ((double)p_bme280->cal_param.dig_P5) * 2.0; + v_x2_u32 = (v_x2_u32 / 4.0) + + (((double)p_bme280->cal_param.dig_P4) * 65536.0); + v_x1_u32 = (((double)p_bme280->cal_param.dig_P3) * + v_x1_u32 * v_x1_u32 / 524288.0 + + ((double)p_bme280->cal_param.dig_P2) * v_x1_u32) / 524288.0; + v_x1_u32 = (1.0 + v_x1_u32 / 32768.0) * + ((double)p_bme280->cal_param.dig_P1); + pressure = 1048576.0 - (double)v_uncom_pressure_s32; + /* Avoid exception caused by division by zero */ + if (v_x1_u32 != BME280_INIT_VALUE) + pressure = (pressure - (v_x2_u32 / 4096.0)) * 6250.0 / v_x1_u32; + else + return BME280_INVALID_DATA; + v_x1_u32 = ((double)p_bme280->cal_param.dig_P9) * + pressure * pressure / 2147483648.0; + v_x2_u32 = pressure * ((double)p_bme280->cal_param.dig_P8) / 32768.0; + pressure = pressure + (v_x1_u32 + v_x2_u32 + + ((double)p_bme280->cal_param.dig_P7)) / 16.0; + + return pressure; +} +/*! + * @brief Reads actual humidity from uncompensated humidity + * @note returns the value in relative humidity (%rH) + * @note Output value of "42.12" equals 42.12 %rH + * + * @param v_uncom_humidity_s32 : value of uncompensated humidity + * + * + * + * @return Return the actual humidity in floating point + * +*/ +double bme280_compensate_humidity_double(s32 v_uncom_humidity_s32) +{ + double var_h = BME280_INIT_VALUE; + + var_h = (((double)p_bme280->cal_param.t_fine) - 76800.0); + if (var_h != BME280_INIT_VALUE) + var_h = (v_uncom_humidity_s32 - + (((double)p_bme280->cal_param.dig_H4) * 64.0 + + ((double)p_bme280->cal_param.dig_H5) / 16384.0 * var_h))* + (((double)p_bme280->cal_param.dig_H2) / 65536.0 * + (1.0 + ((double) p_bme280->cal_param.dig_H6) + / 67108864.0 * var_h * (1.0 + ((double) + p_bme280->cal_param.dig_H3) / 67108864.0 * var_h))); + else + return BME280_INVALID_DATA; + var_h = var_h * (1.0 - ((double) + p_bme280->cal_param.dig_H1)*var_h / 524288.0); + if (var_h > 100.0) + var_h = 100.0; + else if (var_h < 0.0) + var_h = 0.0; + return var_h; + +} +#endif +#if defined(BME280_ENABLE_INT64) && defined(BME280_64BITSUPPORT_PRESENT) +/*! + * @brief Reads actual pressure from uncompensated pressure + * @note Returns the value in Pa as unsigned 32 bit + * integer in Q24.8 format (24 integer bits and + * 8 fractional bits). + * @note Output value of "24674867" + * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa + * + * + * + * @param v_uncom_pressure_s32 : value of uncompensated temperature + * + * + * @return Return the actual pressure in u32 + * +*/ +u32 bme280_compensate_pressure_int64(s32 v_uncom_pressure_s32) +{ + s64 v_x1_s64r = BME280_INIT_VALUE; + s64 v_x2_s64r = BME280_INIT_VALUE; + s64 pressure = BME280_INIT_VALUE; + + v_x1_s64r = ((s64)p_bme280->cal_param.t_fine) + - 128000; + v_x2_s64r = v_x1_s64r * v_x1_s64r * + (s64)p_bme280->cal_param.dig_P6; + v_x2_s64r = v_x2_s64r + ((v_x1_s64r * + (s64)p_bme280->cal_param.dig_P5) + << BME280_SHIFT_BIT_POSITION_BY_17_BITS); + v_x2_s64r = v_x2_s64r + + (((s64)p_bme280->cal_param.dig_P4) + << BME280_SHIFT_BIT_POSITION_BY_35_BITS); + v_x1_s64r = ((v_x1_s64r * v_x1_s64r * + (s64)p_bme280->cal_param.dig_P3) + >> BME280_SHIFT_BIT_POSITION_BY_08_BITS) + + ((v_x1_s64r * (s64)p_bme280->cal_param.dig_P2) + << BME280_SHIFT_BIT_POSITION_BY_12_BITS); + v_x1_s64r = (((((s64)1) + << BME280_SHIFT_BIT_POSITION_BY_47_BITS) + v_x1_s64r)) * + ((s64)p_bme280->cal_param.dig_P1) + >> BME280_SHIFT_BIT_POSITION_BY_33_BITS; + pressure = 1048576 - v_uncom_pressure_s32; + /* Avoid exception caused by division by zero */ + if (v_x1_s64r != BME280_INIT_VALUE) + #if defined __KERNEL__ + pressure = div64_s64((((pressure + << BME280_SHIFT_BIT_POSITION_BY_31_BITS) - v_x2_s64r) + * 3125), v_x1_s64r); + #else + pressure = (((pressure + << BME280_SHIFT_BIT_POSITION_BY_31_BITS) - v_x2_s64r) + * 3125) / v_x1_s64r; + #endif + else + return BME280_INVALID_DATA; + v_x1_s64r = (((s64)p_bme280->cal_param.dig_P9) * + (pressure >> BME280_SHIFT_BIT_POSITION_BY_13_BITS) * + (pressure >> BME280_SHIFT_BIT_POSITION_BY_13_BITS)) + >> BME280_SHIFT_BIT_POSITION_BY_25_BITS; + v_x2_s64r = (((s64)p_bme280->cal_param.dig_P8) * + pressure) >> BME280_SHIFT_BIT_POSITION_BY_19_BITS; + pressure = (((pressure + v_x1_s64r + + v_x2_s64r) >> BME280_SHIFT_BIT_POSITION_BY_08_BITS) + + (((s64)p_bme280->cal_param.dig_P7) + << BME280_SHIFT_BIT_POSITION_BY_04_BITS)); + + return (u32)pressure; +} +/*! + * @brief Reads actual pressure from uncompensated pressure + * @note Returns the value in Pa. + * @note Output value of "12337434" + * @note represents 12337434 / 128 = 96386.2 Pa = 963.862 hPa + * + * + * + * @param v_uncom_pressure_s32 : value of uncompensated pressure + * + * + * @return the actual pressure in u32 + * +*/ +u32 bme280_compensate_pressure_int64_twentyfour_bit_output( +s32 v_uncom_pressure_s32) +{ + u32 pressure = BME280_INIT_VALUE; + + pressure = bme280_compensate_pressure_int64( + v_uncom_pressure_s32); + pressure = (u32)(pressure >> BME280_SHIFT_BIT_POSITION_BY_01_BIT); + return pressure; +} +#endif +/*! + * @brief Computing waiting time for sensor data read + * + * + * + * + * @param v_delaytime_u8 : The value of delay time for force mode + * + * + * @retval 0 -> Success + * + * + */ +BME280_RETURN_FUNCTION_TYPE bme280_compute_wait_time(u8 +*v_delaytime_u8) +{ + /* used to return the communication result*/ + BME280_RETURN_FUNCTION_TYPE com_rslt = SUCCESS; + + *v_delaytime_u8 = (T_INIT_MAX + + T_MEASURE_PER_OSRS_MAX * + (((1 << + p_bme280->oversamp_temperature) + >> BME280_SHIFT_BIT_POSITION_BY_01_BIT) + + ((1 << p_bme280->oversamp_pressure) + >> BME280_SHIFT_BIT_POSITION_BY_01_BIT) + + ((1 << p_bme280->oversamp_humidity) + >> BME280_SHIFT_BIT_POSITION_BY_01_BIT)) + + (p_bme280->oversamp_pressure ? + T_SETUP_PRESSURE_MAX : 0) + + (p_bme280->oversamp_humidity ? + T_SETUP_HUMIDITY_MAX : 0) + 15) / 16; + return com_rslt; +} diff --git a/app/src/main/jni/bme280.h b/app/src/main/jni/bme280.h new file mode 100644 index 0000000..49817ab --- /dev/null +++ b/app/src/main/jni/bme280.h @@ -0,0 +1,1704 @@ +/** \mainpage +* +**************************************************************************** +* Copyright (C) 2013 - 2015 Bosch Sensortec GmbH +* +* File : bme280.h +* +* Date : 2015/03/27 +* +* Revision : 2.0.4(Pressure and Temperature compensation code revision is 1.1 +* and Humidity compensation code revision is 1.0) +* +* Usage: Sensor Driver for BME280 sensor +* +**************************************************************************** +* +* \section License +* +* 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 the +* 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 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 +* +* The information provided is believed to be accurate and reliable. +* The copyright holder assumes no responsibility +* for the consequences of use +* of such information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of the copyright holder. +**************************************************************************/ +/*! \file bme280.h + \brief BME280 Sensor Driver Support Header File */ +#ifndef __BME280_H__ +#define __BME280_H__ + + +/*! +* @brief The following definition uses for define the data types +* +* @note While porting the API please consider the following +* @note Please check the version of C standard +* @note Are you using Linux platform +*/ + +/*! +* @brief For the Linux platform support +* Please use the types.h for your data types definitions +*/ +#ifdef __KERNEL__ + +#include +#include +#define BME280_64BITSUPPORT_PRESENT +/* singed integer type*/ +typedef int8_t s8;/**< used for signed 8bit */ +typedef int16_t s16;/**< used for signed 16bit */ +typedef int32_t s32;/**< used for signed 32bit */ +typedef int64_t s64;/**< used for signed 64bit */ + +typedef u_int8_t u8;/**< used for unsigned 8bit */ +typedef u_int16_t u16;/**< used for unsigned 16bit */ +typedef u_int32_t u32;/**< used for unsigned 32bit */ +typedef u_int64_t u64;/**< used for unsigned 64bit */ + + + +#else /* ! __KERNEL__ */ +/********************************************************** +* These definition uses for define the C +* standard version data types +***********************************************************/ +# if !defined(__STDC_VERSION__) + +/************************************************ + * compiler is C11 C standard +************************************************/ +#if (__STDC_VERSION__ == 201112L) + +/************************************************/ +#include +/************************************************/ + +/*unsigned integer types*/ +typedef uint8_t u8;/**< used for unsigned 8bit */ +typedef uint16_t u16;/**< used for unsigned 16bit */ +typedef uint32_t u32;/**< used for unsigned 32bit */ +typedef uint64_t u64;/**< used for unsigned 64bit */ + +/*signed integer types*/ +typedef int8_t s8;/**< used for signed 8bit */ +typedef int16_t s16;/**< used for signed 16bit */ +typedef int32_t s32;/**< used for signed 32bit */ +typedef int64_t s64;/**< used for signed 64bit */ +#define BME280_64BITSUPPORT_PRESENT +/************************************************ + * compiler is C99 C standard +************************************************/ + +#elif (__STDC_VERSION__ == 199901L) + +/* stdint.h is a C99 supported c library. +which is used to fixed the integer size*/ +/************************************************/ +#include +/************************************************/ + +/*unsigned integer types*/ +typedef uint8_t u8;/**< used for unsigned 8bit */ +typedef uint16_t u16;/**< used for unsigned 16bit */ +typedef uint32_t u32;/**< used for unsigned 32bit */ +typedef uint64_t u64;/**< used for unsigned 64bit */ + +/*signed integer types*/ +typedef int8_t s8;/**< used for signed 8bit */ +typedef int16_t s16;/**< used for signed 16bit */ +typedef int32_t s32;/**< used for signed 32bit */ +typedef int64_t s64;/**< used for signed 64bit */ +#define BME280_64BITSUPPORT_PRESENT +/************************************************ + * compiler is C89 or other C standard +************************************************/ + +#else /* !defined(__STDC_VERSION__) */ +/*! +* @brief By default it is defined as 32 bit machine configuration +* define your data types based on your +* machine/compiler/controller configuration +*/ +#define MACHINE_32_BIT + +/*! @brief + * If your machine support 16 bit + * define the MACHINE_16_BIT + */ +#ifdef MACHINE_16_BIT +#include +/*signed integer types*/ +typedef signed char s8;/**< used for signed 8bit */ +typedef signed short int s16;/**< used for signed 16bit */ +typedef signed long int s32;/**< used for signed 32bit */ + +#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL +typedef long int s64;/**< used for signed 64bit */ +typedef unsigned long int u64;/**< used for unsigned 64bit */ +#define BME280_64BITSUPPORT_PRESENT +#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) +typedef long long int s64;/**< used for signed 64bit */ +typedef unsigned long long int u64;/**< used for unsigned 64bit */ +#define BME280_64BITSUPPORT_PRESENT +#else +#warning Either the correct data type for signed 64 bit integer \ +could not be found, or 64 bit integers are not supported in your environment. +#warning The API will only offer 32 bit pressure calculation.This will \ +slightly impede accuracy(noise of ~1 pascal RMS will be added to output). +#warning If 64 bit integers are supported on your platform, \ +please set s64 manually and "#define(BMPE80_64BITSUPPORT_PRESENT)" manually. +#endif + +/*unsigned integer types*/ +typedef unsigned char u8;/**< used for unsigned 8bit */ +typedef unsigned short int u16;/**< used for unsigned 16bit */ +typedef unsigned long int u32;/**< used for unsigned 32bit */ + +/* If your machine support 32 bit +define the MACHINE_32_BIT*/ +#elif defined MACHINE_32_BIT +/*signed integer types*/ +typedef signed char s8;/**< used for signed 8bit */ +typedef signed short int s16;/**< used for signed 16bit */ +typedef signed int s32;/**< used for signed 32bit */ +typedef signed long long int s64;/**< used for signed 64bit */ + +/*unsigned integer types*/ +typedef unsigned char u8;/**< used for unsigned 8bit */ +typedef unsigned short int u16;/**< used for unsigned 16bit */ +typedef unsigned int u32;/**< used for unsigned 32bit */ +typedef unsigned long long int u64;/**< used for unsigned 64bit */ +/*! @brief + * If your machine support 64 bit + * define the MACHINE_64_BIT + */ +#define BME280_64BITSUPPORT_PRESENT + +/* If your machine support 64 bit +define the MACHINE_64_BIT*/ +#elif defined MACHINE_64_BIT +/*signed integer types*/ +typedef signed char s8;/**< used for signed 8bit */ +typedef signed short int s16;/**< used for signed 16bit */ +typedef signed int s32;/**< used for signed 32bit */ +typedef signed long int s64;/**< used for signed 64bit */ + +/*unsigned integer types*/ +typedef unsigned char u8;/**< used for unsigned 8bit */ +typedef unsigned short int u16;/**< used for unsigned 16bit */ +typedef unsigned int u32;/**< used for unsigned 32bit */ +typedef unsigned long int u64;/**< used for unsigned 64bit */ +#define BME280_64BITSUPPORT_PRESENT + +#else +#warning The data types defined above which not supported \ +define the data types manually +#endif +#endif + +/*** This else will execute for the compilers + * which are not supported the C standards + * Like C89/C99/C11***/ +#else +/*! +* @brief By default it is defined as 32 bit machine configuration +* define your data types based on your +* machine/compiler/controller configuration +*/ +#define MACHINE_32_BIT + +/* If your machine support 16 bit +define the MACHINE_16_BIT*/ +#ifdef MACHINE_16_BIT +#include +/*signed integer types*/ +typedef signed char s8;/**< used for signed 8bit */ +typedef signed short int s16;/**< used for signed 16bit */ +typedef signed long int s32;/**< used for signed 32bit */ + +#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL +typedef long int s64;/**< used for signed 64bit */ +typedef unsigned long int u64;/**< used for unsigned 64bit */ +#define BME280_64BITSUPPORT_PRESENT +#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) +typedef long long int s64;/**< used for signed 64bit */ +typedef unsigned long long int u64;/**< used for unsigned 64bit */ +#define BME280_64BITSUPPORT_PRESENT +#else +#warning Either the correct data type for signed 64 bit integer \ +could not be found, or 64 bit integers are not supported in your environment. +#warning The API will only offer 32 bit pressure calculation.This will \ +slightly impede accuracy(noise of ~1 pascal RMS will be added to output). +#warning If 64 bit integers are supported on your platform, \ +please set s64 manually and "#define(BME280_64BITSUPPORT_PRESENT)" manually. +#endif + +/*unsigned integer types*/ +typedef unsigned char u8;/**< used for unsigned 8bit */ +typedef unsigned short int u16;/**< used for unsigned 16bit */ +typedef unsigned long int u32;/**< used for unsigned 32bit */ + +/*! @brief If your machine support 32 bit +define the MACHINE_32_BIT*/ +#elif defined MACHINE_32_BIT +/*signed integer types*/ +typedef signed char s8;/**< used for signed 8bit */ +typedef signed short int s16;/**< used for signed 16bit */ +typedef signed int s32;/**< used for signed 32bit */ +typedef signed long long int s64;/**< used for signed 64bit */ + +/*unsigned integer types*/ +typedef unsigned char u8;/**< used for unsigned 8bit */ +typedef unsigned short int u16;/**< used for unsigned 16bit */ +typedef unsigned int u32;/**< used for unsigned 32bit */ +typedef unsigned long long int u64;/**< used for unsigned 64bit */ +#define BME280_64BITSUPPORT_PRESENT + +/* If your machine support 64 bit +define the MACHINE_64_BIT*/ +#elif defined MACHINE_64_BIT +/*signed integer types*/ +typedef signed char s8;/**< used for signed 8bit */ +typedef signed short int s16;/**< used for signed 16bit */ +typedef signed int s32;/**< used for signed 32bit */ +typedef signed long int s64;/**< used for signed 64bit */ + +/*unsigned integer types*/ +typedef unsigned char u8;/**< used for unsigned 8bit */ +typedef unsigned short int u16;/**< used for unsigned 16bit */ +typedef unsigned int u32;/**< used for unsigned 32bit */ +typedef unsigned long int u64;/**< used for unsigned 64bit */ +#define BME280_64BITSUPPORT_PRESENT + +#else +#warning The data types defined above which not supported \ +define the data types manually +#endif +#endif +#endif +/********************************************/ +/**\name ENABLE FLATING OUTPUT */ +/**************************************/ +/*! +* @brief If the user wants to support floating point calculations, please set + the following define. If floating point + calculation is not wanted or allowed + (e.g. in Linux kernel), please do not set the define. */ +#define BME280_ENABLE_FLOAT +/*! +* @brief If the user wants to support 64 bit integer calculation + (needed for optimal pressure accuracy) please set + the following define. If int64 calculation is not wanted + (e.g. because it would include + large libraries), please do not set the define. */ +#define BME280_ENABLE_INT64 +/***************************************************************/ +/**\name BUS READ AND WRITE FUNCTION POINTERS */ +/***************************************************************/ +/*! + @brief Define the calling convention of YOUR bus communication routine. + @note This includes types of parameters. This example shows the + configuration for an SPI bus link. + + If your communication function looks like this: + + write_my_bus_xy(u8 device_addr, u8 register_addr, + u8 * data, u8 length); + + The BME280_WR_FUNC_PTR would equal: + + BME280_WR_FUNC_PTR s8 (* bus_write)(u8, + u8, u8 *, u8) + + Parameters can be mixed as needed refer to the + refer BME280_BUS_WRITE_FUNC macro. + + +*/ +/** defines the return parameter type of the BME280_WR_FUNCTION */ +#define BME280_BUS_WR_RETURN_TYPE s8 + +/* links the order of parameters defined in +BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ +#define BME280_BUS_WR_PARAM_TYPES u8, u8,\ + u8 *, u8 + +/* links the order of parameters defined in +BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ +#define BME280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\ + register_data, wr_len) + +/* never change this line */ +#define BME280_BUS_WRITE_FUNC(device_addr, register_addr,\ +register_data, wr_len) bus_write(device_addr, register_addr,\ + register_data, wr_len) +/*! + @brief link macro between API function calls and bus read function + @note The bus write function can change since this is a + system dependant issue. + + If the bus_read parameter calling order is like: reg_addr, + reg_data, wr_len it would be as it is here. + + If the parameters are differently ordered or your communication + function like I2C need to know the device address, + you can change this macro accordingly. + + + BME280_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ + bus_read(dev_addr, reg_addr, reg_data, wr_len) + + This macro lets all API functions call YOUR communication routine in a + way that equals your definition in the + refer BME280_WR_FUNC_PTR definition. + + @note: this macro also includes the "MSB='1' + for reading BME280 addresses. + +*/ +/*defines the return parameter type of the BME280_RD_FUNCTION +*/ +#define BME280_BUS_RD_RETURN_TYPE s8 + +/**\brief defines the calling parameter types of the BME280_RD_FUNCTION +*/ +#define BME280_BUS_RD_PARAM_TYPES (u8, u8,\ + u8 *, u8) + +/* links the order of parameters defined in \ +BME280_BUS_RD_PARAM_TYPE to function calls used inside the API +*/ +#define BME280_BUS_RD_PARAM_ORDER (device_addr, register_addr,\ + register_data) + +/* never change this line */ +#define BME280_BUS_READ_FUNC(device_addr, register_addr,\ + register_data, rd_len)bus_read(device_addr, register_addr,\ + register_data, rd_len) +/****************************************/ +/**\name DELAY */ +/****************************************/ +/* defines the return parameter type of the BME280_DELAY_FUNCTION +*/ +#define BME280_DELAY_RETURN_TYPE void + +/* defines the calling parameter types of the BME280_DELAY_FUNCTION +*/ +#define BME280_DELAY_PARAM_TYPES u16 +/***************************************************************/ +/**\name GET AND SET BITSLICE FUNCTIONS */ +/***************************************************************/ +/* never change this line */ +#define BME280_DELAY_FUNC(delay_in_msec)\ + delay_func(delay_in_msec) + +#define BME280_GET_BITSLICE(regvar, bitname)\ + ((regvar & bitname##__MSK) >> bitname##__POS) + +#define BME280_SET_BITSLICE(regvar, bitname, val)\ +((regvar & ~bitname##__MSK) | ((val< Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_init(struct bme280_t *bme280); +/**************************************************************/ +/**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED TEMPERATURE */ +/**************************************************************/ +/*! + * @brief This API is used to read uncompensated temperature + * in the registers 0xFA, 0xFB and 0xFC + * @note 0xFA -> MSB -> bit from 0 to 7 + * @note 0xFB -> LSB -> bit from 0 to 7 + * @note 0xFC -> LSB -> bit from 4 to 7 + * + * @param v_uncomp_temperature_s32 : The value of uncompensated temperature + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_temperature( +s32 *v_uncomp_temperature_s32); +/**************************************************************/ +/**\name FUNCTION FOR INTIALIZATION TRUE TEMPERATURE */ +/**************************************************************/ +/*! + * @brief Reads actual temperature from uncompensated temperature + * @note Returns the value in 0.01 degree Centigrade + * Output value of "5123" equals 51.23 DegC. + * + * + * + * @param v_uncomp_temperature_s32 : value of uncompensated temperature + * + * + * @return Returns the actual temperature + * +*/ +s32 bme280_compensate_temperature_int32(s32 v_uncomp_temperature_s32); +/*! + * @brief Reads actual temperature from uncompensated temperature + * @note Returns the value with 500LSB/DegC centred around 24 DegC + * output value of "5123" equals(5123/500)+24 = 34.246DegC + * + * + * @param v_uncomp_temperature_s32: value of uncompensated temperature + * + * + * + * @return Return the actual temperature as s16 output + * +*/ +s16 bme280_compensate_temperature_int32_sixteen_bit_output( +s32 v_uncomp_temperature_s32); +/**************************************************************/ +/**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED PRESSURE */ +/**************************************************************/ +/*! + * @brief This API is used to read uncompensated pressure. + * in the registers 0xF7, 0xF8 and 0xF9 + * @note 0xF7 -> MSB -> bit from 0 to 7 + * @note 0xF8 -> LSB -> bit from 0 to 7 + * @note 0xF9 -> LSB -> bit from 4 to 7 + * + * + * + * @param v_uncomp_pressure_s32 : The value of uncompensated pressure + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure( +s32 *v_uncomp_pressure_s32); +/**************************************************************/ +/**\name FUNCTION FOR INTIALIZATION TRUE PRESSURE */ +/**************************************************************/ +/*! + * @brief Reads actual pressure from uncompensated pressure + * @note Returns the value in Pascal(Pa) + * Output value of "96386" equals 96386 Pa = + * 963.86 hPa = 963.86 millibar + * + * + * + * @param v_uncomp_pressure_s32 : value of uncompensated pressure + * + * + * + * @return Return the actual pressure output as u32 + * +*/ +u32 bme280_compensate_pressure_int32(s32 v_uncomp_pressure_s32); +/**************************************************************/ +/**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED HUMIDITY */ +/**************************************************************/ +/*! + * @brief This API is used to read uncompensated humidity. + * in the registers 0xF7, 0xF8 and 0xF9 + * @note 0xFD -> MSB -> bit from 0 to 7 + * @note 0xFE -> LSB -> bit from 0 to 7 + * + * + * + * @param v_uncomp_humidity_s32 : The value of uncompensated humidity + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_humidity( +s32 *v_uncomp_humidity_s32); +/**************************************************************/ +/**\name FUNCTION FOR INTIALIZATION RELATIVE HUMIDITY */ +/**************************************************************/ +/*! + * @brief Reads actual humidity from uncompensated humidity + * @note Returns the value in %rH as unsigned 32bit integer + * in Q22.10 format(22 integer 10 fractional bits). + * @note An output value of 42313 + * represents 42313 / 1024 = 41.321 %rH + * + * + * + * @param v_uncomp_humidity_s32: value of uncompensated humidity + * + * @return Return the actual relative humidity output as u32 + * +*/ +u32 bme280_compensate_humidity_int32(s32 v_uncomp_humidity_s32); +/*! + * @brief Reads actual humidity from uncompensated humidity + * @note Returns the value in %rH as unsigned 16bit integer + * @note An output value of 42313 + * represents 42313/512 = 82.643 %rH + * + * + * + * @param v_uncomp_humidity_s32: value of uncompensated humidity + * + * + * @return Return the actual relative humidity output as u16 + * +*/ +u16 bme280_compensate_humidity_int32_sixteen_bit_output( +s32 v_uncomp_humidity_s32); +/**************************************************************/ +/**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED PRESSURE, + TEMPERATURE AND HUMIDITY */ +/**************************************************************/ +/*! + * @brief This API used to read uncompensated + * pressure,temperature and humidity + * + * + * + * + * @param v_uncomp_pressure_s32: The value of uncompensated pressure. + * @param v_uncomp_temperature_s32: The value of uncompensated temperature + * @param v_uncomp_humidity_s32: The value of uncompensated humidity. + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure_temperature_humidity( +s32 *v_uncomp_pressure_s32, +s32 *v_uncomp_temperature_s32, s32 *v_uncomp_humidity_s32); +/**************************************************************/ +/**\name FUNCTION FOR TRUE UNCOMPENSATED PRESSURE, + TEMPERATURE AND HUMIDITY */ +/**************************************************************/ +/*! + * @brief This API used to read true pressure, temperature and humidity + * + * + * + * + * @param v_pressure_u32 : The value of compensated pressure. + * @param v_temperature_s32 : The value of compensated temperature. + * @param v_humidity_u32 : The value of compensated humidity. + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_read_pressure_temperature_humidity( +u32 *v_pressure_u32, s32 *v_temperature_s32, u32 *v_humidity_u32); +/**************************************************************/ +/**\name FUNCTION FOR CALIBRATION */ +/**************************************************************/ +/*! + * @brief This API is used to + * calibration parameters used for calculation in the registers + * + * parameter | Register address | bit + *------------|------------------|---------------- + * dig_T1 | 0x88 and 0x89 | from 0 : 7 to 8: 15 + * dig_T2 | 0x8A and 0x8B | from 0 : 7 to 8: 15 + * dig_T3 | 0x8C and 0x8D | from 0 : 7 to 8: 15 + * dig_P1 | 0x8E and 0x8F | from 0 : 7 to 8: 15 + * dig_P2 | 0x90 and 0x91 | from 0 : 7 to 8: 15 + * dig_P3 | 0x92 and 0x93 | from 0 : 7 to 8: 15 + * dig_P4 | 0x94 and 0x95 | from 0 : 7 to 8: 15 + * dig_P5 | 0x96 and 0x97 | from 0 : 7 to 8: 15 + * dig_P6 | 0x98 and 0x99 | from 0 : 7 to 8: 15 + * dig_P7 | 0x9A and 0x9B | from 0 : 7 to 8: 15 + * dig_P8 | 0x9C and 0x9D | from 0 : 7 to 8: 15 + * dig_P9 | 0x9E and 0x9F | from 0 : 7 to 8: 15 + * dig_H1 | 0xA1 | from 0 to 7 + * dig_H2 | 0xE1 and 0xE2 | from 0 : 7 to 8: 15 + * dig_H3 | 0xE3 | from 0 to 7 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_calib_param(void); +/**************************************************************/ +/**\name FUNCTION FOR TEMPERATURE OVER SAMPLING */ +/**************************************************************/ +/*! + * @brief This API is used to get + * the temperature oversampling setting in the register 0xF4 + * bits from 5 to 7 + * + * value | Temperature oversampling + * ---------------------|--------------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of temperature over sampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_temperature( +u8 *v_value_u8); +/*! + * @brief This API is used to set + * the temperature oversampling setting in the register 0xF4 + * bits from 5 to 7 + * + * value | Temperature oversampling + * ---------------------|--------------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of temperature over sampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_temperature( +u8 v_value_u8); +/**************************************************************/ +/**\name FUNCTION FOR PRESSURE OVER SAMPLING */ +/**************************************************************/ +/*! + * @brief This API is used to get + * the pressure oversampling setting in the register 0xF4 + * bits from 2 to 4 + * + * value | Pressure oversampling + * --------------------|-------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of pressure oversampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_pressure( +u8 *v_value_u8); +/*! + * @brief This API is used to set + * the pressure oversampling setting in the register 0xF4 + * bits from 2 to 4 + * + * value | Pressure oversampling + * --------------------|-------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of pressure oversampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_pressure( +u8 v_value_u8); +/**************************************************************/ +/**\name FUNCTION FOR HUMIDITY OVER SAMPLING */ +/**************************************************************/ +/*! + * @brief This API is used to get + * the humidity oversampling setting in the register 0xF2 + * bits from 0 to 2 + * + * value | Humidity oversampling + * ---------------------|------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of humidity over sampling + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_humidity(u8 *v_value_u8); +/*! + * @brief This API is used to set + * the humidity oversampling setting in the register 0xF2 + * bits from 0 to 2 + * + * value | Humidity oversampling + * ---------------------|------------------------- + * 0x00 | Skipped + * 0x01 | BME280_OVERSAMP_1X + * 0x02 | BME280_OVERSAMP_2X + * 0x03 | BME280_OVERSAMP_4X + * 0x04 | BME280_OVERSAMP_8X + * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X + * + * + * @param v_value_u8 : The value of humidity over sampling + * + * + * + * @note The "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" + * register sets the humidity + * data acquisition options of the device. + * @note changes to this registers only become + * effective after a write operation to + * "BME280_CTRL_MEAS_REG" register. + * @note In the code automated reading and writing of + * "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" + * @note register first set the + * "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" + * and then read and write + * the "BME280_CTRL_MEAS_REG" register in the function. + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_humidity( +u8 v_value_u8); +/**************************************************************/ +/**\name FUNCTION FOR POWER MODE*/ +/**************************************************************/ +/*! + * @brief This API used to get the + * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 + * + * + * + * @param v_power_mode_u8 : The value of power mode + * value | mode + * -----------------|------------------ + * 0x00 | BME280_SLEEP_MODE + * 0x01 and 0x02 | BME280_FORCED_MODE + * 0x03 | BME280_NORMAL_MODE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_power_mode(u8 *v_power_mode_u8); +/*! + * @brief This API used to set the + * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 + * + * + * + * @param v_power_mode_u8 : The value of power mode + * value | mode + * -----------------|------------------ + * 0x00 | BME280_SLEEP_MODE + * 0x01 and 0x02 | BME280_FORCED_MODE + * 0x03 | BME280_NORMAL_MODE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_power_mode(u8 v_power_mode_u8); +/**************************************************************/ +/**\name FUNCTION FOR SOFT RESET*/ +/**************************************************************/ +/*! + * @brief Used to reset the sensor + * The value 0xB6 is written to the 0xE0 + * register the device is reset using the + * complete power-on-reset procedure. + * @note Soft reset can be easily set using bme280_set_softreset(). + * @note Usage Hint : bme280_set_softreset() + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_soft_rst(void); +/**************************************************************/ +/**\name FUNCTION FOR SPI ENABLE*/ +/**************************************************************/ +/*! + * @brief This API used to get the sensor + * SPI mode(communication type) in the register 0xF5 bit 0 + * + * + * + * @param v_enable_disable_u8 : The value of SPI enable + * value | Description + * --------|-------------- + * 0 | Disable + * 1 | Enable + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_spi3(u8 *v_enable_disable_u8); +/*! + * @brief This API used to set the sensor + * SPI mode(communication type) in the register 0xF5 bit 0 + * + * + * + * @param v_enable_disable_u8 : The value of SPI enable + * value | Description + * --------|-------------- + * 0 | Disable + * 1 | Enable + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_spi3(u8 v_enable_disable_u8); +/**************************************************************/ +/**\name FUNCTION FOR IIR FILTER*/ +/**************************************************************/ +/*! + * @brief This API is used to reads filter setting + * in the register 0xF5 bit 3 and 4 + * + * + * + * @param v_value_u8 : The value of IIR filter coefficient + * + * value | Filter coefficient + * -------------|------------------------- + * 0x00 | BME280_FILTER_COEFF_OFF + * 0x01 | BME280_FILTER_COEFF_2 + * 0x02 | BME280_FILTER_COEFF_4 + * 0x03 | BME280_FILTER_COEFF_8 + * 0x04 | BME280_FILTER_COEFF_16 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_filter(u8 *v_value_u8); +/*! + * @brief This API is used to write filter setting + * in the register 0xF5 bit 3 and 4 + * + * + * + * @param v_value_u8 : The value of IIR filter coefficient + * + * value | Filter coefficient + * -------------|------------------------- + * 0x00 | BME280_FILTER_COEFF_OFF + * 0x01 | BME280_FILTER_COEFF_2 + * 0x02 | BME280_FILTER_COEFF_4 + * 0x03 | BME280_FILTER_COEFF_8 + * 0x04 | BME280_FILTER_COEFF_16 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_filter(u8 v_value_u8); +/**************************************************************/ +/**\name FUNCTION FOR STANDBY DURATION*/ +/**************************************************************/ +/*! + * @brief This API used to Read the + * standby duration time from the sensor in the register 0xF5 bit 5 to 7 + * + * @param v_standby_durn_u8 : The value of standby duration time value. + * value | standby duration + * -------------|----------------------- + * 0x00 | BME280_STANDBY_TIME_1_MS + * 0x01 | BME280_STANDBY_TIME_63_MS + * 0x02 | BME280_STANDBY_TIME_125_MS + * 0x03 | BME280_STANDBY_TIME_250_MS + * 0x04 | BME280_STANDBY_TIME_500_MS + * 0x05 | BME280_STANDBY_TIME_1000_MS + * 0x06 | BME280_STANDBY_TIME_2000_MS + * 0x07 | BME280_STANDBY_TIME_4000_MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_get_standby_durn(u8 *v_standby_durn_u8); +/*! + * @brief This API used to write the + * standby duration time from the sensor in the register 0xF5 bit 5 to 7 + * + * @param v_standby_durn_u8 : The value of standby duration time value. + * value | standby duration + * -------------|----------------------- + * 0x00 | BME280_STANDBY_TIME_1_MS + * 0x01 | BME280_STANDBY_TIME_63_MS + * 0x02 | BME280_STANDBY_TIME_125_MS + * 0x03 | BME280_STANDBY_TIME_250_MS + * 0x04 | BME280_STANDBY_TIME_500_MS + * 0x05 | BME280_STANDBY_TIME_1000_MS + * 0x06 | BME280_STANDBY_TIME_2000_MS + * 0x07 | BME280_STANDBY_TIME_4000_MS + * + * @note Normal mode comprises an automated perpetual + * cycling between an (active) + * Measurement period and an (inactive) standby period. + * @note The standby time is determined by + * the contents of the register t_sb. + * Standby time can be set using BME280_STANDBY_TIME_125_MS. + * + * @note Usage Hint : bme280_set_standby_durn(BME280_STANDBY_TIME_125_MS) + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE bme280_set_standby_durn(u8 v_standby_durn_u8); +/**************************************************************/ +/**\name FUNCTION FOR WORK MODE*/ +/**************************************************************/ +/* + * @brief Writes the working mode to the sensor + * + * + * + * + * @param v_work_mode_u8 : Mode to be set + * value | Working mode + * ----------|-------------------- + * 0 | BME280_ULTRALOWPOWER_MODE + * 1 | BME280_LOWPOWER_MODE + * 2 | BME280_STANDARDRESOLUTION_MODE + * 3 | BME280_HIGHRESOLUTION_MODE + * 4 | BME280_ULTRAHIGHRESOLUTION_MODE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +/*BME280_RETURN_FUNCTION_TYPE bme280_set_work_mode(u8 v_work_mode_u8);*/ +/**************************************************************/ +/**\name FUNCTION FOR FORCE MODE DATA READ*/ +/**************************************************************/ +/*! + * @brief This API used to read uncompensated + * temperature,pressure and humidity in forced mode + * + * + * @param v_uncom_pressure_s32: The value of uncompensated pressure + * @param v_uncom_temperature_s32: The value of uncompensated temperature + * @param v_uncom_humidity_s32: The value of uncompensated humidity + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BME280_RETURN_FUNCTION_TYPE +bme280_get_forced_uncomp_pressure_temperature_humidity( +s32 *v_uncom_pressure_s32, +s32 *v_uncom_temperature_s32, s32 *v_uncom_humidity_s32); +/**************************************************************/ +/**\name FUNCTION FOR COMMON READ AND WRITE */ +/**************************************************************/ +/*! + * @brief + * This API write the data to + * the given register + * + * + * @param v_addr_u8 -> Address of the register + * @param v_data_u8 -> The data from the register + * @param v_len_u8 -> no of bytes to read + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BME280_RETURN_FUNCTION_TYPE bme280_write_register(u8 v_addr_u8, +u8 *v_data_u8, u8 v_len_u8); +/*! + * @brief + * This API reads the data from + * the given register + * + * + * @param v_addr_u8 -> Address of the register + * @param v_data_u8 -> The data from the register + * @param v_len_u8 -> no of bytes to read + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BME280_RETURN_FUNCTION_TYPE bme280_read_register(u8 v_addr_u8, +u8 *v_data_u8, u8 v_len_u8); +/**************************************************************/ +/**\name FUNCTION FOR FLOAT OUTPUT TEMPERATURE*/ +/**************************************************************/ +#ifdef BME280_ENABLE_FLOAT +/*! + * @brief Reads actual temperature from uncompensated temperature + * @note returns the value in Degree centigrade + * @note Output value of "51.23" equals 51.23 DegC. + * + * + * + * @param v_uncom_temperature_s32 : value of uncompensated temperature + * + * + * + * @return Return the actual temperature in floating point + * +*/ +double bme280_compensate_temperature_double( +s32 v_uncom_temperature_s32); +/**************************************************************/ +/**\name FUNCTION FOR FLOAT OUTPUT PRESSURE*/ +/**************************************************************/ +/*! + * @brief Reads actual pressure from uncompensated pressure + * @note Returns pressure in Pa as double. + * @note Output value of "96386.2" + * equals 96386.2 Pa = 963.862 hPa. + * + * + * @param v_uncom_pressure_s32 : value of uncompensated pressure + * + * + * @return Return the actual pressure in floating point + * +*/ +double bme280_compensate_pressure_double(s32 v_uncom_pressure_s32); +/**************************************************************/ +/**\name FUNCTION FOR FLOAT OUTPUT HUMIDITY*/ +/**************************************************************/ +/*! + * @brief Reads actual humidity from uncompensated humidity + * @note returns the value in relative humidity (%rH) + * @note Output value of "42.12" equals 42.12 %rH + * + * @param v_uncom_humidity_s32 : value of uncompensated humidity + * + * + * + * @return Return the actual humidity in floating point + * +*/ +double bme280_compensate_humidity_double(s32 v_uncom_humidity_s32); +#endif +/**************************************************************/ +/**\name FUNCTION FOR 64BIT OUTPUT PRESSURE*/ +/**************************************************************/ +#if defined(BME280_ENABLE_INT64) && defined(BME280_64BITSUPPORT_PRESENT) +/*! + * @brief Reads actual pressure from uncompensated pressure + * @note Returns the value in Pa as unsigned 32 bit + * integer in Q24.8 format (24 integer bits and + * 8 fractional bits). + * @note Output value of "24674867" + * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa + * + * + * + * @param v_uncom_pressure_s32 : value of uncompensated temperature + * + * + * @return Return the actual pressure in u32 + * +*/ +u32 bme280_compensate_pressure_int64(s32 v_uncom_pressure_s32); +/**************************************************************/ +/**\name FUNCTION FOR 24BIT OUTPUT PRESSURE*/ +/**************************************************************/ +/*! + * @brief Reads actual pressure from uncompensated pressure + * @note Returns the value in Pa. + * @note Output value of "12337434" + * @note represents 12337434 / 128 = 96386.2 Pa = 963.862 hPa + * + * + * + * @param v_uncom_pressure_s32 : value of uncompensated pressure + * + * + * @return the actual pressure in u32 + * +*/ +u32 bme280_compensate_pressure_int64_twentyfour_bit_output( +s32 v_uncom_pressure_s32); +#endif +/**************************************************************/ +/**\name FUNCTION FOR WAIT PERIOD*/ +/**************************************************************/ +/*! + * @brief Computing waiting time for sensor data read + * + * + * + * + * @param v_delaytime_u8 : The value of delay time for force mode + * + * + * @retval 0 -> Success + * + * + */ +BME280_RETURN_FUNCTION_TYPE bme280_compute_wait_time(u8 +*v_delaytime_u8r); +#endif diff --git a/app/src/main/jni/si1132.c b/app/src/main/jni/si1132.c new file mode 100644 index 0000000..2099c7e --- /dev/null +++ b/app/src/main/jni/si1132.c @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include "si1132.h" + +int si1132_begin(const char *device) +{ + int status = 0; + si1132Fd = -1; + + si1132Fd = open(device, O_RDWR); + if (si1132Fd < 0) { + printf("ERROR: si1132 open failed\n"); + return -1; + } + + status = ioctl(si1132Fd, I2C_SLAVE, Si1132_ADDR); + if (status < 0) { + printf("ERROR: si1132 ioctl error\n"); + close(si1132Fd); + return -1; + } + + if (Si1132_I2C_read8(Si1132_REG_PARTID) != 0x32) { + printf("ERROR: si1132 read failed the PART ID\n"); + return -1; + } + + initialize(); + + return si1132Fd; +} + +void si1132_end() { + if (si1132Fd) + close(si1132Fd); +} + +void initialize(void) +{ + reset(); + + Si1132_I2C_write8(Si1132_REG_UCOEF0, 0x7B); + Si1132_I2C_write8(Si1132_REG_UCOEF1, 0x6B); + Si1132_I2C_write8(Si1132_REG_UCOEF2, 0x01); + Si1132_I2C_write8(Si1132_REG_UCOEF3, 0x00); + + Si1132_I2C_writeParam(Si1132_PARAM_CHLIST, Si1132_PARAM_CHLIST_ENUV | + Si1132_PARAM_CHLIST_ENALSIR | Si1132_PARAM_CHLIST_ENALSVIS); + Si1132_I2C_write8(Si1132_REG_INTCFG, Si1132_REG_INTCFG_INTOE); + Si1132_I2C_write8(Si1132_REG_IRQEN, Si1132_REG_IRQEN_ALSEVERYSAMPLE); + + Si1132_I2C_writeParam(Si1132_PARAM_ALSIRADCMUX, Si1132_PARAM_ADCMUX_SMALLIR); + usleep(10000); + // fastest clocks, clock div 1 + Si1132_I2C_writeParam(Si1132_PARAM_ALSIRADCGAIN, 0); + usleep(10000); + // take 511 clocks to measure + Si1132_I2C_writeParam(Si1132_PARAM_ALSIRADCCOUNTER, Si1132_PARAM_ADCCOUNTER_511CLK); + // in high range mode + Si1132_I2C_writeParam(Si1132_PARAM_ALSIRADCMISC, Si1132_PARAM_ALSIRADCMISC_RANGE); + usleep(10000); + // fastest clocks + Si1132_I2C_writeParam(Si1132_PARAM_ALSVISADCGAIN, 0); + usleep(10000); + // take 511 clocks to measure + Si1132_I2C_writeParam(Si1132_PARAM_ALSVISADCCOUNTER, Si1132_PARAM_ADCCOUNTER_511CLK); + //in high range mode (not normal signal) + Si1132_I2C_writeParam(Si1132_PARAM_ALSVISADCMISC, Si1132_PARAM_ALSVISADCMISC_VISRANGE); + usleep(10000); + + Si1132_I2C_write8(Si1132_REG_MEASRATE0, 0xFF); + Si1132_I2C_write8(Si1132_REG_COMMAND, Si1132_ALS_AUTO); +} + +void reset() +{ + Si1132_I2C_write8(Si1132_REG_MEASRATE0, 0); + Si1132_I2C_write8(Si1132_REG_MEASRATE1, 0); + Si1132_I2C_write8(Si1132_REG_IRQEN, 0); + Si1132_I2C_write8(Si1132_REG_IRQMODE1, 0); + Si1132_I2C_write8(Si1132_REG_IRQMODE2, 0); + Si1132_I2C_write8(Si1132_REG_INTCFG, 0); + Si1132_I2C_write8(Si1132_REG_IRQSTAT, 0xFF); + + Si1132_I2C_write8(Si1132_REG_COMMAND, Si1132_RESET); + usleep(10000); + Si1132_I2C_write8(Si1132_REG_HWKEY, 0x17); + + usleep(10000); +} + +void Si1132_readVisible(float *result) +{ + usleep(10000); + *result = ((Si1132_I2C_read16(0x22) - 256) / 0.282) * 14.5; +} + +void Si1132_readIR(float *result) +{ + usleep(10000); + *result = ((Si1132_I2C_read16(0x24) - 250) / 2.44) * 14.5; +} + +void Si1132_readUV(int *result) +{ + usleep(10000); + *result = (int)Si1132_I2C_read16(0x2c); +} + +unsigned char Si1132_I2C_read8(unsigned char reg) +{ + unsigned char ret; + write(si1132Fd, ®, 1); + read(si1132Fd, &ret, 1); + return ret; +} + +unsigned short Si1132_I2C_read16(unsigned char reg) +{ + unsigned char rbuf[2]; + write(si1132Fd, ®, 1); + read(si1132Fd, rbuf, 2); + return (unsigned short)(rbuf[0] | rbuf[1] << 8); +} + +void Si1132_I2C_write8(unsigned char reg, unsigned char val) +{ + unsigned char wbuf[2]; + wbuf[0] = reg; + wbuf[1] = val; + write(si1132Fd, wbuf, 2); +} + +void Si1132_I2C_writeParam(unsigned char param, unsigned char val) +{ + Si1132_I2C_write8(Si1132_REG_PARAMWR, val); + Si1132_I2C_write8(Si1132_REG_COMMAND, param | Si1132_PARAM_SET); +} diff --git a/app/src/main/jni/si1132.h b/app/src/main/jni/si1132.h new file mode 100644 index 0000000..ddeef2d --- /dev/null +++ b/app/src/main/jni/si1132.h @@ -0,0 +1,92 @@ +/* COMMANDS */ +#define Si1132_PARAM_QUERY 0x80 +#define Si1132_PARAM_SET 0xA0 +#define Si1132_NOP 0x00 +#define Si1132_RESET 0x01 +#define Si1132_BUSADDR 0x02 +#define Si1132_GET_CAL 0x12 +#define Si1132_ALS_FORCE 0x06 +#define Si1132_ALS_PAUSE 0x0A +#define Si1132_ALS_AUTO 0x0E + +/* Parameters */ +#define Si1132_PARAM_I2CADDR 0x00 +#define Si1132_PARAM_CHLIST 0x01 +#define Si1132_PARAM_CHLIST_ENUV 0x80 +#define Si1132_PARAM_CHLIST_ENAUX 0x40 +#define Si1132_PARAM_CHLIST_ENALSIR 0x20 +#define Si1132_PARAM_CHLIST_ENALSVIS 0x10 + +#define Si1132_PARAM_ALSENCODING 0x06 + +#define Si1132_PARAM_ALSIRADCMUX 0x0E +#define Si1132_PARAM_AUXADCMUX 0x0F + +#define Si1132_PARAM_ALSVISADCCOUNTER 0x10 +#define Si1132_PARAM_ALSVISADCGAIN 0x11 +#define Si1132_PARAM_ALSVISADCMISC 0x12 +#define Si1132_PARAM_ALSVISADCMISC_VISRANGE 0x20 + +#define Si1132_PARAM_ALSIRADCCOUNTER 0x1D +#define Si1132_PARAM_ALSIRADCGAIN 0x1E +#define Si1132_PARAM_ALSIRADCMISC 0x1F +#define Si1132_PARAM_ALSIRADCMISC_RANGE 0x20 + +#define Si1132_PARAM_ADCCOUNTER_511CLK 0x70 + +#define Si1132_PARAM_ADCMUX_SMALLIR 0x00 +#define Si1132_PARAM_ADCMUX_LARGEIR 0x03 + +/* REGISTERS */ +#define Si1132_REG_PARTID 0x00 +#define Si1132_REG_REVID 0x01 +#define Si1132_REG_SEQID 0x02 + +#define Si1132_REG_INTCFG 0x03 +#define Si1132_REG_INTCFG_INTOE 0x01 + +#define Si1132_REG_IRQEN 0x04 +#define Si1132_REG_IRQEN_ALSEVERYSAMPLE 0x01 + +#define Si1132_REG_IRQMODE1 0x05 +#define Si1132_REG_IRQMODE2 0x06 + +#define Si1132_REG_HWKEY 0x07 +#define Si1132_REG_MEASRATE0 0x08 +#define Si1132_REG_MEASRATE1 0x09 +#define Si1132_REG_UCOEF0 0x13 +#define Si1132_REG_UCOEF1 0x14 +#define Si1132_REG_UCOEF2 0x15 +#define Si1132_REG_UCOEF3 0x16 +#define Si1132_REG_PARAMWR 0x17 +#define Si1132_REG_COMMAND 0x18 +#define Si1132_REG_RESPONSE 0x20 +#define Si1132_REG_IRQSTAT 0x21 + +#define Si1132_REG_ALSVISDATA0 0x22 +#define Si1132_REG_ALSVISDATA1 0x23 +#define Si1132_REG_ALSIRDATA0 0x24 +#define Si1132_REG_ALSIRDATA1 0x25 +#define Si1132_REG_UVINDEX0 0x2C +#define Si1132_REG_UVINDEX1 0x2D +#define Si1132_REG_PARAMRD 0x2E +#define Si1132_REG_CHIPSTAT 0x30 + +#define Si1132_ADDR 0x60 + +int si1132Fd; + +int si1132_begin(const char *device); +void si1132_end(); +void initialize(void); +void reset(); + +void Si1132_readVisible(float *result); +void Si1132_readIR(float *result); +void Si1132_readUV(); + +unsigned char Si1132_I2C_read8(unsigned char reg); +unsigned short Si1132_I2C_read16(unsigned char reg); + +void Si1132_I2C_write8(unsigned char reg, unsigned char val); +void Si1132_I2C_writeParam(unsigned char param, unsigned char val); diff --git a/app/src/main/jni/weather.c b/app/src/main/jni/weather.c new file mode 100644 index 0000000..830b211 --- /dev/null +++ b/app/src/main/jni/weather.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) +#define LOG_TAG "weather" + +#include +#include +#include + +#include +#include +#include + +int pressure; +int temperature; +int humidity; + +float SEALEVELPRESSURE_HPA = 1024.25; + +jint Java_com_hardkernel_odroid_weatherboard_MainActivity_openWeatherBoard(JNIEnv* env, jobject obj, jstring str) { + const char *i2c_dev = (*env)->GetStringUTFChars(env, str, 0); + int result = -1; + result = si1132_begin(i2c_dev); + if (result == -1) + return result; + result = bme280_begin(i2c_dev); + (*env)->ReleaseStringUTFChars(env, str, i2c_dev); + return result; +} + +void Java_com_hardkernel_odroid_weatherboard_MainActivity_closeWeatherBoard(JNIEnv* env, jobject obj) { + bme280_end(); + si1132_end(); +} + +void Java_com_hardkernel_odroid_weatherboard_MainActivity_bme280_end(JNIEnv* env, jobject obj) { + bme280_end(); +} + +jint Java_com_hardkernel_odroid_weatherboard_MainActivity_getUVindex(JNIEnv* env, jobject obj) { + int result = 0; + Si1132_readUV(&result); + return result; +} + +jfloat Java_com_hardkernel_odroid_weatherboard_MainActivity_getVisible(JNIEnv* env, jobject obj) { + float result = 0.0; + Si1132_readVisible(&result); + return result; +} + +jfloat Java_com_hardkernel_odroid_weatherboard_MainActivity_getIR(JNIEnv* env, jobject obj) { + float result = 0.0; + Si1132_readIR(&result); + return result; +} + +void Java_com_hardkernel_odroid_weatherboard_MainActivity_readyData(JNIEnv* env, jobject obj) { + bme280_read_pressure_temperature_humidity(&pressure, &temperature, &humidity); +} + +jint Java_com_hardkernel_odroid_weatherboard_MainActivity_getTemperature(JNIEnv* env, jobject obj) { + return temperature; +} + +jint Java_com_hardkernel_odroid_weatherboard_MainActivity_getPressure(JNIEnv* env, jobject obj) { + return pressure; +} + +jint Java_com_hardkernel_odroid_weatherboard_MainActivity_getHumidity(JNIEnv* env, jobject obj) { + return humidity; +} + +jint Java_com_hardkernel_odroid_weatherboard_MainActivity_getAltitude(JNIEnv* env, jobject obj) { + int result = 0; + bme280_readAltitude(pressure, &SEALEVELPRESSURE_HPA, &result); + return result; +} diff --git a/app/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..288b665 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..6ae570b Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_launcher.png b/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..d4fb7cd Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..85a6081 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..6f7e3a5 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml new file mode 100644 index 0000000..3416a3e --- /dev/null +++ b/app/src/main/res/menu/main.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/app/src/main/res/values-v11/styles.xml b/app/src/main/res/values-v11/styles.xml new file mode 100644 index 0000000..3c02242 --- /dev/null +++ b/app/src/main/res/values-v11/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/main/res/values-v14/styles.xml b/app/src/main/res/values-v14/styles.xml new file mode 100644 index 0000000..a91fd03 --- /dev/null +++ b/app/src/main/res/values-v14/styles.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..f3e7020 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,10 @@ + + + + 64dp + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..55c1e59 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..c277dbf --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,22 @@ + + + + WeatherBoard + Hello world! + Settings + + BME280 + SI1132 + Temperature + Pressure + UV index + Visible + IR + Humidity + °C + Altitude + /dev/i2c-1 + /dev/i2c-10 + /dev/i2c-3 + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..6ce89c7 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..19414bd --- /dev/null +++ b/build.gradle @@ -0,0 +1,17 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + jcenter() + google() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.2.1' + } +} + +allprojects { + repositories { + jcenter() + google() + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f6b961f Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9a4163a --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/import-summary.txt b/import-summary.txt new file mode 100644 index 0000000..dc15d1c --- /dev/null +++ b/import-summary.txt @@ -0,0 +1,43 @@ +ECLIPSE ANDROID PROJECT IMPORT SUMMARY +====================================== + +Ignored Files: +-------------- +The following files were *not* copied into the new Gradle project; you +should evaluate whether these are still needed in your project and if +so manually move them: + +* .idea\ +* .idea\codeStyles\ +* .idea\codeStyles\Project.xml +* .idea\modules.xml +* .idea\vcs.xml +* .idea\weatherboard.iml +* .idea\workspace.xml +* ic_launcher-web.png +* proguard-project.txt + +Moved Files: +------------ +Android Gradle projects use a different directory structure than ADT +Eclipse projects. Here's how the projects were restructured: + +* AndroidManifest.xml => app\src\main\AndroidManifest.xml +* jni\ => app\src\main\jni\ +* res\ => app\src\main\res\ +* src\ => app\src\main\java\ + +Next Steps: +----------- +You can now build the project. The Gradle project needs network +connectivity to download dependencies. + +Bugs: +----- +If for some reason your project does not build, and you determine that +it is due to a bug or limitation of the Eclipse to Gradle importer, +please file a bug at http://b.android.com with category +Component-Tools. + +(This import summary is for your information only, and can be deleted +after import once you are satisfied with the results.) diff --git a/local.properties b/local.properties new file mode 100644 index 0000000..ac3bbf9 --- /dev/null +++ b/local.properties @@ -0,0 +1,9 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Sun Mar 17 17:14:41 KST 2019 +ndk.dir=C\:\\Android\\sdk\\ndk-bundle +sdk.dir=C\:\\Android\\sdk diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..d3db109 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app'