LibDriver BA111
Loading...
Searching...
No Matches
driver_ba111_read_test.c
Go to the documentation of this file.
1
36
38
39static ba111_handle_t gs_handle;
40
49uint8_t ba111_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint32_t i;
53 ba111_info_t info;
54
55 /* link interface function */
64
65 /* get ba111 information */
66 res = ba111_info(&info);
67 if (res != 0)
68 {
69 ba111_interface_debug_print("ba111: get info failed.\n");
70
71 return 1;
72 }
73 else
74 {
75 /* print chip information */
76 ba111_interface_debug_print("ba111: chip is %s.\n", info.chip_name);
77 ba111_interface_debug_print("ba111: manufacturer is %s.\n", info.manufacturer_name);
78 ba111_interface_debug_print("ba111: interface is %s.\n", info.interface);
79 ba111_interface_debug_print("ba111: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
80 ba111_interface_debug_print("ba111: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
81 ba111_interface_debug_print("ba111: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
82 ba111_interface_debug_print("ba111: max current is %0.2fmA.\n", info.max_current_ma);
83 ba111_interface_debug_print("ba111: max temperature is %0.1fC.\n", info.temperature_max);
84 ba111_interface_debug_print("ba111: min temperature is %0.1fC.\n", info.temperature_min);
85 }
86
87 /* start read test */
88 ba111_interface_debug_print("ba111: start read test.\n");
89
90 /* ba111 init */
91 res = ba111_init(&gs_handle);
92 if (res != 0)
93 {
94 ba111_interface_debug_print("ba111: init failed.\n");
95
96 return 1;
97 }
98
99 for (i = 0; i < times; i++)
100 {
101 uint16_t tds_raw;
102 uint16_t tds_ppm;
103 uint16_t temperature_raw;
104 float temperature;
105
106 /* delay 1000ms */
108
109 /* read */
110 res = ba111_read(&gs_handle, &tds_raw, &tds_ppm, &temperature_raw, &temperature);
111 if (res != 0)
112 {
113 ba111_interface_debug_print("ba111: read failed.\n");
114 (void)ba111_deinit(&gs_handle);
115
116 return 1;
117 }
118
119 /* output */
120 ba111_interface_debug_print("ba111: tds is %d ppm.\n", tds_ppm);
121 ba111_interface_debug_print("ba111: temperature is %0.2fC.\n", temperature);
122 }
123
124 /* finish read test */
125 ba111_interface_debug_print("ba111: finish read test.\n");
126 (void)ba111_deinit(&gs_handle);
127
128 return 0;
129}
driver ba111 read test header file
struct ba111_handle_s ba111_handle_t
ba111 handle structure definition
uint8_t ba111_init(ba111_handle_t *handle)
initialize the chip
struct ba111_info_s ba111_info_t
ba111 information structure definition
uint8_t ba111_info(ba111_info_t *info)
get chip's information
uint8_t ba111_read(ba111_handle_t *handle, uint16_t *tds_raw, uint16_t *tds_ppm, uint16_t *temperature_raw, float *temperature)
read the data
uint8_t ba111_deinit(ba111_handle_t *handle)
close the chip
uint16_t ba111_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t ba111_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint8_t ba111_interface_uart_init(void)
interface uart init
void ba111_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ba111_interface_uart_deinit(void)
interface uart deinit
uint8_t ba111_interface_uart_flush(void)
interface uart flush
void ba111_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ba111_read_test(uint32_t times)
read test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]