/** * @file sgp40.h * @defgroup sgp40 sgp40 * @{ * * ESP-IDF driver for SGP40 Indoor Air Quality Sensor for VOC Measurements * * Copyright (c) 2020 Ruslan V. Uss * * BSD Licensed as described in the file LICENSE */ #ifndef __SGP40_H__ #define __SGP40_H__ #include #include #include "driver/i2c_master.h" #include "sensirion_voc_algorithm.h" #ifdef __cplusplus extern "C" { #endif #define SGP40_ADDR 0x59 //!< I2C address /** * @brief Type of SGP40 device handle */ typedef void *sgp40_handle_t; /** * @brief Create and init sensor object, read device information, initialize the VOC algorithm * * @param[in] bus_handle I2C bus handle. Obtained from i2c_new_master_bus(). * @param[in] dev_addr I2C address of sensor. Use SGP40_ADDR for default address. * @param[out] handle_ret Handle to created SGP40 driver object. * @return `ESP_OK` on success */ esp_err_t sgp40_create(i2c_master_bus_handle_t bus_handle, const uint8_t dev_addr, sgp40_handle_t *handle_ret); /** * @brief Delete and release a sensor object * * @param sensor object handle of sgp40 * @return `ESP_OK` on success */ esp_err_t sgp40_delete(sgp40_handle_t sensor); /** * @brief Reset device, than put it to idle mode * * @param sensor object handle of sgp40 * @return `ESP_OK` on success */ esp_err_t sgp40_soft_reset(sgp40_handle_t sensor); /** * @brief Perform a self-test * * @param sensor object handle of sgp40 * @return `ESP_OK` on success */ esp_err_t sgp40_self_test(sgp40_handle_t sensor); /** * @brief Turn hotplate off, stop measurement and put device to idle mode * * @param sensor object handle of sgp40 * @return `ESP_OK` on success */ esp_err_t sgp40_heater_off(sgp40_handle_t sensor); /** * @brief Perform a measurement * * @param sensor object handle of sgp40 * @param humidity Relative humidity, percents. Use NaN if * you want uncompensated measurement * @param temperature Temperature, degrees Celsius. Use NaN if * you want uncompensated measurement * @param[out] raw Raw value, proportional to the logarithm * of the resistance of the sensing element * @return `ESP_OK` on success */ esp_err_t sgp40_measure_raw(sgp40_handle_t sensor, float humidity, float temperature, uint16_t *raw); /** * @brief Perform a measurement and update VOC index * * @param sensor object handle of sgp40 * @param humidity Relative humidity, percents. Use NaN if * you want uncompensated measurement * @param temperature Temperature, degrees Celsius. Use NaN if * you want uncompensated measurement * @param[out] voc_index Calculated VOC index * @return `ESP_OK` on success */ esp_err_t sgp40_measure_voc(sgp40_handle_t sensor, float humidity, float temperature, int32_t *voc_index); #ifdef __cplusplus } #endif /**@}*/ #endif /* __SGP40_H__ */