LibDriver DHT11
Loading...
Searching...
No Matches
driver_dht11_read_test.c
Go to the documentation of this file.
1
37
39
40static dht11_handle_t gs_handle;
41
50uint8_t dht11_read_test(uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 uint16_t temperature_raw;
55 uint16_t humidity_raw;
56 float temperature;
57 uint8_t humidity;
58 dht11_info_t info;
59
60 /* link interface function */
71
72 /* get dht11 information */
73 res = dht11_info(&info);
74 if (res != 0)
75 {
76 dht11_interface_debug_print("dht11: get info failed.\n");
77
78 return 1;
79 }
80 else
81 {
82 /* print dht11 information */
83 dht11_interface_debug_print("dht11: chip is %s.\n", info.chip_name);
84 dht11_interface_debug_print("dht11: manufacturer is %s.\n", info.manufacturer_name);
85 dht11_interface_debug_print("dht11: interface is %s.\n", info.interface);
86 dht11_interface_debug_print("dht11: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
87 dht11_interface_debug_print("dht11: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
88 dht11_interface_debug_print("dht11: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
89 dht11_interface_debug_print("dht11: max current is %0.2fmA.\n", info.max_current_ma);
90 dht11_interface_debug_print("dht11: max temperature is %0.1fC.\n", info.temperature_max);
91 dht11_interface_debug_print("dht11: min temperature is %0.1fC.\n", info.temperature_min);
92 }
93
94 /* start basic read test */
95 dht11_interface_debug_print("dht11: start read test.\n");
96
97 /* dht11 init */
98 res = dht11_init(&gs_handle);
99 if (res != 0)
100 {
101 dht11_interface_debug_print("dht11: init failed.\n");
102
103 return 1;
104 }
105
106 /* delay 2000 ms for read */
108 for (i = 0; i < times; i++)
109 {
110 /* read temperature and humidity */
111 res = dht11_read_temperature_humidity(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature, (uint16_t *)&humidity_raw, (uint8_t *)&humidity);
112 if (res != 0)
113 {
114 dht11_interface_debug_print("dht11: read failed.\n");
115 (void)dht11_deinit(&gs_handle);
116
117 return 1;
118 }
119
120 /* print result */
121 dht11_interface_debug_print("dht11: temperature: %.01fC.\n", temperature);
122 dht11_interface_debug_print("dht11: humidity: %d%%.\n", humidity);
123
124 /* delay 2000 ms*/
126 }
127
128 /* finish basic read test and exit */
129 dht11_interface_debug_print("dht11: finish read test.\n");
130 (void)dht11_deinit(&gs_handle);
131
132 return 0;
133}
driver dht11 read test header file
uint8_t dht11_read_temperature_humidity(dht11_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, uint8_t *humidity_s)
read the temperature and humidity data
struct dht11_info_s dht11_info_t
dht11 info structure definition
uint8_t dht11_info(dht11_info_t *info)
get chip's information
struct dht11_handle_s dht11_handle_t
dht11 handle structure definition
uint8_t dht11_init(dht11_handle_t *handle)
initialize the chip
uint8_t dht11_deinit(dht11_handle_t *handle)
close the chip
uint8_t dht11_interface_init(void)
interface bus init
uint8_t dht11_interface_deinit(void)
interface bus deinit
uint8_t dht11_interface_read(uint8_t *value)
interface bus read
uint8_t dht11_interface_write(uint8_t value)
interface bus write
void dht11_interface_delay_us(uint32_t us)
interface delay us
void dht11_interface_debug_print(const char *const fmt,...)
interface print format data
void dht11_interface_enable_irq(void)
interface enable the interrupt
void dht11_interface_disable_irq(void)
interface disable the interrupt
void dht11_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t dht11_read_test(uint32_t times)
read test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]