/* * Copyright (c) 2020, RudyLo * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2020-01-20 luhuadong the first version * 2020-10-05 luhuadong v0.9.0 */ #include #include #include #include "dhtxx.h" #include "ulog.h" #define DATA_PIN 100//PG4 float temp_dth = 0; float humi_dht = 0; dht_device_t sensor_dht; /* cat_dhtxx sensor data by dynamic */ static void cat_dhtxx(void) { dht_device_t sensor = dht_create(DATA_PIN); if(dht_read(sensor)) { rt_int32_t temp = dht_get_temperature(sensor); rt_int32_t humi = dht_get_humidity(sensor); rt_kprintf("Temp: %d, Humi: %d\n", temp, humi); } else { rt_kprintf("Read dht sensor failed.\n"); } dht_delete(sensor); } #ifdef FINSH_USING_MSH MSH_CMD_EXPORT(cat_dhtxx, read dhtxx humidity and temperature); #endif void dht11_get_data(void) { // dht_device_t sensor = dht_create(DATA_PIN); if(dht_read(sensor_dht)) { rt_int32_t temp = dht_get_temperature(sensor_dht); rt_int32_t humi = dht_get_humidity(sensor_dht); temp_dth = temp/10.0; humi_dht = humi/10.0; // LOG_I("Temp: %d, Humi: %d\n", temp, humi); } else { // LOG_W("Read dht sensor failed.\n"); } // dht_delete(sensor); } void dht11_init(void) { sensor_dht = dht_create(DATA_PIN); }