mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
tests/driver_tsl4531x: Add tests for illuminance sensor.
Missing README.
This commit is contained in:
parent
63dcc18c55
commit
b99bd67efd
12
tests/driver_tsl4531x/Makefile
Normal file
12
tests/driver_tsl4531x/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
BOARD ?= stm32f4discovery
|
||||
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += tsl4531x
|
||||
USEMODULE += xtimer
|
||||
|
||||
I2C_PORT ?= 0
|
||||
|
||||
CFLAGS += -DTSL4531_I2C_PORT=$(I2C_PORT)
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
59
tests/driver_tsl4531x/main.c
Normal file
59
tests/driver_tsl4531x/main.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 TSL2561 Lux sensor
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "xtimer.h"
|
||||
#include "periph/i2c.h"
|
||||
|
||||
#include "tsl4531x.h"
|
||||
|
||||
#define _100ms_in_us (100 * 1000u) /* 1 second delay between printf */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
tsl4531x_t dev;
|
||||
int err;
|
||||
|
||||
puts("TSL4531x test application. Initializing...");
|
||||
|
||||
if((err = tsl4531x_init(&dev, TSL4531_I2C_PORT, TSL4531x_INTEGRATE_200ms)) < 0) {
|
||||
printf("Error setting up device. %d (%s)\n", err, strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
puts("Initialized, will begin measurements.");
|
||||
while (1) {
|
||||
int err;
|
||||
uint16_t lux;
|
||||
|
||||
if ((err = tsl4531x_read(&dev, &lux)) < 0) {
|
||||
printf("Error reading from device. %d (%s)\n", err, strerror(err));
|
||||
} else {
|
||||
printf("Illuminance [lx]: %u\n", lux);
|
||||
}
|
||||
|
||||
xtimer_usleep(_100ms_in_us);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user