From 8c8f5ffb82e24dedda2192825eb44218ed042cc8 Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Sat, 16 May 2026 22:21:44 +0300 Subject: [PATCH] feat: added deinit --- include/zh_aht.h | 9 +++++++++ version.txt | 2 +- zh_aht.c | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/zh_aht.h b/include/zh_aht.h index 651f257..3ddb55e 100644 --- a/include/zh_aht.h +++ b/include/zh_aht.h @@ -65,6 +65,15 @@ extern "C" */ esp_err_t zh_aht_init(const zh_aht_init_config_t *config, zh_aht_handle_t *handle); + /** + * @brief Deinitialize AHT sensor. + * + * @param[in] handle Pointer to unique AHT handle. + * + * @return ESP_OK if success or an error code otherwise. + */ + esp_err_t zh_aht_deinit(zh_aht_handle_t *handle); + /** * @brief Read AHT sensor. * diff --git a/version.txt b/version.txt index 0fa4ae4..fbcbf73 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.3.0 \ No newline at end of file +3.4.0 \ No newline at end of file diff --git a/zh_aht.c b/zh_aht.c index 8ac3805..a1ea116 100644 --- a/zh_aht.c +++ b/zh_aht.c @@ -33,6 +33,17 @@ esp_err_t zh_aht_init(const zh_aht_init_config_t *config, zh_aht_handle_t *handl return ESP_OK; } +esp_err_t zh_aht_deinit(zh_aht_handle_t *handle) +{ + ZH_LOGI("AHT deinitialization started."); + ZH_ERROR_CHECK(handle != NULL, ESP_ERR_INVALID_ARG, NULL, "AHT deinitialization failed. Invalid argument."); + ZH_ERROR_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, NULL, "AHT deinitialization failed. AHT not initialized."); + ZH_ERROR_CHECK(i2c_master_bus_rm_device(handle->dev_handle) == ESP_OK, ESP_FAIL, NULL, "AHT deinitialization failed. I2C remove device failed."); + handle->is_initialized = false; + ZH_LOGI("AHT deinitialization completed successfully."); + return ESP_OK; +} + esp_err_t zh_aht_read(zh_aht_handle_t *handle, float *humidity, float *temperature) // -V2008 { ZH_LOGI("AHT read begin.");