tests/driver_si114x: add basic test application
This commit is contained in:
parent
5c7cc50698
commit
2d432eaccd
6
tests/driver_si114x/Makefile
Normal file
6
tests/driver_si114x/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
# This test should also work with Si1146 and Si1147 variants.
|
||||
USEMODULE += si1145
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
12
tests/driver_si114x/README.md
Normal file
12
tests/driver_si114x/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
### Test application for Si114X sensors family
|
||||
|
||||
#### Introduction
|
||||
|
||||
The Si114X (Si1145, Si1146 and Si1147) sensors are UV, light and proximity sensors.
|
||||
More information in the [datasheet](https://www.silabs.com/Support%20Documents%2FTechnicalDocs%2FSi1145-46-47.pdf).
|
||||
|
||||
#### Expected results
|
||||
|
||||
After initialization, the sensor continuously (every 2 secs) displays the
|
||||
IR light, the visible light, the UV index, the proximity and the value of the
|
||||
response register.
|
||||
70
tests/driver_si114x/main.c
Normal file
70
tests/driver_si114x/main.c
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2018 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 Si114x UV, IR, visible and proximity
|
||||
* sensor.
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* Bas Stottelaar <basstottelaar@gmail.com>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "si114x.h"
|
||||
#include "si114x_params.h"
|
||||
#include "xtimer.h"
|
||||
#include "board.h"
|
||||
|
||||
static si114x_t dev;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("Si1145 test application\n"
|
||||
"+------------Initializing------------+\n");
|
||||
|
||||
int result = si114x_init(&dev, &si114x_params[0]);
|
||||
if (result == -SI114X_ERR_I2C) {
|
||||
puts("[Error] The given i2c is not enabled");
|
||||
return -1;
|
||||
}
|
||||
else if (result == -SI114X_ERR_NODEV) {
|
||||
puts("[Error] The sensor did not answer correctly on the "
|
||||
"given address");
|
||||
return 1;
|
||||
}
|
||||
|
||||
puts("Initialization successful\n"
|
||||
"+--------Starting Measurements--------+\n");
|
||||
|
||||
while (1) {
|
||||
printf("UV index: %" PRIu16 "\n"
|
||||
"IR light [lx]: %" PRIu16 "\n"
|
||||
"Visible light [lx]: %" PRIu16 "\n"
|
||||
"Distance [cnt]: %" PRIu16 "\n"
|
||||
"Response: 0x%02x\n"
|
||||
"\n+-------------------------------------+\n",
|
||||
si114x_read_uv(&dev),
|
||||
si114x_read_ir(&dev),
|
||||
si114x_read_visible(&dev),
|
||||
si114x_read_distance(&dev),
|
||||
si114x_read_response(&dev));
|
||||
|
||||
/* 2 seconds delay between measures */
|
||||
xtimer_sleep(2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user