You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.8 KiB
135 lines
3.8 KiB
/**
|
|
* bsec2 but rewritten in C
|
|
*
|
|
* Created on 2021/12/12.
|
|
*/
|
|
|
|
#ifndef ESPNODE_BSEC2_H
|
|
#define ESPNODE_BSEC2_H
|
|
|
|
// BSEC
|
|
#include "bme68x.h"
|
|
#include "bsec_datatypes.h"
|
|
#include "bsec_interface.h"
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#define ARRAY_LEN(array) (sizeof(array)/sizeof((array)[0]))
|
|
#define BSEC_CHECK_INPUT(x, shift) ((x) & (1 << ((shift)-1)))
|
|
#define BSEC_TOTAL_HEAT_DUR UINT16_C(140)
|
|
|
|
typedef bsec_output_t bsecData;
|
|
typedef bsec_virtual_sensor_t bsecSensor;
|
|
|
|
typedef struct
|
|
{
|
|
bsecData output[BSEC_NUMBER_OUTPUTS];
|
|
uint8_t nOutputs;
|
|
} bsecOutputs;
|
|
|
|
struct bsec2;
|
|
typedef void (*bsecCallback)(const struct bme68x_data *data, const bsecOutputs *outputs, const struct bsec2 * bsec);
|
|
|
|
struct bsec2 {
|
|
// "public"
|
|
struct bme68x_dev *sensor;
|
|
bsec_version_t version;
|
|
bsec_library_return_t status;
|
|
// "private"
|
|
int8_t sensor_status;
|
|
bsec_bme_settings_t bmeConf;
|
|
bsecCallback newDataCallback;
|
|
bsecOutputs outputs;
|
|
uint8_t opMode;
|
|
float extTempOffset;
|
|
uint32_t ovfCounter;
|
|
uint32_t lastMillis;
|
|
uint8_t workBuffer[BSEC_MAX_WORKBUFFER_SIZE];
|
|
};
|
|
|
|
int bsec2_init(struct bsec2 *self, struct bme68x_dev *dev);
|
|
|
|
/**
|
|
* @brief Function that sets the desired sensors and the sample rates
|
|
* @param sensorList : The list of output sensors
|
|
* @param nSensors : Number of outputs requested
|
|
* @param sampleRate : The sample rate of requested sensors, def BSEC_SAMPLE_RATE_ULP
|
|
* @return true for success, false otherwise
|
|
*/
|
|
bool bsec2_updateSubscription(struct bsec2 *self, const bsecSensor *sensorList, uint8_t nSensors, float sampleRate);
|
|
|
|
/**
|
|
* @brief Callback from the user to read data from the BME68x using parallel/forced mode, process and store outputs
|
|
* @return true for success, false otherwise
|
|
*/
|
|
bool bsec2_run(struct bsec2 *self);
|
|
|
|
static inline void bsec2_attachCallback(struct bsec2 *self, bsecCallback callback)
|
|
{
|
|
self->newDataCallback = callback;
|
|
}
|
|
|
|
/**
|
|
* @brief Function to get the BSEC outputs
|
|
* @return pointer to BSEC outputs if available else nullptr
|
|
*/
|
|
static inline const bsecOutputs* bsec2_getOutputs(struct bsec2 *self)
|
|
{
|
|
if (self->outputs.nOutputs)
|
|
return &self->outputs;
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* @brief Function to get the BSEC output by sensor id
|
|
* @return pointer to BSEC output, nullptr otherwise
|
|
*/
|
|
bsecData bsec2_getData(struct bsec2 *self, bsecSensor id);
|
|
|
|
/**
|
|
* @brief Function to get the state of the algorithm to save to non-volatile memory
|
|
* @param state : Pointer to a memory location, to hold the state
|
|
* @return true for success, false otherwise
|
|
*/
|
|
bool bsec2_getState(struct bsec2 *self, uint8_t *state);
|
|
|
|
/**
|
|
* @brief Function to set the state of the algorithm from non-volatile memory
|
|
* @param state : Pointer to a memory location that contains the state
|
|
* @return true for success, false otherwise
|
|
*/
|
|
bool bsec2_setState(struct bsec2 *self, uint8_t *state);
|
|
|
|
/**
|
|
* @brief Function to retrieve the current library configuration
|
|
* @param config : Pointer to a memory location, to hold the serialized config blob
|
|
* @return true for success, false otherwise
|
|
*/
|
|
bool bsec2_getConfig(struct bsec2 *self, uint8_t *config);
|
|
|
|
/**
|
|
* @brief Function to set the configuration of the algorithm from memory
|
|
* @param state : Pointer to a memory location that contains the configuration
|
|
* @return true for success, false otherwise
|
|
*/
|
|
bool bsec2_setConfig(struct bsec2 *self, const uint8_t *config);
|
|
|
|
/**
|
|
* @brief Function to set the temperature offset
|
|
* @param tempOffset : Temperature offset in degree Celsius
|
|
*/
|
|
static inline void bsec2_setTemperatureOffset(struct bsec2 *self, float tempOffset)
|
|
{
|
|
self->extTempOffset = tempOffset;
|
|
}
|
|
|
|
/**
|
|
* @brief Function to calculate an int64_t timestamp in milliseconds
|
|
*/
|
|
int64_t bsec2_getTimeMs(struct bsec2 *self);
|
|
|
|
extern void bsec2_errormsg(const char *msg);
|
|
|
|
extern uint32_t bsec2_timestamp_millis();
|
|
|
|
#endif //ESPNODE_BSEC2_H
|
|
|