diff --git a/tests/driver_tsl4531x/Makefile b/tests/driver_tsl4531x/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0e35e6a9eb6e19a3bdfa06699d03b837caf9f8f7 --- /dev/null +++ b/tests/driver_tsl4531x/Makefile @@ -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 diff --git a/tests/driver_tsl4531x/main.c b/tests/driver_tsl4531x/main.c new file mode 100644 index 0000000000000000000000000000000000000000..644b6d1ad12d4e985aade472b41799697c98e1f2 --- /dev/null +++ b/tests/driver_tsl4531x/main.c @@ -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; +}