From b99bd67efd8b6cc80294b0efc9abf88ab6b03c86 Mon Sep 17 00:00:00 2001 From: Juan Carrano <j.carrano@fu-berlin.de> Date: Mon, 10 Sep 2018 14:15:19 +0200 Subject: [PATCH] tests/driver_tsl4531x: Add tests for illuminance sensor. Missing README. --- tests/driver_tsl4531x/Makefile | 12 +++++++ tests/driver_tsl4531x/main.c | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/driver_tsl4531x/Makefile create mode 100644 tests/driver_tsl4531x/main.c diff --git a/tests/driver_tsl4531x/Makefile b/tests/driver_tsl4531x/Makefile new file mode 100644 index 0000000000..0e35e6a9eb --- /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 0000000000..644b6d1ad1 --- /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; +} -- GitLab