88 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| #pragma once
 | |
| 
 | |
| #include "esp_err.h"
 | |
| #include "esp_log.h"
 | |
| #ifdef CONFIG_IDF_TARGET_ESP8266
 | |
| #include "driver/i2c.h"
 | |
| #else
 | |
| #include "driver/i2c_master.h"
 | |
| #endif
 | |
| #include "freertos/FreeRTOS.h"
 | |
| #include "freertos/task.h"
 | |
| 
 | |
| #define ZH_HTU_INIT_CONFIG_DEFAULT() \
 | |
|     {                                \
 | |
|         .i2c_port = 0,               \
 | |
|         .resolution = HTU_RES_12_14  \
 | |
|     }
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C"
 | |
| {
 | |
| #endif
 | |
| 
 | |
|     typedef enum
 | |
|     {
 | |
|         HTU_RES_8_12 = 0x1,   // 8 bit humidity resolution / 12 bit temperature resolution.
 | |
|         HTU_RES_10_13 = 0x40, // 10 bit humidity resolution / 13 bit temperature resolution.
 | |
|         HTU_RES_11_11 = 0x41, // 11 bit humidity resolution / 11 bit temperature resolution.
 | |
|         HTU_RES_12_14 = 0x0   // 12 bit humidity resolution / 14 bit temperature resolution.
 | |
|     } zh_htu_resolution_t;
 | |
| 
 | |
|     typedef struct // Structure for initial initialization of AHT sensor.
 | |
|     {
 | |
|         bool i2c_port;                  // I2C port.
 | |
|         zh_htu_resolution_t resolution; // Sensor measurement resolution.
 | |
| #ifndef CONFIG_IDF_TARGET_ESP8266
 | |
|         i2c_master_bus_handle_t i2c_handle; // Unique I2C bus handle.
 | |
| #endif
 | |
|     } zh_htu_init_config_t;
 | |
| 
 | |
|     /**
 | |
|      * @brief Initialize HTU sensor.
 | |
|      *
 | |
|      * @param[in] config Pointer to HTU initialized configuration structure. Can point to a temporary variable.
 | |
|      *
 | |
|      * @attention I2C driver must be initialized first.
 | |
|      *
 | |
|      * @note Before initialize the sensor recommend initialize zh_htu_init_config_t structure with default values.
 | |
|      *
 | |
|      * @code zh_htu_init_config_t config = ZH_HTU_INIT_CONFIG_DEFAULT() @endcode
 | |
|      *
 | |
|      * @return
 | |
|      *              - ESP_OK if initialization was success
 | |
|      *              - ESP_ERR_INVALID_ARG if parameter error
 | |
|      *              - ESP_ERR_NOT_FOUND if sensor not connected or not responded
 | |
|      *              - ESP_ERR_INVALID_RESPONSE if I2C driver error
 | |
|      */
 | |
|     esp_err_t zh_htu_init(const zh_htu_init_config_t *config);
 | |
| 
 | |
|     /**
 | |
|      * @brief Read HTU sensor.
 | |
|      *
 | |
|      * @param[out] humidity Pointer for HTU sensor reading data of humidity.
 | |
|      * @param[out] temperature Pointer for HTU sensor reading data of temperature.
 | |
|      *
 | |
|      * @return
 | |
|      *              - ESP_OK if read was success
 | |
|      *              - ESP_ERR_INVALID_ARG if parameter error
 | |
|      *              - ESP_ERR_NOT_FOUND if sensor is not initialized
 | |
|      *              - ESP_ERR_INVALID_CRC if check CRC is fail
 | |
|      *              - ESP_ERR_INVALID_RESPONSE if I2C driver error
 | |
|      *              - ESP_ERR_TIMEOUT if sensor has not responded
 | |
|      */
 | |
|     esp_err_t zh_htu_read(float *humidity, float *temperature);
 | |
| 
 | |
|     /**
 | |
|      * @brief Reset HTU sensor.
 | |
|      *
 | |
|      * @return
 | |
|      *              - ESP_OK if reset was success
 | |
|      *              - ESP_ERR_NOT_FOUND if sensor is not initialized
 | |
|      *              - ESP_ERR_INVALID_RESPONSE if I2C driver error
 | |
|      */
 | |
|     esp_err_t zh_htu_reset(void);
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif |