ESPHome  2021.11.4
Data Structures | Typedefs | Functions | Variables
esphome::sgp40 Namespace Reference

Data Structures

struct  SGP40Baselines
 
class  SGP40Component
 This class implements support for the Sensirion sgp40 i2c GAS (VOC) sensors. More...
 
struct  VocAlgorithmParams
 Struct to hold all the states of the VOC algorithm. More...
 

Typedefs

using fix16_t = int32_t
 

Functions

fix16_t fix16_from_int (int32_t a)
 
int32_t fix16_cast_to_int (fix16_t a)
 
void voc_algorithm_init (VocAlgorithmParams *params)
 Initialize the VOC algorithm parameters. More...
 
void voc_algorithm_get_states (VocAlgorithmParams *params, int32_t *state0, int32_t *state1)
 Get current algorithm states. More...
 
void voc_algorithm_set_states (VocAlgorithmParams *params, int32_t state0, int32_t state1)
 Set previously retrieved algorithm states to resume operation after a short interruption, skipping initial learning phase. More...
 
void voc_algorithm_set_tuning_parameters (VocAlgorithmParams *params, int32_t voc_index_offset, int32_t learning_time_hours, int32_t gating_max_duration_minutes, int32_t std_initial)
 Set parameters to customize the VOC algorithm. More...
 
void voc_algorithm_process (VocAlgorithmParams *params, int32_t sraw, int32_t *voc_index)
 Calculate the VOC index value from the raw sensor value. More...
 

Variables

const uint32_t FIX16_ONE = 0x00010000
 
struct esphome::sgp40::SGP40Baselines PACKED
 
const uint32_t SHORTEST_BASELINE_STORE_INTERVAL = 10800
 
const uint32_t MAXIMUM_STORAGE_DIFF = 50
 

Typedef Documentation

◆ fix16_t

using esphome::sgp40::fix16_t = typedef int32_t

Definition at line 12 of file sensirion_voc_algorithm.h.

Function Documentation

◆ fix16_cast_to_int()

int32_t esphome::sgp40::fix16_cast_to_int ( fix16_t  a)
inline

Definition at line 25 of file sensirion_voc_algorithm.cpp.

◆ fix16_from_int()

fix16_t esphome::sgp40::fix16_from_int ( int32_t  a)
inline

Definition at line 23 of file sensirion_voc_algorithm.cpp.

◆ voc_algorithm_get_states()

void esphome::sgp40::voc_algorithm_get_states ( VocAlgorithmParams params,
int32_t *  state0,
int32_t *  state1 
)

Get current algorithm states.

Retrieved values can be used in voc_algorithm_set_states() to resume operation after a short interruption, skipping initial learning phase. This feature can only be used after at least 3 hours of continuous operation.

Parameters
paramsPointer to the VocAlgorithmParams struct
state0State0 to be stored
state1State1 to be stored

Definition at line 308 of file sensirion_voc_algorithm.cpp.

◆ voc_algorithm_init()

void esphome::sgp40::voc_algorithm_init ( VocAlgorithmParams params)

Initialize the VOC algorithm parameters.

Call this once at the beginning or whenever the sensor stopped measurements.

Parameters
paramsPointer to the VocAlgorithmParams struct

Definition at line 284 of file sensirion_voc_algorithm.cpp.

◆ voc_algorithm_process()

void esphome::sgp40::voc_algorithm_process ( VocAlgorithmParams params,
int32_t  sraw,
int32_t *  voc_index 
)

Calculate the VOC index value from the raw sensor value.

Parameters
paramsPointer to the VocAlgorithmParams struct
srawRaw value from the SGP40 sensor
voc_indexCalculated VOC index value from the raw sensor value. Zero during initial blackout period and 1..500 afterwards

Definition at line 328 of file sensirion_voc_algorithm.cpp.

◆ voc_algorithm_set_states()

void esphome::sgp40::voc_algorithm_set_states ( VocAlgorithmParams params,
int32_t  state0,
int32_t  state1 
)

Set previously retrieved algorithm states to resume operation after a short interruption, skipping initial learning phase.

This feature should not be used after inerruptions of more than 10 minutes. Call this once after voc_algorithm_init() and the optional voc_algorithm_set_tuning_parameters(), if desired. Otherwise, the algorithm will start with initial learning phase.

Parameters
paramsPointer to the VocAlgorithmParams struct
state0State0 to be restored
state1State1 to be restored

Definition at line 313 of file sensirion_voc_algorithm.cpp.

◆ voc_algorithm_set_tuning_parameters()

void esphome::sgp40::voc_algorithm_set_tuning_parameters ( VocAlgorithmParams params,
int32_t  voc_index_offset,
int32_t  learning_time_hours,
int32_t  gating_max_duration_minutes,
int32_t  std_initial 
)

Set parameters to customize the VOC algorithm.

Call this once after voc_algorithm_init(), if desired. Otherwise, the default values will be used.

Parameters
paramsPointer to the VocAlgorithmParams struct
voc_index_offsetVOC index representing typical (average) conditions. Range 1..250, default 100
learning_time_hoursTime constant of long-term estimator. Past events will be forgotten after about twice the learning time. Range 1..72 [hours], default 12 [hours]
gating_max_duration_minutesMaximum duration of gating (freeze of estimator during high VOC index signal). 0 (no gating) or range 1..720 [minutes], default 180 [minutes]
std_initialInitial estimate for standard deviation. Lower value boosts events during initial learning period, but may result in larger device-to-device variations. Range 10..500, default 50

Definition at line 318 of file sensirion_voc_algorithm.cpp.

Variable Documentation

◆ FIX16_ONE

const uint32_t esphome::sgp40::FIX16_ONE = 0x00010000

Definition at line 21 of file sensirion_voc_algorithm.cpp.

◆ MAXIMUM_STORAGE_DIFF

const uint32_t esphome::sgp40::MAXIMUM_STORAGE_DIFF = 50

Definition at line 37 of file sgp40.h.

◆ PACKED

struct esphome::sgp40::SGP40Baselines esphome::sgp40::PACKED

◆ SHORTEST_BASELINE_STORE_INTERVAL

const uint32_t esphome::sgp40::SHORTEST_BASELINE_STORE_INTERVAL = 10800

Definition at line 34 of file sgp40.h.