diff --git a/epicardium/modules/bsec.c b/epicardium/modules/bsec.c index 925e63f3493131a8c5c8c4e25d4c818839a0ef1f..bcb81bd64fc95c3acb50732c914186df0fc159b0 100644 --- a/epicardium/modules/bsec.c +++ b/epicardium/modules/bsec.c @@ -18,9 +18,9 @@ #include <stdio.h> TaskHandle_t bsec_task_id; -static struct bme680_sensor_data last_bme680_data; static int64_t last_bme680_timestamp; static bool bsec_task_active; +static struct bsec_sensor_data last_bsec_data; #define ULP 0 // From generic_18v_3s_4d/bsec_serialized_configurations_iaq.c @@ -102,13 +102,22 @@ void output_ready( float co2_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_bsec_data.temperature = temperature; + last_bsec_data.humidity = humidity; + last_bsec_data.pressure = pressure / 100.; + last_bsec_data.gas_resistance = gas; + last_bsec_data.timestamp = timestamp; + last_bsec_data.accuracy = iaq_accuracy; + last_bsec_data.indoor_air_quality = iaq; + last_bsec_data.static_indoor_air_quality = static_iaq; + last_bsec_data.co2_equivalent = co2_equivalent; + last_bsec_data.breath_voc_equivalent = breath_voc_equivalent; + + __sync_synchronize(); + last_bme680_timestamp = timestamp; 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, co21e3: %u, breath_voc1e3: %u\n", (unsigned int)(timestamp / 1e6), (unsigned int)(iaq), (unsigned int)(iaq_accuracy), @@ -119,8 +128,8 @@ void output_ready( (unsigned int)(raw_humidity * 10), (unsigned int)(gas), (unsigned int)(static_iaq), - (unsigned int)(co2_equivalent * 1e6), - (unsigned int)(breath_voc_equivalent * 1e6)); + (unsigned int)(co2_equivalent * 1e3), + (unsigned int)(breath_voc_equivalent * 1e3)); } static uint32_t bsec_load(char *path, uint8_t *buffer, uint32_t n_buffer) @@ -302,9 +311,19 @@ int bsec_read_bme680(struct bme680_sensor_data *data) if (!bsec_task_active) { return BME680_E_COM_FAIL; } + + if(data == NULL) { + return -EFAULT; + } + while (last_bme680_timestamp == 0) vTaskDelay(pdMS_TO_TICKS(10)); - *data = last_bme680_data; + + data->temperature = last_bsec_data.temperature; + data->humidity = last_bsec_data.humidity; + data->pressure = last_bsec_data.pressure; + data->gas_resistance = last_bsec_data.gas_resistance; + return BME680_OK; }