LibDriver MAX30205
Loading...
Searching...
No Matches
driver_max30205_read_test.c
Go to the documentation of this file.
1
37
39
40static max30205_handle_t gs_handle;
41
51uint8_t max30205_read_test(max30205_address_t addr, uint32_t times)
52{
53 uint8_t res;
54 uint32_t i;
55 int16_t low_threshold, high_threshold;
56 int16_t raw;
57 float s;
58 max30205_info_t info;
59
60 /* link interface function */
68
69 /* get information */
70 res = max30205_info(&info);
71 if (res != 0)
72 {
73 max30205_interface_debug_print("max30205: get info failed.\n");
74
75 return 1;
76 }
77 else
78 {
79 /* print chip information */
80 max30205_interface_debug_print("max30205: chip is %s.\n", info.chip_name);
81 max30205_interface_debug_print("max30205: manufacturer is %s.\n", info.manufacturer_name);
82 max30205_interface_debug_print("max30205: interface is %s.\n", info.interface);
83 max30205_interface_debug_print("max30205: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
84 max30205_interface_debug_print("max30205: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
85 max30205_interface_debug_print("max30205: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
86 max30205_interface_debug_print("max30205: max current is %0.2fmA.\n", info.max_current_ma);
87 max30205_interface_debug_print("max30205: max temperature is %0.1fC.\n", info.temperature_max);
88 max30205_interface_debug_print("max30205: min temperature is %0.1fC.\n", info.temperature_min);
89 }
90
91 /* start read test */
92 max30205_interface_debug_print("max30205: start read test.\n");
93 res = max30205_set_addr_pin(&gs_handle, addr);
94 if (res != 0)
95 {
96 max30205_interface_debug_print("max30205: set addr pin failed.\n");
97
98 return 1;
99 }
100
101 /* max30205 init */
102 res = max30205_init(&gs_handle);
103 if (res != 0)
104 {
105 max30205_interface_debug_print("max30205: init failed.\n");
106
107 return 1;
108 }
109
110 /* set interrupt comparator mode */
112 if (res != 0)
113 {
114 max30205_interface_debug_print("max30205: set interrupt mode failed.\n");
115 (void)max30205_deinit(&gs_handle);
116
117 return 1;
118 }
119
120 /* set set fault queue 1 */
122 if (res != 0)
123 {
124 max30205_interface_debug_print("max30205: set fault queue 1 failed.\n");
125 (void)max30205_deinit(&gs_handle);
126
127 return 1;
128 }
129
130 /* set pin low activity */
132 if (res != 0)
133 {
134 max30205_interface_debug_print("max30205: set pin polarity failed.\n");
135 (void)max30205_deinit(&gs_handle);
136
137 return 1;
138 }
139
140 /* disable bus timeout */
142 if (res != 0)
143 {
144 max30205_interface_debug_print("max30205: set bus timeout failed.\n");
145 (void)max30205_deinit(&gs_handle);
146
147 return 1;
148 }
149
150 /* convert low threshold 35.0 */
151 res = max30205_convert_to_register(&gs_handle, 35.0f, (int16_t *)&low_threshold);
152 if (res != 0)
153 {
154 max30205_interface_debug_print("max30205: convert to register failed.\n");
155 (void)max30205_deinit(&gs_handle);
156
157 return 1;
158 }
159
160 /* set low threshold */
161 res = max30205_set_interrupt_low_threshold(&gs_handle, low_threshold);
162 if (res != 0)
163 {
164 max30205_interface_debug_print("max30205: set low threshold failed.\n");
165 (void)max30205_deinit(&gs_handle);
166
167 return 1;
168 }
169
170 /* convert high threshold 39.0 */
171 res = max30205_convert_to_register(&gs_handle, 39.0f, (int16_t *)&high_threshold);
172 if (res != 0)
173 {
174 max30205_interface_debug_print("max30205: convert to register failed.\n");
175 (void)max30205_deinit(&gs_handle);
176
177 return 1;
178 }
179
180 /* set high threshold */
181 res = max30205_set_interrupt_high_threshold(&gs_handle, high_threshold);
182 if (res != 0)
183 {
184 max30205_interface_debug_print("max30205: set high threshold failed.\n");
185 (void)max30205_deinit(&gs_handle);
186
187 return 1;
188 }
189
190 /* normal read mode test */
191 max30205_interface_debug_print("max30205: normal read mode test.\n");
193 if (res != 0)
194 {
195 max30205_interface_debug_print("max30205: set data format failed.\n");
196 (void)max30205_deinit(&gs_handle);
197
198 return 1;
199 }
200 for (i = 0; i < times; i++)
201 {
202 /* read data */
203 res = max30205_single_read(&gs_handle, (int16_t *)&raw, (float *)&s);
204 if (res != 0)
205 {
206 max30205_interface_debug_print("max30205: read failed.\n");
207 (void)max30205_deinit(&gs_handle);
208
209 return 1;
210 }
211 max30205_interface_debug_print("max30205: temperature: %.01fC.\n", s);
213 }
214
215 /* set extended format */
216 max30205_interface_debug_print("max30205: extended read mode test.\n");
218 if (res != 0)
219 {
220 max30205_interface_debug_print("max30205: set data format failed.\n");
221 (void)max30205_deinit(&gs_handle);
222
223 return 1;
224 }
225 for (i = 0; i < times; i++)
226 {
227 /* read data */
228 res = max30205_single_read(&gs_handle, (int16_t *)&raw, (float *)&s);
229 if (res != 0)
230 {
231 max30205_interface_debug_print("max30205: read failed.\n");
232 (void)max30205_deinit(&gs_handle);
233
234 return 1;
235 }
236 max30205_interface_debug_print("max30205: temperature: %.01fC.\n", s);
238 }
239
240 /* single read test */
241 max30205_interface_debug_print("max30205: single read test.\n");
242 for (i = 0; i < times; i++)
243 {
244 /* read data */
245 res = max30205_single_read(&gs_handle, (int16_t *)&raw, (float *)&s);
246 if (res != 0)
247 {
248 max30205_interface_debug_print("max30205: read failed.\n");
249 (void)max30205_deinit(&gs_handle);
250
251 return 1;
252 }
253 max30205_interface_debug_print("max30205: temperature: %.01fC.\n", s);
255 }
256
257 /* continuous read test */
258 max30205_interface_debug_print("max30205: continuous read test.\n");
259 res = max30205_start_continuous_read(&gs_handle);
260 if (res != 0)
261 {
262 max30205_interface_debug_print("max30205: start continuous read failed.\n");
263 (void)max30205_deinit(&gs_handle);
264
265 return 1;
266 }
268 for (i = 0; i < times; i++)
269 {
270 /* read data */
271 res = max30205_continuous_read(&gs_handle, (int16_t *)&raw, (float *)&s);
272 if (res != 0)
273 {
274 max30205_interface_debug_print("max30205: read failed.\n");
275 (void)max30205_deinit(&gs_handle);
276
277 return 1;
278 }
279 max30205_interface_debug_print("max30205: temperature: %.01fC.\n", s);
281 }
282 res = max30205_stop_continuous_read(&gs_handle);
283 if (res != 0)
284 {
285 max30205_interface_debug_print("max30205: stop continuous read failed.\n");
286 (void)max30205_deinit(&gs_handle);
287
288 return 1;
289 }
290
291 /* finished read test */
292 max30205_interface_debug_print("max30205: finished read test.\n");
293 (void)max30205_deinit(&gs_handle);
294
295 return 0;
296}
driver max30205 read test header file
struct max30205_handle_s max30205_handle_t
max30205 handle structure definition
uint8_t max30205_set_data_format(max30205_handle_t *handle, max30205_data_format_t format)
set the chip data format
uint8_t max30205_start_continuous_read(max30205_handle_t *handle)
start reading data
struct max30205_info_s max30205_info_t
max30205 information structure definition
uint8_t max30205_set_addr_pin(max30205_handle_t *handle, max30205_address_t addr_pin)
set the iic address pin
uint8_t max30205_info(max30205_info_t *info)
get chip's information
max30205_address_t
max30205 address enumeration definition
uint8_t max30205_deinit(max30205_handle_t *handle)
close the chip
uint8_t max30205_set_bus_timeout(max30205_handle_t *handle, max30205_bus_timeout_t bus_timeout)
set the iic bus timeout
uint8_t max30205_continuous_read(max30205_handle_t *handle, int16_t *raw, float *s)
read data continuously
uint8_t max30205_single_read(max30205_handle_t *handle, int16_t *raw, float *s)
read data once
uint8_t max30205_init(max30205_handle_t *handle)
initialize the chip
uint8_t max30205_stop_continuous_read(max30205_handle_t *handle)
stop reading data
@ MAX30205_BUS_TIMEOUT_DISABLE
@ MAX30205_DATA_FORMAT_NORMAL
@ MAX30205_DATA_FORMAT_EXTENDED
void max30205_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t max30205_interface_iic_deinit(void)
interface iic bus deinit
uint8_t max30205_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t max30205_interface_iic_init(void)
interface iic bus init
uint8_t max30205_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void max30205_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t max30205_set_fault_queue(max30205_handle_t *handle, max30205_fault_queue_t fault_queue)
set the chip fault queue
uint8_t max30205_set_interrupt_mode(max30205_handle_t *handle, max30205_interrupt_mode_t mode)
set the chip interrupt mode
uint8_t max30205_set_interrupt_low_threshold(max30205_handle_t *handle, int16_t threshold)
set the chip interrupt low threshold
uint8_t max30205_set_pin_polarity(max30205_handle_t *handle, max30205_pin_polarity_t polarity)
set the interrupt pin polarity
uint8_t max30205_convert_to_register(max30205_handle_t *handle, float s, int16_t *reg)
convert a temperature value to a register raw data
uint8_t max30205_set_interrupt_high_threshold(max30205_handle_t *handle, int16_t threshold)
set the chip interrupt high threshold
@ MAX30205_INTERRUPT_MODE_COMPARATOR
@ MAX30205_FAULT_QUEUE_1
@ MAX30205_PIN_POLARITY_LOW
uint8_t max30205_read_test(max30205_address_t addr, uint32_t times)
read test
char manufacturer_name[32]