Skip to content
Snippets Groups Projects
Commit 3aca1482 authored by schneider's avatar schneider
Browse files

feat(bme680): Act as shim if BSEC is active

parent ad325247
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,13 @@ int epic_bme680_init() ...@@ -67,6 +67,13 @@ int epic_bme680_init()
{ {
int8_t result = BME680_OK; int8_t result = BME680_OK;
if (bsec_active()) {
/* If the proprietary Bosch BSEC libary is in use
* we redirect calls to that. It always runs
* in the background
*/
return 0;
}
if (initialized) { if (initialized) {
return 0; return 0;
} }
...@@ -133,6 +140,10 @@ int epic_bme680_deinit() ...@@ -133,6 +140,10 @@ int epic_bme680_deinit()
* penalty. * penalty.
*/ */
if (bsec_active()) {
return 0;
}
#if 0 #if 0
if (!initialized) { if (!initialized) {
return 0; return 0;
...@@ -152,6 +163,10 @@ int epic_bme680_read_sensors(struct bme680_sensor_data *data) ...@@ -152,6 +163,10 @@ int epic_bme680_read_sensors(struct bme680_sensor_data *data)
{ {
int8_t result = BME680_OK; int8_t result = BME680_OK;
if (bsec_active()) {
return bsec_read_bme680(data);
}
if (!initialized) { if (!initialized) {
LOG_ERR("bme680", "bme680 sensor not initialized"); LOG_ERR("bme680", "bme680 sensor not initialized");
return -EINVAL; return -EINVAL;
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#include <stdio.h> #include <stdio.h>
TaskHandle_t bsec_task_id; TaskHandle_t bsec_task_id;
static struct bme680_sensor_data last_bme680_data;
static int64_t last_bme680_timestamp;
static bool active;
// From generic_18v_3s_4d/bsec_serialized_configurations_iaq.c // From generic_18v_3s_4d/bsec_serialized_configurations_iaq.c
static const uint8_t bsec_config_generic_18v_3s_4d[454] = { static const uint8_t bsec_config_generic_18v_3s_4d[454] = {
...@@ -108,9 +111,14 @@ void output_ready( ...@@ -108,9 +111,14 @@ void output_ready(
float co2_equivalent, float co2_equivalent,
float breath_voc_equivalent float breath_voc_equivalent
) { ) {
last_bme680_data.temperature = temperature;
last_bme680_data.humidity = humidity;
last_bme680_data.pressure = pressure / 100.;
last_bme680_data.gas_resistance = gas;
last_bme680_timestamp = timestamp;
return; return;
printf("bosch data time: %u, iaq: %u, iaq_a: %u, temp10: %u, hum10: %u, pres: %u, raw_temp10: %u, raw_hum10: %u, gas: %u, static_iaq: %u, co21e6: %u, breath_voc1e6: %u\n", printf("bosch data time: %u, iaq: %u, iaq_a: %u, temp10: %u, hum10: %u, pres: %u, raw_temp10: %u, raw_hum10: %u, gas: %u, static_iaq: %u, co21e6: %u, breath_voc1e6: %u\n",
(unsigned int)(timestamp / 9e6), (unsigned int)(timestamp / 1e6),
(unsigned int)(iaq), (unsigned int)(iaq),
(unsigned int)(iaq_accuracy), (unsigned int)(iaq_accuracy),
(unsigned int)(temperature * 10), (unsigned int)(temperature * 10),
...@@ -289,15 +297,26 @@ static void delay(uint32_t msec) ...@@ -289,15 +297,26 @@ static void delay(uint32_t msec)
vTaskDelay(pdMS_TO_TICKS(msec)); vTaskDelay(pdMS_TO_TICKS(msec));
} }
/*! bool bsec_active(void)
* @brief Main function which configures BSEC library and then reads and processes the data from sensor based {
* on timer ticks return active;
* }
* @return result of the processing
*/ int bsec_read_bme680(struct bme680_sensor_data *data)
{
if (!active) {
return BME680_E_COM_FAIL;
}
while (last_bme680_timestamp == 0)
vTaskDelay(pdMS_TO_TICKS(10));
*data = last_bme680_data;
return BME680_OK;
}
void vBSECTask(void *pvParameters) void vBSECTask(void *pvParameters)
{ {
return_values_init ret; return_values_init ret;
active = true;
bsec_task_id = xTaskGetCurrentTaskHandle(); bsec_task_id = xTaskGetCurrentTaskHandle();
/* Call to the function which initializes the BSEC library */ /* Call to the function which initializes the BSEC library */
...@@ -317,7 +336,7 @@ void vBSECTask(void *pvParameters) ...@@ -317,7 +336,7 @@ void vBSECTask(void *pvParameters)
#endif #endif
if (ret.bme680_status) { if (ret.bme680_status) {
printf("bme680 init failed\n"); printf("bme680 init failed\n");
/* Could not intialize BME680 or BSEC library */ /* Could not intialize BME680 */
while (1) while (1)
; ;
} else if (ret.bsec_status) { } else if (ret.bsec_status) {
......
...@@ -136,7 +136,11 @@ void max30001_mutex_init(void); ...@@ -136,7 +136,11 @@ void max30001_mutex_init(void);
/* ---------- GPIO --------------------------------------------------------- */ /* ---------- GPIO --------------------------------------------------------- */
extern gpio_cfg_t gpio_configs[]; extern gpio_cfg_t gpio_configs[];
/* ---------- BSEC / BME680 ------------------------------------------------ */
void vBSECTask(void *pvParameters); void vBSECTask(void *pvParameters);
bool bsec_active(void);
struct bme680_sensor_data;
int bsec_read_bme680(struct bme680_sensor_data *data);
/* ---------- Sleep -------------------------------------------------------- */ /* ---------- Sleep -------------------------------------------------------- */
void sleep_deepsleep(void); void sleep_deepsleep(void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment