LibDriver AGS10
Loading...
Searching...
No Matches
driver_ags10_read_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static ags10_handle_t gs_handle;
41
50uint8_t ags10_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 ags10_info_t info;
61
62 /* link interface function */
71
72 /* get ags10 information */
73 res = ags10_info(&info);
74 if (res != 0)
75 {
76 ags10_interface_debug_print("ags10: get info failed.\n");
77
78 return 1;
79 }
80 else
81 {
82 /* print ags10 information */
83 ags10_interface_debug_print("ags10: chip is %s.\n", info.chip_name);
84 ags10_interface_debug_print("ags10: manufacturer is %s.\n", info.manufacturer_name);
85 ags10_interface_debug_print("ags10: interface is %s.\n", info.interface);
86 ags10_interface_debug_print("ags10: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
87 ags10_interface_debug_print("ags10: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
88 ags10_interface_debug_print("ags10: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
89 ags10_interface_debug_print("ags10: max current is %0.2fmA.\n", info.max_current_ma);
90 ags10_interface_debug_print("ags10: max temperature is %0.1fC.\n", info.temperature_max);
91 ags10_interface_debug_print("ags10: min temperature is %0.1fC.\n", info.temperature_min);
92 }
93
94 /* start basic read test */
95 ags10_interface_debug_print("ags10: start read test.\n");
96
97 /* ags10 init */
98 res = ags10_init(&gs_handle);
99 if (res != 0)
100 {
101 ags10_interface_debug_print("ags10: init failed.\n");
102
103 return 1;
104 }
105
106 /* get version */
107 res = ags10_get_version(&gs_handle, &version);
108 if (res != 0)
109 {
110 ags10_interface_debug_print("ags10: get version failed.\n");
111 (void)ags10_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* print result */
117 ags10_interface_debug_print("ags10: version is 0x%02X.\n", version);
118
119 /* delay 2000 ms for read */
121 for (i = 0; i < times; i++)
122 {
123 /* read tvoc */
124 res = ags10_read_tvoc(&gs_handle, (uint32_t *)&raw, (uint32_t *)&ppb);
125 if (res != 0)
126 {
127 ags10_interface_debug_print("ags10: read tvoc failed.\n");
128 (void)ags10_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* print result */
134 ags10_interface_debug_print("ags10: tvoc is %dppb.\n", ppb);
135
136 /* delay 2000 ms*/
138 }
139
140 /* get resistance */
141 res = ags10_get_resistance(&gs_handle, &raw, &ohm);
142 if (res != 0)
143 {
144 ags10_interface_debug_print("ags10: get resistance failed.\n");
145 (void)ags10_deinit(&gs_handle);
146
147 return 1;
148 }
149
150 /* print result */
151 ags10_interface_debug_print("ags10: resistance is %0.2fohm.\n", ohm);
152
153 /* delay 2000 ms for read */
155
156 reg = rand() % 0xFFFFU;
157 res = ags10_zero_point_calibration(&gs_handle, reg);
158 if (res != 0)
159 {
160 ags10_interface_debug_print("ags10: zero point calibration failed.\n");
161 (void)ags10_deinit(&gs_handle);
162
163 return 1;
164 }
165
166 /* print result */
167 ags10_interface_debug_print("ags10: 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 ags10_interface_debug_print("ags10: current resistance zero point calibration failed.\n");
177 (void)ags10_deinit(&gs_handle);
178
179 return 1;
180 }
181
182 /* print result */
183 ags10_interface_debug_print("ags10: current resistance zero point calibration.\n");
184
185 /* delay 2000 ms*/
187
188 /* reset zero point calibration */
189 res = ags10_reset_zero_point_calibration(&gs_handle);
190 if (res != 0)
191 {
192 ags10_interface_debug_print("ags10: reset zero point calibration failed.\n");
193 (void)ags10_deinit(&gs_handle);
194
195 return 1;
196 }
197
198 /* print result */
199 ags10_interface_debug_print("ags10: reset zero point calibration.\n");
200
201 /* delay 2000 ms*/
203
204 addr_7bit = 0x1A;
205 res = ags10_modify_slave_address(&gs_handle, addr_7bit);
206 if (res != 0)
207 {
208 ags10_interface_debug_print("ags10: modify slave address failed.\n");
209 (void)ags10_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* print result */
215 ags10_interface_debug_print("ags10: modify slave address 0x%02X.\n", addr_7bit);
216
217 /* finish read test */
218 ags10_interface_debug_print("ags10: finish read test.\n");
219 (void)ags10_deinit(&gs_handle);
220
221 return 0;
222}
driver ags10 read test header file
uint8_t ags10_deinit(ags10_handle_t *handle)
close the chip
uint8_t ags10_info(ags10_info_t *info)
get chip's information
uint8_t ags10_current_resistance_zero_point_calibration(ags10_handle_t *handle)
zero point calibration using current resistance
uint8_t ags10_zero_point_calibration(ags10_handle_t *handle, uint16_t raw)
zero point calibration
struct ags10_info_s ags10_info_t
ags10 information structure definition
uint8_t ags10_get_resistance(ags10_handle_t *handle, uint32_t *raw, double *ohm)
get resistance
uint8_t ags10_read_tvoc(ags10_handle_t *handle, uint32_t *raw, uint32_t *ppb)
read tvoc
uint8_t ags10_modify_slave_address(ags10_handle_t *handle, uint8_t addr_7bit)
modify slave address
uint8_t ags10_get_version(ags10_handle_t *handle, uint8_t *version)
get version
uint8_t ags10_reset_zero_point_calibration(ags10_handle_t *handle)
reset zero point calibration
struct ags10_handle_s ags10_handle_t
ags10 handle structure definition
uint8_t ags10_init(ags10_handle_t *handle)
initialize the chip
void ags10_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ags10_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t ags10_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t ags10_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
uint8_t ags10_interface_iic_deinit(void)
interface iic bus deinit
uint8_t ags10_interface_iic_init(void)
interface iic bus init
void ags10_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ags10_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]