LibDriver HTU31D
Loading...
Searching...
No Matches
driver_htu31d_read_test.c
Go to the documentation of this file.
1
36
38
39static htu31d_handle_t gs_handle;
40
50uint8_t htu31d_read_test(htu31d_addr_pin_t addr_pin, uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 htu31d_info_t info;
55
56 /* link functions */
64
65 /* htu31d info */
66 res = htu31d_info(&info);
67 if (res != 0)
68 {
69 htu31d_interface_debug_print("htu31d: get info failed.\n");
70
71 return 1;
72 }
73 else
74 {
75 /* print chip information */
76 htu31d_interface_debug_print("htu31d: chip is %s.\n", info.chip_name);
77 htu31d_interface_debug_print("htu31d: manufacturer is %s.\n", info.manufacturer_name);
78 htu31d_interface_debug_print("htu31d: interface is %s.\n", info.interface);
79 htu31d_interface_debug_print("htu31d: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
80 htu31d_interface_debug_print("htu31d: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
81 htu31d_interface_debug_print("htu31d: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
82 htu31d_interface_debug_print("htu31d: max current is %0.2fmA.\n", info.max_current_ma);
83 htu31d_interface_debug_print("htu31d: max temperature is %0.1fC.\n", info.temperature_max);
84 htu31d_interface_debug_print("htu31d: min temperature is %0.1fC.\n", info.temperature_min);
85 }
86
87 /* start read test */
88 htu31d_interface_debug_print("htu31d: start read test.\n");
89
90 /* set addr pin */
91 res = htu31d_set_addr_pin(&gs_handle, addr_pin);
92 if (res != 0)
93 {
94 htu31d_interface_debug_print("htu31d: set addr pin failed.\n");
95
96 return 1;
97 }
98
99 /* init */
100 res = htu31d_init(&gs_handle);
101 if (res != 0)
102 {
103 htu31d_interface_debug_print("htu31d: init failed.\n");
104
105 return 1;
106 }
107
108 /* disable heater */
109 res = htu31d_set_heater_off(&gs_handle);
110 if (res != 0)
111 {
112 htu31d_interface_debug_print("htu31d: set heater off failed.\n");
113 (void)htu31d_deinit(&gs_handle);
114
115 return 1;
116 }
117
118 /* set very high */
120 if (res != 0)
121 {
122 htu31d_interface_debug_print("htu31d: set humidity osr failed.\n");
123 (void)htu31d_deinit(&gs_handle);
124
125 return 1;
126 }
127
128 /* set very high */
130 if (res != 0)
131 {
132 htu31d_interface_debug_print("htu31d: set temperature osr failed.\n");
133 (void)htu31d_deinit(&gs_handle);
134
135 return 1;
136 }
137
138 /* output */
139 htu31d_interface_debug_print("htu31d: set humidity osr very high.\n");
140 htu31d_interface_debug_print("htu31d: set temperature osr very high.\n");
141
142 for (i = 0; i < times; i++)
143 {
144 uint16_t temperature_raw;
145 float temperature_s;
146 uint16_t humidity_raw;
147 float humidity_s;
148
149 res = htu31d_read_temperature_humidity(&gs_handle,
150 &temperature_raw, &temperature_s,
151 &humidity_raw, &humidity_s
152 );
153 if (res != 0)
154 {
155 htu31d_interface_debug_print("htu31d: read temperature humidity failed.\n");
156 (void)htu31d_deinit(&gs_handle);
157
158 return 1;
159 }
160
161 /* output */
162 htu31d_interface_debug_print("htu31d: temperature is %0.2fC.\n", temperature_s);
163 htu31d_interface_debug_print("htu31d: humidity is %0.2f%%.\n", humidity_s);
164
165 /* delay 2000ms */
167 }
168
169 /* set low */
171 if (res != 0)
172 {
173 htu31d_interface_debug_print("htu31d: set humidity osr failed.\n");
174 (void)htu31d_deinit(&gs_handle);
175
176 return 1;
177 }
178
179 /* set low */
181 if (res != 0)
182 {
183 htu31d_interface_debug_print("htu31d: set temperature osr failed.\n");
184 (void)htu31d_deinit(&gs_handle);
185
186 return 1;
187 }
188
189 /* output */
190 htu31d_interface_debug_print("htu31d: set humidity osr low.\n");
191 htu31d_interface_debug_print("htu31d: set temperature osr low.\n");
192
193 for (i = 0; i < times; i++)
194 {
195 uint16_t humidity_raw;
196 float humidity_s;
197
198 res = htu31d_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
199 if (res != 0)
200 {
201 htu31d_interface_debug_print("htu31d: read humidity failed.\n");
202 (void)htu31d_deinit(&gs_handle);
203
204 return 1;
205 }
206
207 /* output */
208 htu31d_interface_debug_print("htu31d: humidity is %0.2f%%.\n", humidity_s);
209
210 /* delay 2000ms */
212 }
213
214 /* finish read test */
215 htu31d_interface_debug_print("htu31d: finish read test.\n");
216 (void)htu31d_deinit(&gs_handle);
217
218 return 0;
219}
driver htu31d read test header file
uint8_t htu31d_set_addr_pin(htu31d_handle_t *handle, htu31d_addr_pin_t addr_pin)
set the address pin
struct htu31d_info_s htu31d_info_t
htu31d information structure definition
uint8_t htu31d_deinit(htu31d_handle_t *handle)
close the chip
uint8_t htu31d_read_humidity(htu31d_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read the humidity data
htu31d_addr_pin_t
htu31d addr pin enumeration definition
uint8_t htu31d_init(htu31d_handle_t *handle)
initialize the chip
uint8_t htu31d_set_heater_off(htu31d_handle_t *handle)
disable heater
uint8_t htu31d_read_temperature_humidity(htu31d_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read the temperature and humidity data
uint8_t htu31d_info(htu31d_info_t *info)
get chip's information
uint8_t htu31d_set_temperature_osr(htu31d_handle_t *handle, htu31d_temperature_osr_t osr)
set temperature osr
struct htu31d_handle_s htu31d_handle_t
htu31d handle structure definition
uint8_t htu31d_set_humidity_osr(htu31d_handle_t *handle, htu31d_humidity_osr_t osr)
set humidity osr
@ HTU31D_HUMIDITY_OSR_LOW
@ HTU31D_HUMIDITY_OSR_VERY_HIGH
@ HTU31D_TEMPERATURE_OSR_VERY_HIGH
@ HTU31D_TEMPERATURE_OSR_LOW
uint8_t htu31d_interface_iic_deinit(void)
interface iic bus deinit
uint8_t htu31d_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void htu31d_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t htu31d_interface_iic_init(void)
interface iic bus init
void htu31d_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t htu31d_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t htu31d_read_test(htu31d_addr_pin_t addr_pin, uint32_t times)
read test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]