tests/vcnl40x0: add test application
This commit is contained in:
parent
22b2306536
commit
456e0a3abf
7
tests/driver_vcnl40x0/Makefile
Normal file
7
tests/driver_vcnl40x0/Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
APPLICATION = driver_vcnl40x0
|
||||||
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
|
USEMODULE += vcnl4010
|
||||||
|
USEMODULE += xtimer
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
10
tests/driver_vcnl40x0/README.md
Normal file
10
tests/driver_vcnl40x0/README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
## About
|
||||||
|
This is a test application for the VCNL40X0 proximity and ambient light sensor.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
After initialization, every 2 seconds, the application:
|
||||||
|
* reads the proximity (cts);
|
||||||
|
* reads the ambient light (cts);
|
||||||
|
* reads the illuminance (computed from ambient light by dividing it by 4);
|
||||||
|
* those values are printed to STDOUT.
|
||||||
65
tests/driver_vcnl40x0/main.c
Normal file
65
tests/driver_vcnl40x0/main.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Inria
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
* directory for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup tests
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Test application for the VNCL40X0 proximity and ambient light sensor.
|
||||||
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "vcnl40x0.h"
|
||||||
|
#include "vcnl40x0_params.h"
|
||||||
|
#include "xtimer.h"
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
|
#define SLEEP_2S (2U) /* 2 seconds delay between printf */
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
vcnl40x0_t dev;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
puts("VCNL40X0 test application\n");
|
||||||
|
|
||||||
|
printf("+------------Initializing------------+\n");
|
||||||
|
result = vcnl40x0_init(&dev, &vcnl40x0_params[0]);
|
||||||
|
if (result == -VCNL40X0_ERR_I2C) {
|
||||||
|
puts("[Error] The given i2c is not enabled");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (result == -VCNL40X0_ERR_NODEV) {
|
||||||
|
puts("[Error] The sensor did not answer correctly on the given address");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Initialization successful\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n+--------Starting Measurements--------+\n");
|
||||||
|
while (1) {
|
||||||
|
printf("Proximity [cts]: %d\n"
|
||||||
|
"Ambient light [cts]: %d\n"
|
||||||
|
"Illuminance [lx]: %d\n"
|
||||||
|
"\n+-------------------------------------+\n",
|
||||||
|
vcnl40x0_read_proximity(&dev),
|
||||||
|
vcnl40x0_read_ambient_light(&dev),
|
||||||
|
vcnl40x0_read_illuminance(&dev));
|
||||||
|
|
||||||
|
xtimer_sleep(SLEEP_2S);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user