LibDriver HDC302X
Loading...
Searching...
No Matches
driver_hdc302x_read_test.c
Go to the documentation of this file.
1
36
38
39static hdc302x_handle_t gs_handle;
40
50uint8_t hdc302x_read_test(hdc302x_address_t addr, uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 uint16_t temperature_raw;
55 float temperature_s;
56 uint16_t humidity_raw;
57 float humidity_s;
58 hdc302x_info_t info;
59
60 /* link functions */
69
70 /* hdc302x info */
71 res = hdc302x_info(&info);
72 if (res != 0)
73 {
74 hdc302x_interface_debug_print("hdc302x: get info failed.\n");
75
76 return 1;
77 }
78 else
79 {
80 /* print chip information */
81 hdc302x_interface_debug_print("hdc302x: chip is %s.\n", info.chip_name);
82 hdc302x_interface_debug_print("hdc302x: manufacturer is %s.\n", info.manufacturer_name);
83 hdc302x_interface_debug_print("hdc302x: interface is %s.\n", info.interface);
84 hdc302x_interface_debug_print("hdc302x: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
85 hdc302x_interface_debug_print("hdc302x: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
86 hdc302x_interface_debug_print("hdc302x: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
87 hdc302x_interface_debug_print("hdc302x: max current is %0.2fmA.\n", info.max_current_ma);
88 hdc302x_interface_debug_print("hdc302x: max temperature is %0.1fC.\n", info.temperature_max);
89 hdc302x_interface_debug_print("hdc302x: min temperature is %0.1fC.\n", info.temperature_min);
90 }
91
92 /* start read test */
93 hdc302x_interface_debug_print("hdc302x: start read test.\n");
94
95 /* set address */
96 res = hdc302x_set_addr(&gs_handle, addr);
97 if (res != 0)
98 {
99 hdc302x_interface_debug_print("hdc302x: set addr failed.\n");
100
101 return 1;
102 }
103
104 /* hdc302x init */
105 res = hdc302x_init(&gs_handle);
106 if (res != 0)
107 {
108 hdc302x_interface_debug_print("hdc302x: init failed.\n");
109
110 return 1;
111 }
112
113 /* single read test */
114 hdc302x_interface_debug_print("hdc302x: single read test.\n");
115
116 /* set low power mode 0 */
118 if (res != 0)
119 {
120 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
121 (void)hdc302x_deinit(&gs_handle);
122
123 return 1;
124 }
125 hdc302x_interface_debug_print("hdc302x: set low power mode 0.\n");
126
127 /* read data */
128 res = hdc302x_single_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
129 if (res != 0)
130 {
131 hdc302x_interface_debug_print("hdc302x: read failed.\n");
132 (void)hdc302x_deinit(&gs_handle);
133
134 return 1;
135 }
136
137 /* loop */
138 for (i = 0; i < times; i++)
139 {
140 /* read data */
141 res = hdc302x_single_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
142 if (res != 0)
143 {
144 hdc302x_interface_debug_print("hdc302x: read failed.\n");
145 (void)hdc302x_deinit(&gs_handle);
146
147 return 1;
148 }
149 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
150 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
151
152 /* wait 1000 ms */
154 }
155
156 /* set low power mode 1 */
158 if (res != 0)
159 {
160 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
161 (void)hdc302x_deinit(&gs_handle);
162
163 return 1;
164 }
165 hdc302x_interface_debug_print("hdc302x: set low power mode 1.\n");
166
167 /* loop */
168 for (i = 0; i < times; i++)
169 {
170 /* read data */
171 res = hdc302x_single_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
172 if (res != 0)
173 {
174 hdc302x_interface_debug_print("hdc302x: read failed.\n");
175 (void)hdc302x_deinit(&gs_handle);
176
177 return 1;
178 }
179 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
180 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
181
182 /* wait 1000 ms */
184 }
185
186 /* set low power mode 2 */
188 if (res != 0)
189 {
190 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
191 (void)hdc302x_deinit(&gs_handle);
192
193 return 1;
194 }
195 hdc302x_interface_debug_print("hdc302x: set low power mode 2.\n");
196
197 /* loop */
198 for (i = 0; i < times; i++)
199 {
200 /* read data */
201 res = hdc302x_single_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
202 if (res != 0)
203 {
204 hdc302x_interface_debug_print("hdc302x: read failed.\n");
205 (void)hdc302x_deinit(&gs_handle);
206
207 return 1;
208 }
209 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
210 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
211
212 /* wait 1000 ms */
214 }
215
216 /* set low power mode 3 */
218 if (res != 0)
219 {
220 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
221 (void)hdc302x_deinit(&gs_handle);
222
223 return 1;
224 }
225 hdc302x_interface_debug_print("hdc302x: set low power mode 3.\n");
226
227 /* loop */
228 for (i = 0; i < times; i++)
229 {
230 /* read data */
231 res = hdc302x_single_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
232 if (res != 0)
233 {
234 hdc302x_interface_debug_print("hdc302x: read failed.\n");
235 (void)hdc302x_deinit(&gs_handle);
236
237 return 1;
238 }
239 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
240 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
241
242 /* wait 1000 ms */
244 }
245
246 /* continuous read test */
247 hdc302x_interface_debug_print("hdc302x: continuous read test.\n");
248
249 /* set low power mode 0 */
251 if (res != 0)
252 {
253 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
254 (void)hdc302x_deinit(&gs_handle);
255
256 return 1;
257 }
258 hdc302x_interface_debug_print("hdc302x: set low power mode 0.\n");
259
260 /* set auto mode 0.5Hz */
262 if (res != 0)
263 {
264 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
265 (void)hdc302x_deinit(&gs_handle);
266
267 return 1;
268 }
269 hdc302x_interface_debug_print("hdc302x: set auto mode 0.5Hz.\n");
270
271 /* start continuous read */
272 res = hdc302x_start_continuous_read(&gs_handle);
273 if (res != 0)
274 {
275 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
276 (void)hdc302x_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* wait 2000 ms */
283
284 /* loop */
285 for (i = 0; i < times; i++)
286 {
287 /* read data */
288 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
289 if (res != 0)
290 {
291 hdc302x_interface_debug_print("hdc302x: read failed.\n");
292 (void)hdc302x_deinit(&gs_handle);
293
294 return 1;
295 }
296 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
297 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
298
299 /* continuous read humidity */
300 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
301 if (res != 0)
302 {
303 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
304 (void)hdc302x_deinit(&gs_handle);
305
306 return 1;
307 }
308 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
309
310 /* read temperature min */
311 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
312 if (res != 0)
313 {
314 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
315 (void)hdc302x_deinit(&gs_handle);
316
317 return 1;
318 }
319 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
320
321 /* read temperature max */
322 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
323 if (res != 0)
324 {
325 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
326 (void)hdc302x_deinit(&gs_handle);
327
328 return 1;
329 }
330 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
331
332 /* read humidity min */
333 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
334 if (res != 0)
335 {
336 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
337 (void)hdc302x_deinit(&gs_handle);
338
339 return 1;
340 }
341 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
342
343 /* read humidity max */
344 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
345 if (res != 0)
346 {
347 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
348 (void)hdc302x_deinit(&gs_handle);
349
350 return 1;
351 }
352 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
353
354 /* wait 2000 ms */
356 }
357
358 /* stop continuous read */
359 res = hdc302x_stop_continuous_read(&gs_handle);
360 if (res != 0)
361 {
362 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
363 (void)hdc302x_deinit(&gs_handle);
364
365 return 1;
366 }
367
368 /* wait 500 ms */
370
371 /* set auto mode 1Hz */
373 if (res != 0)
374 {
375 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
376 (void)hdc302x_deinit(&gs_handle);
377
378 return 1;
379 }
380 hdc302x_interface_debug_print("hdc302x: set auto mode 1Hz.\n");
381
382 /* start continuous read */
383 res = hdc302x_start_continuous_read(&gs_handle);
384 if (res != 0)
385 {
386 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
387 (void)hdc302x_deinit(&gs_handle);
388
389 return 1;
390 }
391
392 /* wait 500 ms */
394
395 /* loop */
396 for (i = 0; i < times; i++)
397 {
398 /* read data */
399 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
400 if (res != 0)
401 {
402 hdc302x_interface_debug_print("hdc302x: read failed.\n");
403 (void)hdc302x_deinit(&gs_handle);
404
405 return 1;
406 }
407 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
408 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
409
410 /* continuous read humidity */
411 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
412 if (res != 0)
413 {
414 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
415 (void)hdc302x_deinit(&gs_handle);
416
417 return 1;
418 }
419 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
420
421 /* read temperature min */
422 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
423 if (res != 0)
424 {
425 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
426 (void)hdc302x_deinit(&gs_handle);
427
428 return 1;
429 }
430 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
431
432 /* read temperature max */
433 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
434 if (res != 0)
435 {
436 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
437 (void)hdc302x_deinit(&gs_handle);
438
439 return 1;
440 }
441 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
442
443 /* read humidity min */
444 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
445 if (res != 0)
446 {
447 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
448 (void)hdc302x_deinit(&gs_handle);
449
450 return 1;
451 }
452 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
453
454 /* read humidity max */
455 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
456 if (res != 0)
457 {
458 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
459 (void)hdc302x_deinit(&gs_handle);
460
461 return 1;
462 }
463 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
464
465 /* wait 1000 ms */
467 }
468
469 /* stop continuous read */
470 res = hdc302x_stop_continuous_read(&gs_handle);
471 if (res != 0)
472 {
473 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
474 (void)hdc302x_deinit(&gs_handle);
475
476 return 1;
477 }
478
479 /* wait 500 ms */
481
482 /* set auto mode 2Hz */
484 if (res != 0)
485 {
486 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
487 (void)hdc302x_deinit(&gs_handle);
488
489 return 1;
490 }
491 hdc302x_interface_debug_print("hdc302x: set auto mode 2Hz.\n");
492
493 /* start continuous read */
494 res = hdc302x_start_continuous_read(&gs_handle);
495 if (res != 0)
496 {
497 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
498 (void)hdc302x_deinit(&gs_handle);
499
500 return 1;
501 }
502
503 /* wait 500 ms */
505
506 /* loop */
507 for (i = 0; i < times; i++)
508 {
509 /* read data */
510 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
511 if (res != 0)
512 {
513 hdc302x_interface_debug_print("hdc302x: read failed.\n");
514 (void)hdc302x_deinit(&gs_handle);
515
516 return 1;
517 }
518 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
519 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
520
521 /* continuous read humidity */
522 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
523 if (res != 0)
524 {
525 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
526 (void)hdc302x_deinit(&gs_handle);
527
528 return 1;
529 }
530 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
531
532 /* read temperature min */
533 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
534 if (res != 0)
535 {
536 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
537 (void)hdc302x_deinit(&gs_handle);
538
539 return 1;
540 }
541 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
542
543 /* read temperature max */
544 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
545 if (res != 0)
546 {
547 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
548 (void)hdc302x_deinit(&gs_handle);
549
550 return 1;
551 }
552 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
553
554 /* read humidity min */
555 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
556 if (res != 0)
557 {
558 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
559 (void)hdc302x_deinit(&gs_handle);
560
561 return 1;
562 }
563 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
564
565 /* read humidity max */
566 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
567 if (res != 0)
568 {
569 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
570 (void)hdc302x_deinit(&gs_handle);
571
572 return 1;
573 }
574 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
575
576 /* wait 1000 ms */
578 }
579
580 /* stop continuous read */
581 res = hdc302x_stop_continuous_read(&gs_handle);
582 if (res != 0)
583 {
584 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
585 (void)hdc302x_deinit(&gs_handle);
586
587 return 1;
588 }
589
590 /* wait 500 ms */
592
593 /* set auto mode 4Hz */
595 if (res != 0)
596 {
597 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
598 (void)hdc302x_deinit(&gs_handle);
599
600 return 1;
601 }
602 hdc302x_interface_debug_print("hdc302x: set auto mode 4Hz.\n");
603
604 /* start continuous read */
605 res = hdc302x_start_continuous_read(&gs_handle);
606 if (res != 0)
607 {
608 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
609 (void)hdc302x_deinit(&gs_handle);
610
611 return 1;
612 }
613
614 /* wait 500 ms */
616
617 /* loop */
618 for (i = 0; i < times; i++)
619 {
620 /* read data */
621 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
622 if (res != 0)
623 {
624 hdc302x_interface_debug_print("hdc302x: read failed.\n");
625 (void)hdc302x_deinit(&gs_handle);
626
627 return 1;
628 }
629 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
630 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
631
632 /* continuous read humidity */
633 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
634 if (res != 0)
635 {
636 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
637 (void)hdc302x_deinit(&gs_handle);
638
639 return 1;
640 }
641 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
642
643 /* read temperature min */
644 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
645 if (res != 0)
646 {
647 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
648 (void)hdc302x_deinit(&gs_handle);
649
650 return 1;
651 }
652 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
653
654 /* read temperature max */
655 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
656 if (res != 0)
657 {
658 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
659 (void)hdc302x_deinit(&gs_handle);
660
661 return 1;
662 }
663 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
664
665 /* read humidity min */
666 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
667 if (res != 0)
668 {
669 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
670 (void)hdc302x_deinit(&gs_handle);
671
672 return 1;
673 }
674 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
675
676 /* read humidity max */
677 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
678 if (res != 0)
679 {
680 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
681 (void)hdc302x_deinit(&gs_handle);
682
683 return 1;
684 }
685 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
686
687 /* wait 1000 ms */
689 }
690
691 /* stop continuous read */
692 res = hdc302x_stop_continuous_read(&gs_handle);
693 if (res != 0)
694 {
695 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
696 (void)hdc302x_deinit(&gs_handle);
697
698 return 1;
699 }
700
701 /* wait 500 ms */
703
704 /* set auto mode 10Hz */
706 if (res != 0)
707 {
708 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
709 (void)hdc302x_deinit(&gs_handle);
710
711 return 1;
712 }
713 hdc302x_interface_debug_print("hdc302x: set auto mode 10Hz.\n");
714
715 /* start continuous read */
716 res = hdc302x_start_continuous_read(&gs_handle);
717 if (res != 0)
718 {
719 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
720 (void)hdc302x_deinit(&gs_handle);
721
722 return 1;
723 }
724
725 /* wait 500 ms */
727
728 /* loop */
729 for (i = 0; i < times; i++)
730 {
731 /* read data */
732 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
733 if (res != 0)
734 {
735 hdc302x_interface_debug_print("hdc302x: read failed.\n");
736 (void)hdc302x_deinit(&gs_handle);
737
738 return 1;
739 }
740 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
741 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
742
743 /* continuous read humidity */
744 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
745 if (res != 0)
746 {
747 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
748 (void)hdc302x_deinit(&gs_handle);
749
750 return 1;
751 }
752 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
753
754 /* read temperature min */
755 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
756 if (res != 0)
757 {
758 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
759 (void)hdc302x_deinit(&gs_handle);
760
761 return 1;
762 }
763 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
764
765 /* read temperature max */
766 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
767 if (res != 0)
768 {
769 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
770 (void)hdc302x_deinit(&gs_handle);
771
772 return 1;
773 }
774 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
775
776 /* read humidity min */
777 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
778 if (res != 0)
779 {
780 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
781 (void)hdc302x_deinit(&gs_handle);
782
783 return 1;
784 }
785 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
786
787 /* read humidity max */
788 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
789 if (res != 0)
790 {
791 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
792 (void)hdc302x_deinit(&gs_handle);
793
794 return 1;
795 }
796 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
797
798 /* wait 1000 ms */
800 }
801
802 /* stop continuous read */
803 res = hdc302x_stop_continuous_read(&gs_handle);
804 if (res != 0)
805 {
806 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
807 (void)hdc302x_deinit(&gs_handle);
808
809 return 1;
810 }
811
812 /* wait 500 ms */
814
815 /* set low power mode 1 */
817 if (res != 0)
818 {
819 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
820 (void)hdc302x_deinit(&gs_handle);
821
822 return 1;
823 }
824 hdc302x_interface_debug_print("hdc302x: set low power mode 1.\n");
825
826 /* set auto mode 0.5Hz */
828 if (res != 0)
829 {
830 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
831 (void)hdc302x_deinit(&gs_handle);
832
833 return 1;
834 }
835 hdc302x_interface_debug_print("hdc302x: set auto mode 0.5Hz.\n");
836
837 /* start continuous read */
838 res = hdc302x_start_continuous_read(&gs_handle);
839 if (res != 0)
840 {
841 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
842 (void)hdc302x_deinit(&gs_handle);
843
844 return 1;
845 }
846
847 /* wait 2000 ms */
849
850 /* loop */
851 for (i = 0; i < times; i++)
852 {
853 /* read data */
854 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
855 if (res != 0)
856 {
857 hdc302x_interface_debug_print("hdc302x: read failed.\n");
858 (void)hdc302x_deinit(&gs_handle);
859
860 return 1;
861 }
862 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
863 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
864
865 /* continuous read humidity */
866 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
867 if (res != 0)
868 {
869 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
870 (void)hdc302x_deinit(&gs_handle);
871
872 return 1;
873 }
874 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
875
876 /* read temperature min */
877 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
878 if (res != 0)
879 {
880 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
881 (void)hdc302x_deinit(&gs_handle);
882
883 return 1;
884 }
885 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
886
887 /* read temperature max */
888 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
889 if (res != 0)
890 {
891 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
892 (void)hdc302x_deinit(&gs_handle);
893
894 return 1;
895 }
896 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
897
898 /* read humidity min */
899 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
900 if (res != 0)
901 {
902 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
903 (void)hdc302x_deinit(&gs_handle);
904
905 return 1;
906 }
907 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
908
909 /* read humidity max */
910 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
911 if (res != 0)
912 {
913 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
914 (void)hdc302x_deinit(&gs_handle);
915
916 return 1;
917 }
918 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
919
920 /* wait 2000 ms */
922 }
923
924 /* stop continuous read */
925 res = hdc302x_stop_continuous_read(&gs_handle);
926 if (res != 0)
927 {
928 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
929 (void)hdc302x_deinit(&gs_handle);
930
931 return 1;
932 }
933
934 /* wait 500 ms */
936
937 /* set auto mode 1Hz */
939 if (res != 0)
940 {
941 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
942 (void)hdc302x_deinit(&gs_handle);
943
944 return 1;
945 }
946 hdc302x_interface_debug_print("hdc302x: set auto mode 1Hz.\n");
947
948 /* start continuous read */
949 res = hdc302x_start_continuous_read(&gs_handle);
950 if (res != 0)
951 {
952 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
953 (void)hdc302x_deinit(&gs_handle);
954
955 return 1;
956 }
957
958 /* wait 500 ms */
960
961 /* loop */
962 for (i = 0; i < times; i++)
963 {
964 /* read data */
965 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
966 if (res != 0)
967 {
968 hdc302x_interface_debug_print("hdc302x: read failed.\n");
969 (void)hdc302x_deinit(&gs_handle);
970
971 return 1;
972 }
973 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
974 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
975
976 /* continuous read humidity */
977 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
978 if (res != 0)
979 {
980 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
981 (void)hdc302x_deinit(&gs_handle);
982
983 return 1;
984 }
985 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
986
987 /* read temperature min */
988 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
989 if (res != 0)
990 {
991 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
992 (void)hdc302x_deinit(&gs_handle);
993
994 return 1;
995 }
996 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
997
998 /* read temperature max */
999 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1000 if (res != 0)
1001 {
1002 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1003 (void)hdc302x_deinit(&gs_handle);
1004
1005 return 1;
1006 }
1007 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1008
1009 /* read humidity min */
1010 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1011 if (res != 0)
1012 {
1013 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1014 (void)hdc302x_deinit(&gs_handle);
1015
1016 return 1;
1017 }
1018 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1019
1020 /* read humidity max */
1021 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1022 if (res != 0)
1023 {
1024 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1025 (void)hdc302x_deinit(&gs_handle);
1026
1027 return 1;
1028 }
1029 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1030
1031 /* wait 1000 ms */
1033 }
1034
1035 /* stop continuous read */
1036 res = hdc302x_stop_continuous_read(&gs_handle);
1037 if (res != 0)
1038 {
1039 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1040 (void)hdc302x_deinit(&gs_handle);
1041
1042 return 1;
1043 }
1044
1045 /* wait 500 ms */
1047
1048 /* set auto mode 2Hz */
1050 if (res != 0)
1051 {
1052 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1053 (void)hdc302x_deinit(&gs_handle);
1054
1055 return 1;
1056 }
1057 hdc302x_interface_debug_print("hdc302x: set auto mode 2Hz.\n");
1058
1059 /* start continuous read */
1060 res = hdc302x_start_continuous_read(&gs_handle);
1061 if (res != 0)
1062 {
1063 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1064 (void)hdc302x_deinit(&gs_handle);
1065
1066 return 1;
1067 }
1068
1069 /* wait 500 ms */
1071
1072 /* loop */
1073 for (i = 0; i < times; i++)
1074 {
1075 /* read data */
1076 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1077 if (res != 0)
1078 {
1079 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1080 (void)hdc302x_deinit(&gs_handle);
1081
1082 return 1;
1083 }
1084 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1085 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1086
1087 /* continuous read humidity */
1088 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1089 if (res != 0)
1090 {
1091 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
1092 (void)hdc302x_deinit(&gs_handle);
1093
1094 return 1;
1095 }
1096 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
1097
1098 /* read temperature min */
1099 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
1100 if (res != 0)
1101 {
1102 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
1103 (void)hdc302x_deinit(&gs_handle);
1104
1105 return 1;
1106 }
1107 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
1108
1109 /* read temperature max */
1110 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1111 if (res != 0)
1112 {
1113 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1114 (void)hdc302x_deinit(&gs_handle);
1115
1116 return 1;
1117 }
1118 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1119
1120 /* read humidity min */
1121 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1122 if (res != 0)
1123 {
1124 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1125 (void)hdc302x_deinit(&gs_handle);
1126
1127 return 1;
1128 }
1129 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1130
1131 /* read humidity max */
1132 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1133 if (res != 0)
1134 {
1135 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1136 (void)hdc302x_deinit(&gs_handle);
1137
1138 return 1;
1139 }
1140 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1141
1142 /* wait 1000 ms */
1144 }
1145
1146 /* stop continuous read */
1147 res = hdc302x_stop_continuous_read(&gs_handle);
1148 if (res != 0)
1149 {
1150 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1151 (void)hdc302x_deinit(&gs_handle);
1152
1153 return 1;
1154 }
1155
1156 /* wait 500 ms */
1158
1159 /* set auto mode 4Hz */
1161 if (res != 0)
1162 {
1163 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1164 (void)hdc302x_deinit(&gs_handle);
1165
1166 return 1;
1167 }
1168 hdc302x_interface_debug_print("hdc302x: set auto mode 4Hz.\n");
1169
1170 /* start continuous read */
1171 res = hdc302x_start_continuous_read(&gs_handle);
1172 if (res != 0)
1173 {
1174 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1175 (void)hdc302x_deinit(&gs_handle);
1176
1177 return 1;
1178 }
1179
1180 /* wait 500 ms */
1182
1183 /* loop */
1184 for (i = 0; i < times; i++)
1185 {
1186 /* read data */
1187 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1188 if (res != 0)
1189 {
1190 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1191 (void)hdc302x_deinit(&gs_handle);
1192
1193 return 1;
1194 }
1195 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1196 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1197
1198 /* continuous read humidity */
1199 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1200 if (res != 0)
1201 {
1202 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
1203 (void)hdc302x_deinit(&gs_handle);
1204
1205 return 1;
1206 }
1207 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
1208
1209 /* read temperature min */
1210 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
1211 if (res != 0)
1212 {
1213 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
1214 (void)hdc302x_deinit(&gs_handle);
1215
1216 return 1;
1217 }
1218 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
1219
1220 /* read temperature max */
1221 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1222 if (res != 0)
1223 {
1224 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1225 (void)hdc302x_deinit(&gs_handle);
1226
1227 return 1;
1228 }
1229 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1230
1231 /* read humidity min */
1232 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1233 if (res != 0)
1234 {
1235 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1236 (void)hdc302x_deinit(&gs_handle);
1237
1238 return 1;
1239 }
1240 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1241
1242 /* read humidity max */
1243 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1244 if (res != 0)
1245 {
1246 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1247 (void)hdc302x_deinit(&gs_handle);
1248
1249 return 1;
1250 }
1251 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1252
1253 /* wait 1000 ms */
1255 }
1256
1257 /* stop continuous read */
1258 res = hdc302x_stop_continuous_read(&gs_handle);
1259 if (res != 0)
1260 {
1261 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1262 (void)hdc302x_deinit(&gs_handle);
1263
1264 return 1;
1265 }
1266
1267 /* wait 500 ms */
1269
1270 /* set auto mode 10Hz */
1272 if (res != 0)
1273 {
1274 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1275 (void)hdc302x_deinit(&gs_handle);
1276
1277 return 1;
1278 }
1279 hdc302x_interface_debug_print("hdc302x: set auto mode 10Hz.\n");
1280
1281 /* start continuous read */
1282 res = hdc302x_start_continuous_read(&gs_handle);
1283 if (res != 0)
1284 {
1285 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1286 (void)hdc302x_deinit(&gs_handle);
1287
1288 return 1;
1289 }
1290
1291 /* wait 500 ms */
1293
1294 /* loop */
1295 for (i = 0; i < times; i++)
1296 {
1297 /* read data */
1298 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1299 if (res != 0)
1300 {
1301 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1302 (void)hdc302x_deinit(&gs_handle);
1303
1304 return 1;
1305 }
1306 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1307 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1308
1309 /* continuous read humidity */
1310 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1311 if (res != 0)
1312 {
1313 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
1314 (void)hdc302x_deinit(&gs_handle);
1315
1316 return 1;
1317 }
1318 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
1319
1320 /* read temperature min */
1321 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
1322 if (res != 0)
1323 {
1324 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
1325 (void)hdc302x_deinit(&gs_handle);
1326
1327 return 1;
1328 }
1329 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
1330
1331 /* read temperature max */
1332 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1333 if (res != 0)
1334 {
1335 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1336 (void)hdc302x_deinit(&gs_handle);
1337
1338 return 1;
1339 }
1340 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1341
1342 /* read humidity min */
1343 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1344 if (res != 0)
1345 {
1346 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1347 (void)hdc302x_deinit(&gs_handle);
1348
1349 return 1;
1350 }
1351 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1352
1353 /* read humidity max */
1354 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1355 if (res != 0)
1356 {
1357 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1358 (void)hdc302x_deinit(&gs_handle);
1359
1360 return 1;
1361 }
1362 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1363
1364 /* wait 1000 ms */
1366 }
1367
1368 /* stop continuous read */
1369 res = hdc302x_stop_continuous_read(&gs_handle);
1370 if (res != 0)
1371 {
1372 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1373 (void)hdc302x_deinit(&gs_handle);
1374
1375 return 1;
1376 }
1377
1378 /* wait 500 ms */
1380
1381 /* set low power mode 2 */
1383 if (res != 0)
1384 {
1385 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
1386 (void)hdc302x_deinit(&gs_handle);
1387
1388 return 1;
1389 }
1390 hdc302x_interface_debug_print("hdc302x: set low power mode 2.\n");
1391
1392 /* set auto mode 0.5Hz */
1394 if (res != 0)
1395 {
1396 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1397 (void)hdc302x_deinit(&gs_handle);
1398
1399 return 1;
1400 }
1401 hdc302x_interface_debug_print("hdc302x: set auto mode 0.5Hz.\n");
1402
1403 /* start continuous read */
1404 res = hdc302x_start_continuous_read(&gs_handle);
1405 if (res != 0)
1406 {
1407 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1408 (void)hdc302x_deinit(&gs_handle);
1409
1410 return 1;
1411 }
1412
1413 /* wait 2000 ms */
1415
1416 /* loop */
1417 for (i = 0; i < times; i++)
1418 {
1419 /* read data */
1420 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1421 if (res != 0)
1422 {
1423 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1424 (void)hdc302x_deinit(&gs_handle);
1425
1426 return 1;
1427 }
1428 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1429 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1430
1431 /* continuous read humidity */
1432 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1433 if (res != 0)
1434 {
1435 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
1436 (void)hdc302x_deinit(&gs_handle);
1437
1438 return 1;
1439 }
1440 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
1441
1442 /* read temperature min */
1443 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
1444 if (res != 0)
1445 {
1446 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
1447 (void)hdc302x_deinit(&gs_handle);
1448
1449 return 1;
1450 }
1451 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
1452
1453 /* read temperature max */
1454 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1455 if (res != 0)
1456 {
1457 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1458 (void)hdc302x_deinit(&gs_handle);
1459
1460 return 1;
1461 }
1462 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1463
1464 /* read humidity min */
1465 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1466 if (res != 0)
1467 {
1468 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1469 (void)hdc302x_deinit(&gs_handle);
1470
1471 return 1;
1472 }
1473 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1474
1475 /* read humidity max */
1476 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1477 if (res != 0)
1478 {
1479 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1480 (void)hdc302x_deinit(&gs_handle);
1481
1482 return 1;
1483 }
1484 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1485
1486 /* wait 2000 ms */
1488 }
1489
1490 /* stop continuous read */
1491 res = hdc302x_stop_continuous_read(&gs_handle);
1492 if (res != 0)
1493 {
1494 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1495 (void)hdc302x_deinit(&gs_handle);
1496
1497 return 1;
1498 }
1499
1500 /* wait 500 ms */
1502
1503 /* set auto mode 1Hz */
1505 if (res != 0)
1506 {
1507 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1508 (void)hdc302x_deinit(&gs_handle);
1509
1510 return 1;
1511 }
1512 hdc302x_interface_debug_print("hdc302x: set auto mode 1Hz.\n");
1513
1514 /* start continuous read */
1515 res = hdc302x_start_continuous_read(&gs_handle);
1516 if (res != 0)
1517 {
1518 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1519 (void)hdc302x_deinit(&gs_handle);
1520
1521 return 1;
1522 }
1523
1524 /* wait 500 ms */
1526
1527 /* loop */
1528 for (i = 0; i < times; i++)
1529 {
1530 /* read data */
1531 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1532 if (res != 0)
1533 {
1534 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1535 (void)hdc302x_deinit(&gs_handle);
1536
1537 return 1;
1538 }
1539 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1540 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1541
1542 /* continuous read humidity */
1543 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1544 if (res != 0)
1545 {
1546 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
1547 (void)hdc302x_deinit(&gs_handle);
1548
1549 return 1;
1550 }
1551 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
1552
1553 /* read temperature min */
1554 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
1555 if (res != 0)
1556 {
1557 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
1558 (void)hdc302x_deinit(&gs_handle);
1559
1560 return 1;
1561 }
1562 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
1563
1564 /* read temperature max */
1565 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1566 if (res != 0)
1567 {
1568 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1569 (void)hdc302x_deinit(&gs_handle);
1570
1571 return 1;
1572 }
1573 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1574
1575 /* read humidity min */
1576 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1577 if (res != 0)
1578 {
1579 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1580 (void)hdc302x_deinit(&gs_handle);
1581
1582 return 1;
1583 }
1584 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1585
1586 /* read humidity max */
1587 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1588 if (res != 0)
1589 {
1590 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1591 (void)hdc302x_deinit(&gs_handle);
1592
1593 return 1;
1594 }
1595 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1596
1597 /* wait 1000 ms */
1599 }
1600
1601 /* stop continuous read */
1602 res = hdc302x_stop_continuous_read(&gs_handle);
1603 if (res != 0)
1604 {
1605 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1606 (void)hdc302x_deinit(&gs_handle);
1607
1608 return 1;
1609 }
1610
1611 /* wait 500 ms */
1613
1614 /* set auto mode 2Hz */
1616 if (res != 0)
1617 {
1618 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1619 (void)hdc302x_deinit(&gs_handle);
1620
1621 return 1;
1622 }
1623 hdc302x_interface_debug_print("hdc302x: set auto mode 2Hz.\n");
1624
1625 /* start continuous read */
1626 res = hdc302x_start_continuous_read(&gs_handle);
1627 if (res != 0)
1628 {
1629 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1630 (void)hdc302x_deinit(&gs_handle);
1631
1632 return 1;
1633 }
1634
1635 /* wait 500 ms */
1637
1638 /* loop */
1639 for (i = 0; i < times; i++)
1640 {
1641 /* read data */
1642 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1643 if (res != 0)
1644 {
1645 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1646 (void)hdc302x_deinit(&gs_handle);
1647
1648 return 1;
1649 }
1650 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1651 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1652
1653 /* continuous read humidity */
1654 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1655 if (res != 0)
1656 {
1657 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
1658 (void)hdc302x_deinit(&gs_handle);
1659
1660 return 1;
1661 }
1662 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
1663
1664 /* read temperature min */
1665 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
1666 if (res != 0)
1667 {
1668 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
1669 (void)hdc302x_deinit(&gs_handle);
1670
1671 return 1;
1672 }
1673 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
1674
1675 /* read temperature max */
1676 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1677 if (res != 0)
1678 {
1679 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1680 (void)hdc302x_deinit(&gs_handle);
1681
1682 return 1;
1683 }
1684 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1685
1686 /* read humidity min */
1687 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1688 if (res != 0)
1689 {
1690 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1691 (void)hdc302x_deinit(&gs_handle);
1692
1693 return 1;
1694 }
1695 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1696
1697 /* read humidity max */
1698 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1699 if (res != 0)
1700 {
1701 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1702 (void)hdc302x_deinit(&gs_handle);
1703
1704 return 1;
1705 }
1706 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1707
1708 /* wait 1000 ms */
1710 }
1711
1712 /* stop continuous read */
1713 res = hdc302x_stop_continuous_read(&gs_handle);
1714 if (res != 0)
1715 {
1716 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1717 (void)hdc302x_deinit(&gs_handle);
1718
1719 return 1;
1720 }
1721
1722 /* wait 500 ms */
1724
1725 /* set auto mode 4Hz */
1727 if (res != 0)
1728 {
1729 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1730 (void)hdc302x_deinit(&gs_handle);
1731
1732 return 1;
1733 }
1734 hdc302x_interface_debug_print("hdc302x: set auto mode 4Hz.\n");
1735
1736 /* start continuous read */
1737 res = hdc302x_start_continuous_read(&gs_handle);
1738 if (res != 0)
1739 {
1740 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1741 (void)hdc302x_deinit(&gs_handle);
1742
1743 return 1;
1744 }
1745
1746 /* wait 500 ms */
1748
1749 /* loop */
1750 for (i = 0; i < times; i++)
1751 {
1752 /* read data */
1753 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1754 if (res != 0)
1755 {
1756 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1757 (void)hdc302x_deinit(&gs_handle);
1758
1759 return 1;
1760 }
1761 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1762 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1763
1764 /* continuous read humidity */
1765 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1766 if (res != 0)
1767 {
1768 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
1769 (void)hdc302x_deinit(&gs_handle);
1770
1771 return 1;
1772 }
1773 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
1774
1775 /* read temperature min */
1776 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
1777 if (res != 0)
1778 {
1779 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
1780 (void)hdc302x_deinit(&gs_handle);
1781
1782 return 1;
1783 }
1784 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
1785
1786 /* read temperature max */
1787 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1788 if (res != 0)
1789 {
1790 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1791 (void)hdc302x_deinit(&gs_handle);
1792
1793 return 1;
1794 }
1795 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1796
1797 /* read humidity min */
1798 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1799 if (res != 0)
1800 {
1801 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1802 (void)hdc302x_deinit(&gs_handle);
1803
1804 return 1;
1805 }
1806 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1807
1808 /* read humidity max */
1809 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1810 if (res != 0)
1811 {
1812 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1813 (void)hdc302x_deinit(&gs_handle);
1814
1815 return 1;
1816 }
1817 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1818
1819 /* wait 1000 ms */
1821 }
1822
1823 /* stop continuous read */
1824 res = hdc302x_stop_continuous_read(&gs_handle);
1825 if (res != 0)
1826 {
1827 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1828 (void)hdc302x_deinit(&gs_handle);
1829
1830 return 1;
1831 }
1832
1833 /* wait 500 ms */
1835
1836 /* set auto mode 10Hz */
1838 if (res != 0)
1839 {
1840 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1841 (void)hdc302x_deinit(&gs_handle);
1842
1843 return 1;
1844 }
1845 hdc302x_interface_debug_print("hdc302x: set auto mode 10Hz.\n");
1846
1847 /* start continuous read */
1848 res = hdc302x_start_continuous_read(&gs_handle);
1849 if (res != 0)
1850 {
1851 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1852 (void)hdc302x_deinit(&gs_handle);
1853
1854 return 1;
1855 }
1856
1857 /* wait 500 ms */
1859
1860 /* loop */
1861 for (i = 0; i < times; i++)
1862 {
1863 /* read data */
1864 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1865 if (res != 0)
1866 {
1867 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1868 (void)hdc302x_deinit(&gs_handle);
1869
1870 return 1;
1871 }
1872 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1873 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1874
1875 /* continuous read humidity */
1876 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1877 if (res != 0)
1878 {
1879 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
1880 (void)hdc302x_deinit(&gs_handle);
1881
1882 return 1;
1883 }
1884 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
1885
1886 /* read temperature min */
1887 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
1888 if (res != 0)
1889 {
1890 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
1891 (void)hdc302x_deinit(&gs_handle);
1892
1893 return 1;
1894 }
1895 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
1896
1897 /* read temperature max */
1898 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
1899 if (res != 0)
1900 {
1901 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
1902 (void)hdc302x_deinit(&gs_handle);
1903
1904 return 1;
1905 }
1906 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
1907
1908 /* read humidity min */
1909 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
1910 if (res != 0)
1911 {
1912 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
1913 (void)hdc302x_deinit(&gs_handle);
1914
1915 return 1;
1916 }
1917 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
1918
1919 /* read humidity max */
1920 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
1921 if (res != 0)
1922 {
1923 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
1924 (void)hdc302x_deinit(&gs_handle);
1925
1926 return 1;
1927 }
1928 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
1929
1930 /* wait 1000 ms */
1932 }
1933
1934 /* stop continuous read */
1935 res = hdc302x_stop_continuous_read(&gs_handle);
1936 if (res != 0)
1937 {
1938 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
1939 (void)hdc302x_deinit(&gs_handle);
1940
1941 return 1;
1942 }
1943
1944 /* wait 500 ms */
1946
1947 /* set low power mode 3 */
1949 if (res != 0)
1950 {
1951 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
1952 (void)hdc302x_deinit(&gs_handle);
1953
1954 return 1;
1955 }
1956 hdc302x_interface_debug_print("hdc302x: set low power mode 3.\n");
1957
1958 /* set auto mode 0.5Hz */
1960 if (res != 0)
1961 {
1962 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
1963 (void)hdc302x_deinit(&gs_handle);
1964
1965 return 1;
1966 }
1967 hdc302x_interface_debug_print("hdc302x: set auto mode 0.5Hz.\n");
1968
1969 /* start continuous read */
1970 res = hdc302x_start_continuous_read(&gs_handle);
1971 if (res != 0)
1972 {
1973 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
1974 (void)hdc302x_deinit(&gs_handle);
1975
1976 return 1;
1977 }
1978
1979 /* wait 2000 ms */
1981
1982 /* loop */
1983 for (i = 0; i < times; i++)
1984 {
1985 /* read data */
1986 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
1987 if (res != 0)
1988 {
1989 hdc302x_interface_debug_print("hdc302x: read failed.\n");
1990 (void)hdc302x_deinit(&gs_handle);
1991
1992 return 1;
1993 }
1994 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
1995 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
1996
1997 /* continuous read humidity */
1998 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
1999 if (res != 0)
2000 {
2001 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
2002 (void)hdc302x_deinit(&gs_handle);
2003
2004 return 1;
2005 }
2006 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
2007
2008 /* read temperature min */
2009 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
2010 if (res != 0)
2011 {
2012 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
2013 (void)hdc302x_deinit(&gs_handle);
2014
2015 return 1;
2016 }
2017 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
2018
2019 /* read temperature max */
2020 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
2021 if (res != 0)
2022 {
2023 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
2024 (void)hdc302x_deinit(&gs_handle);
2025
2026 return 1;
2027 }
2028 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
2029
2030 /* read humidity min */
2031 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
2032 if (res != 0)
2033 {
2034 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
2035 (void)hdc302x_deinit(&gs_handle);
2036
2037 return 1;
2038 }
2039 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
2040
2041 /* read humidity max */
2042 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
2043 if (res != 0)
2044 {
2045 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
2046 (void)hdc302x_deinit(&gs_handle);
2047
2048 return 1;
2049 }
2050 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
2051
2052 /* wait 2000 ms */
2054 }
2055
2056 /* stop continuous read */
2057 res = hdc302x_stop_continuous_read(&gs_handle);
2058 if (res != 0)
2059 {
2060 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
2061 (void)hdc302x_deinit(&gs_handle);
2062
2063 return 1;
2064 }
2065
2066 /* wait 500 ms */
2068
2069 /* set auto mode 1Hz */
2071 if (res != 0)
2072 {
2073 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
2074 (void)hdc302x_deinit(&gs_handle);
2075
2076 return 1;
2077 }
2078 hdc302x_interface_debug_print("hdc302x: set auto mode 1Hz.\n");
2079
2080 /* start continuous read */
2081 res = hdc302x_start_continuous_read(&gs_handle);
2082 if (res != 0)
2083 {
2084 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
2085 (void)hdc302x_deinit(&gs_handle);
2086
2087 return 1;
2088 }
2089
2090 /* wait 500 ms */
2092
2093 /* loop */
2094 for (i = 0; i < times; i++)
2095 {
2096 /* read data */
2097 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
2098 if (res != 0)
2099 {
2100 hdc302x_interface_debug_print("hdc302x: read failed.\n");
2101 (void)hdc302x_deinit(&gs_handle);
2102
2103 return 1;
2104 }
2105 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
2106 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
2107
2108 /* continuous read humidity */
2109 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
2110 if (res != 0)
2111 {
2112 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
2113 (void)hdc302x_deinit(&gs_handle);
2114
2115 return 1;
2116 }
2117 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
2118
2119 /* read temperature min */
2120 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
2121 if (res != 0)
2122 {
2123 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
2124 (void)hdc302x_deinit(&gs_handle);
2125
2126 return 1;
2127 }
2128 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
2129
2130 /* read temperature max */
2131 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
2132 if (res != 0)
2133 {
2134 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
2135 (void)hdc302x_deinit(&gs_handle);
2136
2137 return 1;
2138 }
2139 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
2140
2141 /* read humidity min */
2142 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
2143 if (res != 0)
2144 {
2145 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
2146 (void)hdc302x_deinit(&gs_handle);
2147
2148 return 1;
2149 }
2150 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
2151
2152 /* read humidity max */
2153 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
2154 if (res != 0)
2155 {
2156 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
2157 (void)hdc302x_deinit(&gs_handle);
2158
2159 return 1;
2160 }
2161 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
2162
2163 /* wait 1000 ms */
2165 }
2166
2167 /* stop continuous read */
2168 res = hdc302x_stop_continuous_read(&gs_handle);
2169 if (res != 0)
2170 {
2171 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
2172 (void)hdc302x_deinit(&gs_handle);
2173
2174 return 1;
2175 }
2176
2177 /* wait 500 ms */
2179
2180 /* set auto mode 2Hz */
2182 if (res != 0)
2183 {
2184 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
2185 (void)hdc302x_deinit(&gs_handle);
2186
2187 return 1;
2188 }
2189 hdc302x_interface_debug_print("hdc302x: set auto mode 2Hz.\n");
2190
2191 /* start continuous read */
2192 res = hdc302x_start_continuous_read(&gs_handle);
2193 if (res != 0)
2194 {
2195 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
2196 (void)hdc302x_deinit(&gs_handle);
2197
2198 return 1;
2199 }
2200
2201 /* wait 500 ms */
2203
2204 /* loop */
2205 for (i = 0; i < times; i++)
2206 {
2207 /* read data */
2208 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
2209 if (res != 0)
2210 {
2211 hdc302x_interface_debug_print("hdc302x: read failed.\n");
2212 (void)hdc302x_deinit(&gs_handle);
2213
2214 return 1;
2215 }
2216 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
2217 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
2218
2219 /* continuous read humidity */
2220 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
2221 if (res != 0)
2222 {
2223 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
2224 (void)hdc302x_deinit(&gs_handle);
2225
2226 return 1;
2227 }
2228 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
2229
2230 /* read temperature min */
2231 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
2232 if (res != 0)
2233 {
2234 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
2235 (void)hdc302x_deinit(&gs_handle);
2236
2237 return 1;
2238 }
2239 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
2240
2241 /* read temperature max */
2242 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
2243 if (res != 0)
2244 {
2245 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
2246 (void)hdc302x_deinit(&gs_handle);
2247
2248 return 1;
2249 }
2250 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
2251
2252 /* read humidity min */
2253 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
2254 if (res != 0)
2255 {
2256 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
2257 (void)hdc302x_deinit(&gs_handle);
2258
2259 return 1;
2260 }
2261 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
2262
2263 /* read humidity max */
2264 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
2265 if (res != 0)
2266 {
2267 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
2268 (void)hdc302x_deinit(&gs_handle);
2269
2270 return 1;
2271 }
2272 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
2273
2274 /* wait 1000 ms */
2276 }
2277
2278 /* stop continuous read */
2279 res = hdc302x_stop_continuous_read(&gs_handle);
2280 if (res != 0)
2281 {
2282 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
2283 (void)hdc302x_deinit(&gs_handle);
2284
2285 return 1;
2286 }
2287
2288 /* wait 500 ms */
2290
2291 /* set auto mode 4Hz */
2293 if (res != 0)
2294 {
2295 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
2296 (void)hdc302x_deinit(&gs_handle);
2297
2298 return 1;
2299 }
2300 hdc302x_interface_debug_print("hdc302x: set auto mode 4Hz.\n");
2301
2302 /* start continuous read */
2303 res = hdc302x_start_continuous_read(&gs_handle);
2304 if (res != 0)
2305 {
2306 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
2307 (void)hdc302x_deinit(&gs_handle);
2308
2309 return 1;
2310 }
2311
2312 /* wait 500 ms */
2314
2315 /* loop */
2316 for (i = 0; i < times; i++)
2317 {
2318 /* read data */
2319 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
2320 if (res != 0)
2321 {
2322 hdc302x_interface_debug_print("hdc302x: read failed.\n");
2323 (void)hdc302x_deinit(&gs_handle);
2324
2325 return 1;
2326 }
2327 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
2328 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
2329
2330 /* continuous read humidity */
2331 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
2332 if (res != 0)
2333 {
2334 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
2335 (void)hdc302x_deinit(&gs_handle);
2336
2337 return 1;
2338 }
2339 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
2340
2341 /* read temperature min */
2342 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
2343 if (res != 0)
2344 {
2345 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
2346 (void)hdc302x_deinit(&gs_handle);
2347
2348 return 1;
2349 }
2350 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
2351
2352 /* read temperature max */
2353 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
2354 if (res != 0)
2355 {
2356 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
2357 (void)hdc302x_deinit(&gs_handle);
2358
2359 return 1;
2360 }
2361 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
2362
2363 /* read humidity min */
2364 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
2365 if (res != 0)
2366 {
2367 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
2368 (void)hdc302x_deinit(&gs_handle);
2369
2370 return 1;
2371 }
2372 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
2373
2374 /* read humidity max */
2375 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
2376 if (res != 0)
2377 {
2378 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
2379 (void)hdc302x_deinit(&gs_handle);
2380
2381 return 1;
2382 }
2383 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
2384
2385 /* wait 1000 ms */
2387 }
2388
2389 /* stop continuous read */
2390 res = hdc302x_stop_continuous_read(&gs_handle);
2391 if (res != 0)
2392 {
2393 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
2394 (void)hdc302x_deinit(&gs_handle);
2395
2396 return 1;
2397 }
2398
2399 /* wait 500 ms */
2401
2402 /* set auto mode 10Hz */
2404 if (res != 0)
2405 {
2406 hdc302x_interface_debug_print("hdc302x: set auto mode failed.\n");
2407 (void)hdc302x_deinit(&gs_handle);
2408
2409 return 1;
2410 }
2411 hdc302x_interface_debug_print("hdc302x: set auto mode 10Hz.\n");
2412
2413 /* start continuous read */
2414 res = hdc302x_start_continuous_read(&gs_handle);
2415 if (res != 0)
2416 {
2417 hdc302x_interface_debug_print("hdc302x: start continuous read failed.\n");
2418 (void)hdc302x_deinit(&gs_handle);
2419
2420 return 1;
2421 }
2422
2423 /* wait 500 ms */
2425
2426 /* loop */
2427 for (i = 0; i < times; i++)
2428 {
2429 /* read data */
2430 res = hdc302x_continuous_read(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
2431 if (res != 0)
2432 {
2433 hdc302x_interface_debug_print("hdc302x: read failed.\n");
2434 (void)hdc302x_deinit(&gs_handle);
2435
2436 return 1;
2437 }
2438 hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature_s);
2439 hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity_s);
2440
2441 /* continuous read humidity */
2442 res = hdc302x_continuous_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
2443 if (res != 0)
2444 {
2445 hdc302x_interface_debug_print("hdc302x: continuous read humidity failed.\n");
2446 (void)hdc302x_deinit(&gs_handle);
2447
2448 return 1;
2449 }
2450 hdc302x_interface_debug_print("hdc302x: only humidity is %0.2f%%.\n", humidity_s);
2451
2452 /* read temperature min */
2453 res = hdc302x_read_temperature_min(&gs_handle, &temperature_raw, &temperature_s);
2454 if (res != 0)
2455 {
2456 hdc302x_interface_debug_print("hdc302x: read temperature min failed.\n");
2457 (void)hdc302x_deinit(&gs_handle);
2458
2459 return 1;
2460 }
2461 hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature_s);
2462
2463 /* read temperature max */
2464 res = hdc302x_read_temperature_max(&gs_handle, &temperature_raw, &temperature_s);
2465 if (res != 0)
2466 {
2467 hdc302x_interface_debug_print("hdc302x: read temperature max failed.\n");
2468 (void)hdc302x_deinit(&gs_handle);
2469
2470 return 1;
2471 }
2472 hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature_s);
2473
2474 /* read humidity min */
2475 res = hdc302x_read_humidity_min(&gs_handle, &humidity_raw, &humidity_s);
2476 if (res != 0)
2477 {
2478 hdc302x_interface_debug_print("hdc302x: read humidity min failed.\n");
2479 (void)hdc302x_deinit(&gs_handle);
2480
2481 return 1;
2482 }
2483 hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity_s);
2484
2485 /* read humidity max */
2486 res = hdc302x_read_humidity_max(&gs_handle, &humidity_raw, &humidity_s);
2487 if (res != 0)
2488 {
2489 hdc302x_interface_debug_print("hdc302x: read humidity max failed.\n");
2490 (void)hdc302x_deinit(&gs_handle);
2491
2492 return 1;
2493 }
2494 hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity_s);
2495
2496 /* wait 1000 ms */
2498 }
2499
2500 /* stop continuous read */
2501 res = hdc302x_stop_continuous_read(&gs_handle);
2502 if (res != 0)
2503 {
2504 hdc302x_interface_debug_print("hdc302x: stop continuous read failed.\n");
2505 (void)hdc302x_deinit(&gs_handle);
2506
2507 return 1;
2508 }
2509
2510 /* wait 500 ms */
2512
2513 /* finish read test */
2514 hdc302x_interface_debug_print("hdc302x: finish read test.\n");
2515 (void)hdc302x_deinit(&gs_handle);
2516
2517 return 0;
2518}
driver hdc302x read test 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_continuous_read_humidity(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
continuous read humidity
struct hdc302x_info_s hdc302x_info_t
hdc302x information structure definition
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_single_read(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
single read
uint8_t hdc302x_set_low_power_mode(hdc302x_handle_t *handle, hdc302x_low_power_mode_t mode)
set low power mode
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_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_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_read_humidity_max(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read humidity max
uint8_t hdc302x_info(hdc302x_info_t *info)
get chip's information
uint8_t hdc302x_start_continuous_read(hdc302x_handle_t *handle)
start continuous read
@ HDC302X_AUTO_MODE_2_HZ
@ HDC302X_AUTO_MODE_10_HZ
@ HDC302X_AUTO_MODE_0P5_HZ
@ HDC302X_AUTO_MODE_1_HZ
@ HDC302X_AUTO_MODE_4_HZ
@ HDC302X_LOW_POWER_MODE_3
@ HDC302X_LOW_POWER_MODE_2
@ HDC302X_LOW_POWER_MODE_0
@ HDC302X_LOW_POWER_MODE_1
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_receive_callback(uint16_t type)
interface receive callback
void hdc302x_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hdc302x_interface_iic_deinit(void)
interface iic bus deinit
uint8_t hdc302x_read_test(hdc302x_address_t addr, uint32_t times)
read test
uint32_t driver_version
char manufacturer_name[32]