LibDriver MAX30205
Loading...
Searching...
No Matches
driver_max30205_interrupt_test.c
Go to the documentation of this file.
1
37
39
40static max30205_handle_t gs_handle;
41
55 float f_low_threshold, float f_high_threshold, uint32_t times)
56{
57 uint8_t res;
58 uint32_t i;
59 int16_t low_threshold, high_threshold;
60 int16_t raw;
61 float s;
62 max30205_info_t info;
63
64 /* link interface function */
72
73 /* get information */
74 res = max30205_info(&info);
75 if (res != 0)
76 {
77 max30205_interface_debug_print("max30205: get info failed.\n");
78
79 return 1;
80 }
81 else
82 {
83 /* print chip information */
84 max30205_interface_debug_print("max30205: chip is %s.\n", info.chip_name);
85 max30205_interface_debug_print("max30205: manufacturer is %s.\n", info.manufacturer_name);
86 max30205_interface_debug_print("max30205: interface is %s.\n", info.interface);
87 max30205_interface_debug_print("max30205: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
88 max30205_interface_debug_print("max30205: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
89 max30205_interface_debug_print("max30205: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
90 max30205_interface_debug_print("max30205: max current is %0.2fmA.\n", info.max_current_ma);
91 max30205_interface_debug_print("max30205: max temperature is %0.1fC.\n", info.temperature_max);
92 max30205_interface_debug_print("max30205: min temperature is %0.1fC.\n", info.temperature_min);
93 }
94
95 /* start interrupt test */
96 max30205_interface_debug_print("max30205: start interrupt test.\n");
97 res = max30205_set_addr_pin(&gs_handle, addr);
98 if (res != 0)
99 {
100 max30205_interface_debug_print("max30205: set addr pin failed.\n");
101
102 return 1;
103 }
104
105 /* max30205 init */
106 res = max30205_init(&gs_handle);
107 if (res != 0)
108 {
109 max30205_interface_debug_print("max30205: init failed.\n");
110
111 return 1;
112 }
113
114 /* set normal format */
116 if (res != 0)
117 {
118 max30205_interface_debug_print("max30205: set data format failed.\n");
119 (void)max30205_deinit(&gs_handle);
120
121 return 1;
122 }
123
124 /* set interrupt mode */
125 res = max30205_set_interrupt_mode(&gs_handle, mode);
126 if (res != 0)
127 {
128 max30205_interface_debug_print("max30205: set interrupt mode failed.\n");
129 (void)max30205_deinit(&gs_handle);
130
131 return 1;
132 }
133
134 /* set fault queue 1 */
136 if (res != 0)
137 {
138 max30205_interface_debug_print("max30205: set fault queue 1 failed.\n");
139 (void)max30205_deinit(&gs_handle);
140
141 return 1;
142 }
143
144 /* set pin low activity */
146 if (res != 0)
147 {
148 max30205_interface_debug_print("max30205: set pin polarity failed.\n");
149 (void)max30205_deinit(&gs_handle);
150
151 return 1;
152 }
153
154 /* set disable bus timeout */
156 if (res != 0)
157 {
158 max30205_interface_debug_print("max30205: set bus timeout failed.\n");
159 (void)max30205_deinit(&gs_handle);
160
161 return 1;
162 }
163
164 /* convert low threshold */
165 res = max30205_convert_to_register(&gs_handle, f_low_threshold, (int16_t *)&low_threshold);
166 if (res != 0)
167 {
168 max30205_interface_debug_print("max30205: convert to register failed.\n");
169 (void)max30205_deinit(&gs_handle);
170
171 return 1;
172 }
173
174 /* set low threshold */
175 res = max30205_set_interrupt_low_threshold(&gs_handle, low_threshold);
176 if (res != 0)
177 {
178 max30205_interface_debug_print("max30205: set low threshold failed.\n");
179 (void)max30205_deinit(&gs_handle);
180
181 return 1;
182 }
183
184 /* convert high threshold */
185 res = max30205_convert_to_register(&gs_handle, f_high_threshold, (int16_t *)&high_threshold);
186 if (res != 0)
187 {
188 max30205_interface_debug_print("max30205: convert to register failed.\n");
189 (void)max30205_deinit(&gs_handle);
190
191 return 1;
192 }
193
194 /* set high threshold */
195 res = max30205_set_interrupt_high_threshold(&gs_handle, high_threshold);
196 if (res != 0)
197 {
198 max30205_interface_debug_print("max30205: set high threshold failed.\n");
199 (void)max30205_deinit(&gs_handle);
200
201 return 1;
202 }
203
204 /* start continuous read */
205 res = max30205_start_continuous_read(&gs_handle);
206 if (res != 0)
207 {
208 max30205_interface_debug_print("max30205: start continuous read failed.\n");
209 (void)max30205_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* delay 1s */
216 for (i = 0; i < times; i++)
217 {
218 /* read data */
219 res = max30205_continuous_read(&gs_handle, (int16_t *)&raw, (float *)&s);
220 if (res != 0)
221 {
222 max30205_interface_debug_print("max30205: read failed.\n");
223 (void)max30205_deinit(&gs_handle);
224
225 return 1;
226 }
227
228 /* output temperature */
229 max30205_interface_debug_print("max30205: temperature: %.01fC.\n", s);
230 if (s > f_high_threshold)
231 {
232 max30205_interface_debug_print("max30205: %d temperature is over high threshold, please see os pin.\n", i+1);
233 }
234 if (s < f_low_threshold)
235 {
236 max30205_interface_debug_print("max30205: %d temperature is below low threshold, please see os pin.\n", i+1);
237 }
238
239 /* delay 1s */
241 }
242
243 /* stop continuous read */
244 res = max30205_stop_continuous_read(&gs_handle);
245 if (res != 0)
246 {
247 max30205_interface_debug_print("max30205: stop continuous read failed.\n");
248 (void)max30205_deinit(&gs_handle);
249
250 return 1;
251 }
252
253 /* finish interrupt test */
254 max30205_interface_debug_print("max30205: finish interrupt test.\n");
255 (void)max30205_deinit(&gs_handle);
256
257 return 0;
258}
driver max30205 interrupt 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_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
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
max30205_interrupt_mode_t
max30205 interrupt mode enumeration definition
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_FAULT_QUEUE_1
@ MAX30205_PIN_POLARITY_LOW
uint8_t max30205_interrupt_test(max30205_address_t addr, max30205_interrupt_mode_t mode, float f_low_threshold, float f_high_threshold, uint32_t times)
interrupt test
char manufacturer_name[32]