LibDriver HDC302X
Loading...
Searching...
No Matches
driver_hdc302x_interrupt.c
Go to the documentation of this file.
1
36
38
39static hdc302x_handle_t gs_handle;
40
49{
50 if (hdc302x_irq_handler(&gs_handle) != 0)
51 {
52 return 1;
53 }
54
55 return 0;
56}
57
72 float temperature_low_deg, float temperature_high_deg,
73 float humidity_low_percentage, float humidity_high_percentage,
74 void (*callback)(uint16_t type))
75{
76 uint8_t res;
77 uint16_t threshold;
78
79 /* link interface function */
87 DRIVER_HDC302X_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
88
89 /* set addr */
90 res = hdc302x_set_addr(&gs_handle, addr);
91 if (res != 0)
92 {
93 hdc302x_interface_debug_print("hdc302x: set addr pin failed.\n");
94
95 return 1;
96 }
97
98 /* hdc302x init */
99 res = hdc302x_init(&gs_handle);
100 if (res != 0)
101 {
102 hdc302x_interface_debug_print("hdc302x: init failed.\n");
103
104 return 1;
105 }
106
107 /* set default low power mode */
109 if (res != 0)
110 {
111 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
112 (void)hdc302x_deinit(&gs_handle);
113
114 return 1;
115 }
116
117 /* set default auto mode */
119 if (res != 0)
120 {
121 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
122 (void)hdc302x_deinit(&gs_handle);
123
124 return 1;
125 }
126
127#if (HDC302X_INTERRUPT_DEFAULT_HEATER != 0)
128 /* enable heater */
129 res = hdc302x_enable_heater(&gs_handle);
130 if (res != 0)
131 {
132 hdc302x_interface_debug_print("hdc302x: enable heater failed.\n");
133 (void)hdc302x_deinit(&gs_handle);
134
135 return 1;
136 }
137#else
138 /* disable heater */
139 res = hdc302x_disable_heater(&gs_handle);
140 if (res != 0)
141 {
142 hdc302x_interface_debug_print("hdc302x: disable heater failed.\n");
143 (void)hdc302x_deinit(&gs_handle);
144
145 return 1;
146 }
147#endif
148
149 /* set default heater power */
151 if (res != 0)
152 {
153 hdc302x_interface_debug_print("hdc302x: set heater power failed.\n");
154 (void)hdc302x_deinit(&gs_handle);
155
156 return 1;
157 }
158
159 /* alert threshold convert to register */
160 res = hdc302x_alert_threshold_convert_to_register(&gs_handle, temperature_low_deg, humidity_low_percentage, &threshold);
161 if (res != 0)
162 {
163 hdc302x_interface_debug_print("hdc302x: alert threshold convert to register failed.\n");
164 (void)hdc302x_deinit(&gs_handle);
165
166 return 1;
167 }
168
169 /* write set low alert */
170 res = hdc302x_write_set_low_alert(&gs_handle, threshold);
171 if (res != 0)
172 {
173 hdc302x_interface_debug_print("hdc302x: write set low alert failed.\n");
174 (void)hdc302x_deinit(&gs_handle);
175
176 return 1;
177 }
178
179 /* alert threshold convert to register */
180 res = hdc302x_alert_threshold_convert_to_register(&gs_handle, temperature_low_deg + 1.0f, humidity_low_percentage + 1.0f, &threshold);
181 if (res != 0)
182 {
183 hdc302x_interface_debug_print("hdc302x: alert threshold convert to register failed.\n");
184 (void)hdc302x_deinit(&gs_handle);
185
186 return 1;
187 }
188
189 /* write clear low alert */
190 res = hdc302x_write_clear_low_alert(&gs_handle, threshold);
191 if (res != 0)
192 {
193 hdc302x_interface_debug_print("hdc302x: write clear low alert failed.\n");
194 (void)hdc302x_deinit(&gs_handle);
195
196 return 1;
197 }
198
199 /* alert threshold convert to register */
200 res = hdc302x_alert_threshold_convert_to_register(&gs_handle, temperature_high_deg, humidity_high_percentage, &threshold);
201 if (res != 0)
202 {
203 hdc302x_interface_debug_print("hdc302x: alert threshold convert to register failed.\n");
204 (void)hdc302x_deinit(&gs_handle);
205
206 return 1;
207 }
208
209 /* write set high alert */
210 res = hdc302x_write_set_high_alert(&gs_handle, threshold);
211 if (res != 0)
212 {
213 hdc302x_interface_debug_print("hdc302x: write set high alert failed.\n");
214 (void)hdc302x_deinit(&gs_handle);
215
216 return 1;
217 }
218
219 /* check humidity high percentage */
220 if (humidity_high_percentage - 1.0f < 0.0f)
221 {
222 hdc302x_interface_debug_print("hdc302x: humidity_high_percentage < 1.0f.\n");
223 (void)hdc302x_deinit(&gs_handle);
224
225 return 1;
226 }
227
228 /* alert threshold convert to register */
229 res = hdc302x_alert_threshold_convert_to_register(&gs_handle, temperature_high_deg - 1.0f, humidity_high_percentage - 1.0f, &threshold);
230 if (res != 0)
231 {
232 hdc302x_interface_debug_print("hdc302x: alert threshold convert to register failed.\n");
233 (void)hdc302x_deinit(&gs_handle);
234
235 return 1;
236 }
237
238 /* write clear high alert */
239 res = hdc302x_write_clear_high_alert(&gs_handle, threshold);
240 if (res != 0)
241 {
242 hdc302x_interface_debug_print("hdc302x: write clear high alert failed.\n");
243 (void)hdc302x_deinit(&gs_handle);
244
245 return 1;
246 }
247
248 /* clear status */
249 res = hdc302x_clear_status(&gs_handle);
250 if (res != 0)
251 {
252 hdc302x_interface_debug_print("hdc302x: clear status failed.\n");
253 (void)hdc302x_deinit(&gs_handle);
254
255 return 1;
256 }
257
258 /* start continuous read */
259 res = hdc302x_start_continuous_read(&gs_handle);
260 if (res != 0)
261 {
262 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
263 (void)hdc302x_deinit(&gs_handle);
264
265 return 1;
266 }
267
268 return 0;
269}
270
280uint8_t hdc302x_interrupt_read(float *temperature, float *humidity)
281{
282 uint16_t temperature_raw;
283 uint16_t humidity_raw;
284
285 /* read data */
286 if (hdc302x_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, temperature,
287 (uint16_t *)&humidity_raw, humidity) != 0)
288 {
289 return 1;
290 }
291
292 return 0;
293}
294
304{
305 uint16_t humidity_raw;
306
307 /* read data */
308 if (hdc302x_read_humidity_min(&gs_handle, (uint16_t *)&humidity_raw, humidity) != 0)
309 {
310 return 1;
311 }
312
313 return 0;
314}
315
325{
326 uint16_t humidity_raw;
327
328 /* read data */
329 if (hdc302x_read_humidity_max(&gs_handle, (uint16_t *)&humidity_raw, humidity) != 0)
330 {
331 return 1;
332 }
333
334 return 0;
335}
336
345uint8_t hdc302x_interrupt_read_temperature_min(float *temperature)
346{
347 uint16_t temperature_raw;
348
349 /* read data */
350 if (hdc302x_read_temperature_min(&gs_handle, &temperature_raw, temperature) != 0)
351 {
352 return 1;
353 }
354
355 return 0;
356}
357
366uint8_t hdc302x_interrupt_read_temperature_max(float *temperature)
367{
368 uint16_t temperature_raw;
369
370 /* read data */
371 if (hdc302x_read_temperature_max(&gs_handle, &temperature_raw, temperature) != 0)
372 {
373 return 1;
374 }
375
376 return 0;
377}
378
387{
388 /* stop continuous read */
389 if (hdc302x_stop_continuous_read(&gs_handle) != 0)
390 {
391 return 1;
392 }
393
394 /* close hdc302x */
395 if (hdc302x_deinit(&gs_handle) != 0)
396 {
397 return 1;
398 }
399
400 return 0;
401}
402
411{
412 /* soft reset */
413 if (hdc302x_soft_reset(&gs_handle) != 0)
414 {
415 return 1;
416 }
417
418 return 0;
419}
420
429uint8_t hdc302x_interrupt_get_nist_id(uint8_t id[6])
430{
431 /* get nist id */
432 if (hdc302x_get_nist_id(&gs_handle, id) != 0)
433 {
434 return 1;
435 }
436
437 return 0;
438}
439
448{
449 /* clear status */
450 if (hdc302x_clear_status(&gs_handle) != 0)
451 {
452 return 1;
453 }
454
455 return 0;
456}
driver hdc302x interrupt header file
uint8_t hdc302x_continuous_read(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
continuous read
uint8_t hdc302x_disable_heater(hdc302x_handle_t *handle)
disable heater
uint8_t hdc302x_set_heater_power(hdc302x_handle_t *handle, uint16_t power)
set heater power
uint8_t hdc302x_enable_heater(hdc302x_handle_t *handle)
enable heater
uint8_t hdc302x_set_addr(hdc302x_handle_t *handle, hdc302x_address_t addr)
set the iic address
uint8_t hdc302x_deinit(hdc302x_handle_t *handle)
close the chip
hdc302x_address_t
hdc302x address enumeration definition
uint8_t hdc302x_irq_handler(hdc302x_handle_t *handle)
irq handler
uint8_t hdc302x_set_low_power_mode(hdc302x_handle_t *handle, hdc302x_low_power_mode_t mode)
set low power mode
uint8_t hdc302x_get_nist_id(hdc302x_handle_t *handle, uint8_t id[6])
get nist id
uint8_t hdc302x_read_temperature_min(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read temperature min
uint8_t hdc302x_set_auto_mode(hdc302x_handle_t *handle, hdc302x_auto_mode_t mode)
set auto mode
uint8_t hdc302x_alert_threshold_convert_to_register(hdc302x_handle_t *handle, float temperature_deg, float humidity_percentage, uint16_t *reg)
convert the alert threshold to the register raw data
uint8_t hdc302x_read_humidity_min(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read humidity min
uint8_t hdc302x_init(hdc302x_handle_t *handle)
initialize the chip
uint8_t hdc302x_write_clear_low_alert(hdc302x_handle_t *handle, uint16_t threshold)
write clear low alert
uint8_t hdc302x_clear_status(hdc302x_handle_t *handle)
clear status
uint8_t hdc302x_write_set_low_alert(hdc302x_handle_t *handle, uint16_t threshold)
write set low alert
uint8_t hdc302x_read_temperature_max(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read temperature max
uint8_t hdc302x_stop_continuous_read(hdc302x_handle_t *handle)
stop continuous read
struct hdc302x_handle_s hdc302x_handle_t
hdc302x handle structure definition
uint8_t hdc302x_soft_reset(hdc302x_handle_t *handle)
soft reset
uint8_t hdc302x_read_humidity_max(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read humidity max
uint8_t hdc302x_start_continuous_read(hdc302x_handle_t *handle)
start continuous read
uint8_t hdc302x_write_clear_high_alert(hdc302x_handle_t *handle, uint16_t threshold)
write clear high alert
uint8_t hdc302x_write_set_high_alert(hdc302x_handle_t *handle, uint16_t threshold)
write set high alert
uint8_t hdc302x_interrupt_irq_handler(void)
interrupt test irq
uint8_t hdc302x_interrupt_read(float *temperature, float *humidity)
interrupt example read
uint8_t hdc302x_interrupt_read_temperature_min(float *temperature)
interrupt example read temperature min
uint8_t hdc302x_interrupt_clear_status(void)
interrupt example clear status
#define HDC302X_INTERRUPT_DEFAULT_LOW_POWER_MODE
hdc302x interrupt example default definition
uint8_t hdc302x_interrupt_get_nist_id(uint8_t id[6])
interrupt example get nist id
#define HDC302X_INTERRUPT_DEFAULT_AUTO_MODE
uint8_t hdc302x_interrupt_init(hdc302x_address_t addr, float temperature_low_deg, float temperature_high_deg, float humidity_low_percentage, float humidity_high_percentage, void(*callback)(uint16_t type))
interrupt example init
#define HDC302X_INTERRUPT_DEFAULT_HEATER_POWER
uint8_t hdc302x_interrupt_read_humidity_min(float *humidity)
interrupt example read humidity min
uint8_t hdc302x_interrupt_soft_reset(void)
interrupt example soft reset
uint8_t hdc302x_interrupt_deinit(void)
interrupt example deinit
uint8_t hdc302x_interrupt_read_humidity_max(float *humidity)
interrupt example read humidity max
uint8_t hdc302x_interrupt_read_temperature_max(float *temperature)
interrupt example read temperature max
uint8_t hdc302x_interface_iic_write_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus write address16
void hdc302x_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t hdc302x_interface_iic_init(void)
interface iic bus init
uint8_t hdc302x_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read address16
void hdc302x_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hdc302x_interface_iic_deinit(void)
interface iic bus deinit