70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
/// © MiroZ 2024
|
|
#include <esp_log.h>
|
|
|
|
#include "Bme68x.h"
|
|
|
|
|
|
static const char *TAG = "Bme68x";
|
|
|
|
|
|
#define MEAS_DUR 140
|
|
#define NEW_GAS_MEAS (BME68X_GASM_VALID_MSK | BME68X_HEAT_STAB_MSK | BME68X_NEW_DATA_MSK)
|
|
|
|
Bme68x::Bme68x(TwoWire & bus) : m_bus(bus)
|
|
{
|
|
m_sensor = new MyLibs::Bme68x();
|
|
}
|
|
|
|
bool Bme68x::init()
|
|
{
|
|
m_sensor->begin(0x77, m_bus);
|
|
|
|
m_sensor->setTPH();
|
|
|
|
uint16_t tempProf[10] = { 320, 100, 100, 100, 200, 200, 200, 320, 320, 320 };
|
|
/* Multiplier to the shared heater duration */
|
|
uint16_t mulProf[10] = { 5, 2, 10, 30, 5, 5, 5, 5, 5, 5 };
|
|
/* Shared heating duration in milliseconds */
|
|
uint16_t sharedHeatrDur = MEAS_DUR - (m_sensor->getMeasDur(BME68X_PARALLEL_MODE) / 1000);
|
|
|
|
m_sensor->setHeaterProf(tempProf, mulProf, sharedHeatrDur, 10);
|
|
m_sensor->setOpMode(BME68X_PARALLEL_MODE);
|
|
|
|
m_operational = m_sensor->checkStatus() == BME68X_OK;
|
|
|
|
return m_operational;
|
|
}
|
|
|
|
/// @brief
|
|
/// @param data
|
|
/// @return returns true when index 9 is read
|
|
bool Bme68x::read(struct BME_DATA * data)
|
|
{
|
|
MyLibs::bme68xData bdata;
|
|
uint8_t left;
|
|
|
|
bool ret_val = false;
|
|
|
|
if(m_sensor->fetchData() > 0)
|
|
{
|
|
do
|
|
{
|
|
left = m_sensor->getData(bdata);
|
|
|
|
if (bdata.status == NEW_GAS_MEAS)
|
|
{
|
|
int ix = _min(bdata.gas_index, 9);
|
|
|
|
data->measurement_bitmask |= (1 << ix);
|
|
|
|
if(ix == 0)
|
|
data->humidity = bdata.humidity;
|
|
else if(ix == 9)
|
|
ret_val = true;
|
|
|
|
data->measurement[ix].resistance = bdata.gas_resistance;
|
|
}
|
|
} while(left > 0);
|
|
}
|
|
return ret_val;
|
|
} |