LibDriver DHT20
Loading...
Searching...
No Matches
driver_dht20_read_test.c
Go to the documentation of this file.
1
36
38
39static dht20_handle_t gs_handle;
40
49uint8_t dht20_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint32_t i;
53 uint32_t temperature_raw;
54 uint32_t humidity_raw;
55 float temperature;
56 uint8_t humidity;
57 dht20_info_t info;
58
59 /* link interface function */
67
68 /* get dht20 information */
69 res = dht20_info(&info);
70 if (res != 0)
71 {
72 dht20_interface_debug_print("dht20: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print dht20 information */
79 dht20_interface_debug_print("dht20: chip is %s.\n", info.chip_name);
80 dht20_interface_debug_print("dht20: manufacturer is %s.\n", info.manufacturer_name);
81 dht20_interface_debug_print("dht20: interface is %s.\n", info.interface);
82 dht20_interface_debug_print("dht20: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 dht20_interface_debug_print("dht20: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 dht20_interface_debug_print("dht20: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 dht20_interface_debug_print("dht20: max current is %0.2fmA.\n", info.max_current_ma);
86 dht20_interface_debug_print("dht20: max temperature is %0.1fC.\n", info.temperature_max);
87 dht20_interface_debug_print("dht20: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start basic read test */
91 dht20_interface_debug_print("dht20: start read test.\n");
92
93 /* dht20 init */
94 res = dht20_init(&gs_handle);
95 if (res != 0)
96 {
97 dht20_interface_debug_print("dht20: init failed.\n");
98
99 return 1;
100 }
101
102 /* delay 2000 ms for read */
104 for (i = 0; i < times; i++)
105 {
106 /* read temperature and humidity */
107 res = dht20_read_temperature_humidity(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature, (uint32_t *)&humidity_raw, (uint8_t *)&humidity);
108 if (res != 0)
109 {
110 dht20_interface_debug_print("dht20: read failed.\n");
111 (void)dht20_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* print result */
117 dht20_interface_debug_print("dht20: temperature: %.01fC.\n", temperature);
118 dht20_interface_debug_print("dht20: humidity: %d%%.\n", humidity);
119
120 /* delay 2000 ms*/
122 }
123
124 /* finish basic read test and exit */
125 dht20_interface_debug_print("dht20: finish read test.\n");
126 (void)dht20_deinit(&gs_handle);
127
128 return 0;
129}
driver dht20 read test header file
struct dht20_handle_s dht20_handle_t
dht20 handle structure definition
uint8_t dht20_deinit(dht20_handle_t *handle)
close the chip
uint8_t dht20_init(dht20_handle_t *handle)
initialize the chip
struct dht20_info_s dht20_info_t
dht20 information structure definition
uint8_t dht20_info(dht20_info_t *info)
get chip's information
uint8_t dht20_read_temperature_humidity(dht20_handle_t *handle, uint32_t *temperature_raw, float *temperature_s, uint32_t *humidity_raw, uint8_t *humidity_s)
read the temperature and humidity data
void dht20_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t dht20_interface_iic_init(void)
interface iic bus init
uint8_t dht20_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
void dht20_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t dht20_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t dht20_interface_iic_deinit(void)
interface iic bus deinit
uint8_t dht20_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]