|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
|
8 | 8 | #include "i2c_bus.h" |
9 | 9 | #include "esp_log.h" |
10 | 10 | #include "hdc2010.h" |
| 11 | +#include "iot_sensor_hub.h" |
11 | 12 |
|
12 | 13 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */ |
13 | 14 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */ |
@@ -289,3 +290,81 @@ esp_err_t hdc2010_default_init(hdc2010_handle_t sensor) |
289 | 290 |
|
290 | 291 | return ESP_OK; |
291 | 292 | } |
| 293 | + |
| 294 | +#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE |
| 295 | + |
| 296 | +static hdc2010_handle_t hdc2010 = NULL; |
| 297 | +static bool is_init = false; |
| 298 | + |
| 299 | +esp_err_t humiture_hdc2010_init(i2c_bus_handle_t i2c_bus, uint8_t addr) |
| 300 | +{ |
| 301 | + if (is_init || !i2c_bus) { |
| 302 | + return ESP_FAIL; |
| 303 | + } |
| 304 | + |
| 305 | + hdc2010 = hdc2010_create(i2c_bus, addr); |
| 306 | + |
| 307 | + if (!hdc2010) { |
| 308 | + return ESP_FAIL; |
| 309 | + } |
| 310 | + |
| 311 | + is_init = true; |
| 312 | + return ESP_OK; |
| 313 | +} |
| 314 | + |
| 315 | +esp_err_t humiture_hdc2010_deinit(void) |
| 316 | +{ |
| 317 | + if (!is_init) { |
| 318 | + return ESP_FAIL; |
| 319 | + } |
| 320 | + |
| 321 | + esp_err_t ret = hdc2010_delete(&hdc2010); |
| 322 | + |
| 323 | + if (ret != ESP_OK) { |
| 324 | + return ESP_FAIL; |
| 325 | + } |
| 326 | + |
| 327 | + is_init = false; |
| 328 | + return ESP_OK; |
| 329 | +} |
| 330 | + |
| 331 | +esp_err_t humiture_hdc2010_test(void) |
| 332 | +{ |
| 333 | + if (!is_init) { |
| 334 | + return ESP_FAIL; |
| 335 | + } |
| 336 | + |
| 337 | + return ESP_OK; |
| 338 | +} |
| 339 | + |
| 340 | +esp_err_t humiture_hdc2010_acquire_humidity(float *h) |
| 341 | +{ |
| 342 | + if (!is_init) { |
| 343 | + return ESP_FAIL; |
| 344 | + } |
| 345 | + |
| 346 | + *h = hdc2010_get_humidity(hdc2010); |
| 347 | + return ESP_OK; |
| 348 | +} |
| 349 | + |
| 350 | +esp_err_t humiture_hdc2010_acquire_temperature(float *t) |
| 351 | +{ |
| 352 | + if (!is_init) { |
| 353 | + return ESP_FAIL; |
| 354 | + } |
| 355 | + |
| 356 | + *t = hdc2010_get_temperature(hdc2010); |
| 357 | + return ESP_OK; |
| 358 | +} |
| 359 | + |
| 360 | +static humiture_impl_t hdc2010_impl = { |
| 361 | + .init = humiture_hdc2010_init, |
| 362 | + .deinit = humiture_hdc2010_deinit, |
| 363 | + .test = humiture_hdc2010_test, |
| 364 | + .acquire_humidity = humiture_hdc2010_acquire_humidity, |
| 365 | + .acquire_temperature = humiture_hdc2010_acquire_temperature, |
| 366 | +}; |
| 367 | + |
| 368 | +SENSOR_HUB_DETECT_FN(HUMITURE_ID, hdc2010, &hdc2010_impl); |
| 369 | + |
| 370 | +#endif |
0 commit comments