LibDriver VEML7700
Loading...
Searching...
No Matches
driver_veml7700_read_test.c
Go to the documentation of this file.
1
36
38
39static veml7700_handle_t gs_handle;
40
49uint8_t veml7700_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint16_t raw;
53 uint16_t raw2;
54 uint32_t i;
55 double lux;
56 veml7700_info_t info;
59
60 /* link interface function */
68
69 /* get information */
70 res = veml7700_info(&info);
71 if (res != 0)
72 {
73 veml7700_interface_debug_print("veml7700: get info failed.\n");
74
75 return 1;
76 }
77 else
78 {
79 /* print chip info */
80 veml7700_interface_debug_print("veml7700: chip is %s.\n", info.chip_name);
81 veml7700_interface_debug_print("veml7700: manufacturer is %s.\n", info.manufacturer_name);
82 veml7700_interface_debug_print("veml7700: interface is %s.\n", info.interface);
83 veml7700_interface_debug_print("veml7700: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
84 veml7700_interface_debug_print("veml7700: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
85 veml7700_interface_debug_print("veml7700: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
86 veml7700_interface_debug_print("veml7700: max current is %0.2fmA.\n", info.max_current_ma);
87 veml7700_interface_debug_print("veml7700: max temperature is %0.1fC.\n", info.temperature_max);
88 veml7700_interface_debug_print("veml7700: min temperature is %0.1fC.\n", info.temperature_min);
89 }
90
91 /* start read test */
92 veml7700_interface_debug_print("veml7700: start read test.\n");
93
94 /* init */
95 res = veml7700_init(&gs_handle);
96 if (res != 0)
97 {
98 veml7700_interface_debug_print("veml7700: init failed.\n");
99
100 return 1;
101 }
102
103 /* set als gain1 */
105 if (res != 0)
106 {
107 veml7700_interface_debug_print("veml7700: set als gain failed.\n");
108 (void)veml7700_deinit(&gs_handle);
109
110 return 1;
111 }
112
113 /* set als integration time 400ms */
115 if (res != 0)
116 {
117 veml7700_interface_debug_print("veml7700: set als integration time failed.\n");
118 (void)veml7700_deinit(&gs_handle);
119
120 return 1;
121 }
122
123 /* set als persistence 1 */
125 if (res != 0)
126 {
127 veml7700_interface_debug_print("veml7700: set als persistence failed.\n");
128 (void)veml7700_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* set power saving mode1 */
135 if (res != 0)
136 {
137 veml7700_interface_debug_print("veml7700: set power saving mode failed.\n");
138 (void)veml7700_deinit(&gs_handle);
139
140 return 1;
141 }
142
143 /* disable power saving */
145 if (res != 0)
146 {
147 veml7700_interface_debug_print("veml7700: set power saving failed.\n");
148 (void)veml7700_deinit(&gs_handle);
149
150 return 1;
151 }
152
153 /* disable als interrupt */
155 if (res != 0)
156 {
157 veml7700_interface_debug_print("veml7700: set als interrupt failed.\n");
158 (void)veml7700_deinit(&gs_handle);
159
160 return 1;
161 }
162
163 /* power on */
165 if (res != 0)
166 {
167 veml7700_interface_debug_print("veml7700: set als mode failed.\n");
168 (void)veml7700_deinit(&gs_handle);
169
170 return 1;
171 }
172
173 /* disable auto range */
175 if (res != 0)
176 {
177 veml7700_interface_debug_print("veml7700: set auto range failed.\n");
178 (void)veml7700_deinit(&gs_handle);
179
180 return 1;
181 }
182
183 /* normal reading */
184 veml7700_interface_debug_print("veml7700: normal reading.\n");
185
186 /* 1000ms */
188
189 /* loop */
190 for (i = 0; i < times; i++)
191 {
192 /* read als */
193 res = veml7700_read_als(&gs_handle, &raw, &lux);
194 if (res != 0)
195 {
196 veml7700_interface_debug_print("veml7700: read als failed.\n");
197 (void)veml7700_deinit(&gs_handle);
198
199 return 1;
200 }
201
202 /* output */
203 veml7700_interface_debug_print("veml7700: als is %0.2flux.\n", lux);
204
205 /* read white */
206 res = veml7700_read_white(&gs_handle, &raw2);
207 if (res != 0)
208 {
209 veml7700_interface_debug_print("veml7700: read white failed.\n");
210 (void)veml7700_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* output */
216 veml7700_interface_debug_print("veml7700: white is %d.\n", raw2);
217
218 /* 1000ms */
220 }
221
222 /* power saving reading */
223 veml7700_interface_debug_print("veml7700: power saving reading.\n");
224
225 /* enable power saving */
227 if (res != 0)
228 {
229 veml7700_interface_debug_print("veml7700: set power saving failed.\n");
230 (void)veml7700_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 /* loop */
236 for (i = 0; i < times; i++)
237 {
238 /* read als */
239 res = veml7700_read_als(&gs_handle, &raw, &lux);
240 if (res != 0)
241 {
242 veml7700_interface_debug_print("veml7700: read als failed.\n");
243 (void)veml7700_deinit(&gs_handle);
244
245 return 1;
246 }
247
248 /* output */
249 veml7700_interface_debug_print("veml7700: als is %0.2flux.\n", lux);
250
251 /* read white */
252 res = veml7700_read_white(&gs_handle, &raw2);
253 if (res != 0)
254 {
255 veml7700_interface_debug_print("veml7700: read white failed.\n");
256 (void)veml7700_deinit(&gs_handle);
257
258 return 1;
259 }
260
261 /* output */
262 veml7700_interface_debug_print("veml7700: white is %d.\n", raw2);
263
264 /* 1000ms */
266 }
267
268 /* auto range reading */
269 veml7700_interface_debug_print("veml7700: auto range reading.\n");
270
271 /* disable power saving */
273 if (res != 0)
274 {
275 veml7700_interface_debug_print("veml7700: set power saving failed.\n");
276 (void)veml7700_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* enable auto range */
283 if (res != 0)
284 {
285 veml7700_interface_debug_print("veml7700: set auto range failed.\n");
286 (void)veml7700_deinit(&gs_handle);
287
288 return 1;
289 }
290
291 /* loop */
292 for (i = 0; i < times; i++)
293 {
294 /* get als gain */
295 res = veml7700_get_als_gain(&gs_handle, &gain);
296 if (res != 0)
297 {
298 veml7700_interface_debug_print("veml7700: get als gain failed.\n");
299 (void)veml7700_deinit(&gs_handle);
300
301 return 1;
302 }
303
304 /* get als integration time */
305 res = veml7700_get_als_integration_time(&gs_handle, &t);
306 if (res != 0)
307 {
308 veml7700_interface_debug_print("veml7700: get als integration time failed.\n");
309 (void)veml7700_deinit(&gs_handle);
310
311 return 1;
312 }
313
314 /* output */
315 if (gain == VEML7700_ALS_GAIN_1)
316 {
317 veml7700_interface_debug_print("veml7700: als gain is 1.\n");
318 }
319 else if (gain == VEML7700_ALS_GAIN_2)
320 {
321 veml7700_interface_debug_print("veml7700: als gain is 2.\n");
322 }
323 else if (gain == VEML7700_ALS_GAIN_1_DIV_8)
324 {
325 veml7700_interface_debug_print("veml7700: als gain is 1/8.\n");
326 }
327 else
328 {
329 veml7700_interface_debug_print("veml7700: als gain is 1/4.\n");
330 }
331
332 /* output */
334 {
335 veml7700_interface_debug_print("veml7700: als integration time is 25ms.\n");
336 }
338 {
339 veml7700_interface_debug_print("veml7700: als integration time is 50ms.\n");
340 }
342 {
343 veml7700_interface_debug_print("veml7700: als integration time is 100ms.\n");
344 }
346 {
347 veml7700_interface_debug_print("veml7700: als integration time is 200ms.\n");
348 }
350 {
351 veml7700_interface_debug_print("veml7700: als integration time is 400ms.\n");
352 }
353 else
354 {
355 veml7700_interface_debug_print("veml7700: als integration time is 800ms.\n");
356 }
357
358 /* read als */
359 res = veml7700_read_als(&gs_handle, &raw, &lux);
360 if (res != 0)
361 {
362 veml7700_interface_debug_print("veml7700: read als failed.\n");
363 (void)veml7700_deinit(&gs_handle);
364
365 return 1;
366 }
367
368 /* output */
369 veml7700_interface_debug_print("veml7700: als is %0.2flux.\n", lux);
370
371 /* read white */
372 res = veml7700_read_white(&gs_handle, &raw2);
373 if (res != 0)
374 {
375 veml7700_interface_debug_print("veml7700: read white failed.\n");
376 (void)veml7700_deinit(&gs_handle);
377
378 return 1;
379 }
380
381 /* output */
382 veml7700_interface_debug_print("veml7700: white is %d.\n", raw2);
383
384 /* 1000ms */
386 }
387
388 /* finish read test */
389 veml7700_interface_debug_print("veml7700: finish read test.\n");
390 (void)veml7700_deinit(&gs_handle);
391
392 return 0;
393}
driver veml7700 read test header file
uint8_t veml7700_set_als_integration_time(veml7700_handle_t *handle, veml7700_als_integration_time_t t)
set als integration time
uint8_t veml7700_deinit(veml7700_handle_t *handle)
close the chip
uint8_t veml7700_set_als_interrupt(veml7700_handle_t *handle, veml7700_bool_t enable)
enable or disable als interrupt
uint8_t veml7700_read_white(veml7700_handle_t *handle, uint16_t *raw)
read white channel
uint8_t veml7700_info(veml7700_info_t *info)
get chip's information
struct veml7700_info_s veml7700_info_t
veml7700 information structure definition
uint8_t veml7700_init(veml7700_handle_t *handle)
initialize the chip
uint8_t veml7700_read_als(veml7700_handle_t *handle, uint16_t *raw, double *lux)
read als channel
uint8_t veml7700_set_als_mode(veml7700_handle_t *handle, veml7700_als_mode_t mode)
set als mode
uint8_t veml7700_set_als_gain(veml7700_handle_t *handle, veml7700_als_gain_t gain)
set als gain
uint8_t veml7700_get_als_gain(veml7700_handle_t *handle, veml7700_als_gain_t *gain)
get als gain
struct veml7700_handle_s veml7700_handle_t
veml7700 handle structure definition
veml7700_als_integration_time_t
veml7700 als integration time enumeration definition
uint8_t veml7700_set_als_persistence(veml7700_handle_t *handle, veml7700_als_persistence_t persistence)
set als persistence
veml7700_als_gain_t
veml7700 als gain enumeration definition
uint8_t veml7700_get_als_integration_time(veml7700_handle_t *handle, veml7700_als_integration_time_t *t)
get als integration time
uint8_t veml7700_set_auto_range(veml7700_handle_t *handle, veml7700_bool_t enable)
set auto range
uint8_t veml7700_set_power_saving(veml7700_handle_t *handle, veml7700_bool_t enable)
enable or disable power saving
uint8_t veml7700_set_power_saving_mode(veml7700_handle_t *handle, veml7700_power_saving_mode_t mode)
set power saving mode
@ VEML7700_BOOL_DISABLE
@ VEML7700_BOOL_ENABLE
@ VEML7700_POWER_SAVING_MODE1
@ VEML7700_ALS_INTEGRATION_TIME_400MS
@ VEML7700_ALS_INTEGRATION_TIME_50MS
@ VEML7700_ALS_INTEGRATION_TIME_25MS
@ VEML7700_ALS_INTEGRATION_TIME_200MS
@ VEML7700_ALS_INTEGRATION_TIME_100MS
@ VEML7700_ALS_GAIN_1
@ VEML7700_ALS_GAIN_2
@ VEML7700_ALS_GAIN_1_DIV_8
@ VEML7700_ALS_PERSISTENCE_1
@ VEML7700_ALS_MODE_POWER_ON
uint8_t veml7700_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void veml7700_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t veml7700_interface_iic_init(void)
interface iic bus init
void veml7700_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t veml7700_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t veml7700_interface_iic_deinit(void)
interface iic bus deinit
uint8_t veml7700_read_test(uint32_t times)
read test
char manufacturer_name[32]