Skip to content
Snippets Groups Projects
Commit 456e0a3a authored by Alexandre Abadie's avatar Alexandre Abadie
Browse files

tests/vcnl40x0: add test application

parent 22b23065
No related branches found
No related tags found
No related merge requests found
APPLICATION = driver_vcnl40x0
include ../Makefile.tests_common
USEMODULE += vcnl4010
USEMODULE += xtimer
include $(RIOTBASE)/Makefile.include
## 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.
/*
* 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment