LibDriver AGS10ET
Loading...
Searching...
No Matches
driver_ags10et_read_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static ags10et_handle_t gs_handle;
41
50uint8_t ags10et_read_test(uint32_t times)
51{
52 uint8_t res;
53 uint8_t version;
54 uint8_t addr_7bit;
55 uint16_t reg;
56 double ohm;
57 uint32_t i;
58 uint32_t raw;
59 uint32_t ppb;
60 ags10et_info_t info;
61
62 /* link interface function */
71
72 /* get ags10et information */
73 res = ags10et_info(&info);
74 if (res != 0)
75 {
76 ags10et_interface_debug_print("ags10et: get info failed.\n");
77
78 return 1;
79 }
80 else
81 {
82 /* print ags10et information */
83 ags10et_interface_debug_print("ags10et: chip is %s.\n", info.chip_name);
84 ags10et_interface_debug_print("ags10et: manufacturer is %s.\n", info.manufacturer_name);
85 ags10et_interface_debug_print("ags10et: interface is %s.\n", info.interface);
86 ags10et_interface_debug_print("ags10et: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
87 ags10et_interface_debug_print("ags10et: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
88 ags10et_interface_debug_print("ags10et: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
89 ags10et_interface_debug_print("ags10et: max current is %0.2fmA.\n", info.max_current_ma);
90 ags10et_interface_debug_print("ags10et: max temperature is %0.1fC.\n", info.temperature_max);
91 ags10et_interface_debug_print("ags10et: min temperature is %0.1fC.\n", info.temperature_min);
92 }
93
94 /* start basic read test */
95 ags10et_interface_debug_print("ags10et: start read test.\n");
96
97 /* ags10et init */
98 res = ags10et_init(&gs_handle);
99 if (res != 0)
100 {
101 ags10et_interface_debug_print("ags10et: init failed.\n");
102
103 return 1;
104 }
105
106 /* get version */
107 res = ags10et_get_version(&gs_handle, &version);
108 if (res != 0)
109 {
110 ags10et_interface_debug_print("ags10et: get version failed.\n");
111 (void)ags10et_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* print result */
117 ags10et_interface_debug_print("ags10et: version is 0x%02X.\n", version);
118
119 /* delay 2000 ms for read */
121 for (i = 0; i < times; i++)
122 {
123 /* read ethanol */
124 res = ags10et_read_ethanol(&gs_handle, (uint32_t *)&raw, (uint32_t *)&ppb);
125 if (res != 0)
126 {
127 ags10et_interface_debug_print("ags10et: read ethanol failed.\n");
128 (void)ags10et_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* print result */
134 ags10et_interface_debug_print("ags10et: ethanol is %dppb.\n", ppb);
135
136 /* delay 2000 ms*/
138 }
139
140 /* get resistance */
141 res = ags10et_get_resistance(&gs_handle, &raw, &ohm);
142 if (res != 0)
143 {
144 ags10et_interface_debug_print("ags10et: get resistance failed.\n");
145 (void)ags10et_deinit(&gs_handle);
146
147 return 1;
148 }
149
150 /* print result */
151 ags10et_interface_debug_print("ags10et: resistance is %0.2fohm.\n", ohm);
152
153 /* delay 2000 ms for read */
155
156 reg = rand() % 0xFFFFU;
157 res = ags10et_zero_point_calibration(&gs_handle, reg);
158 if (res != 0)
159 {
160 ags10et_interface_debug_print("ags10et: zero point calibration failed.\n");
161 (void)ags10et_deinit(&gs_handle);
162
163 return 1;
164 }
165
166 /* print result */
167 ags10et_interface_debug_print("ags10et: zero point calibration 0x%04X.\n", reg);
168
169 /* delay 2000 ms*/
171
172 /* current resistance zero point calibration */
174 if (res != 0)
175 {
176 ags10et_interface_debug_print("ags10et: current resistance zero point calibration failed.\n");
177 (void)ags10et_deinit(&gs_handle);
178
179 return 1;
180 }
181
182 /* print result */
183 ags10et_interface_debug_print("ags10et: current resistance zero point calibration.\n");
184
185 /* delay 2000 ms*/
187
188 /* reset zero point calibration */
189 res = ags10et_reset_zero_point_calibration(&gs_handle);
190 if (res != 0)
191 {
192 ags10et_interface_debug_print("ags10et: reset zero point calibration failed.\n");
193 (void)ags10et_deinit(&gs_handle);
194
195 return 1;
196 }
197
198 /* print result */
199 ags10et_interface_debug_print("ags10et: reset zero point calibration.\n");
200
201 /* delay 2000 ms*/
203
204 addr_7bit = 0x1A;
205 res = ags10et_modify_slave_address(&gs_handle, addr_7bit);
206 if (res != 0)
207 {
208 ags10et_interface_debug_print("ags10et: modify slave address failed.\n");
209 (void)ags10et_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* print result */
215 ags10et_interface_debug_print("ags10et: modify slave address 0x%02X.\n", addr_7bit);
216
217 /* finish read test */
218 ags10et_interface_debug_print("ags10et: finish read test.\n");
219 (void)ags10et_deinit(&gs_handle);
220
221 return 0;
222}
driver ags10et read test header file
uint8_t ags10et_get_resistance(ags10et_handle_t *handle, uint32_t *raw, double *ohm)
get resistance
uint8_t ags10et_reset_zero_point_calibration(ags10et_handle_t *handle)
reset zero point calibration
uint8_t ags10et_deinit(ags10et_handle_t *handle)
close the chip
uint8_t ags10et_current_resistance_zero_point_calibration(ags10et_handle_t *handle)
zero point calibration using current resistance
uint8_t ags10et_read_ethanol(ags10et_handle_t *handle, uint32_t *raw, uint32_t *ppb)
read ethanol
uint8_t ags10et_modify_slave_address(ags10et_handle_t *handle, uint8_t addr_7bit)
modify slave address
uint8_t ags10et_init(ags10et_handle_t *handle)
initialize the chip
struct ags10et_handle_s ags10et_handle_t
ags10et handle structure definition
uint8_t ags10et_get_version(ags10et_handle_t *handle, uint8_t *version)
get version
struct ags10et_info_s ags10et_info_t
ags10et information structure definition
uint8_t ags10et_info(ags10et_info_t *info)
get chip's information
uint8_t ags10et_zero_point_calibration(ags10et_handle_t *handle, uint16_t raw)
zero point calibration
uint8_t ags10et_interface_iic_deinit(void)
interface iic bus deinit
void ags10et_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ags10et_interface_iic_init(void)
interface iic bus init
uint8_t ags10et_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
void ags10et_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ags10et_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t ags10et_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t ags10et_read_test(uint32_t times)
read test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v