diff --git a/tests/driver_tsl4531x/Makefile b/tests/driver_tsl4531x/Makefile index 0e35e6a9eb6e19a3bdfa06699d03b837caf9f8f7..487030b625962f9f58668b9267ba7b732b6986b2 100644 --- a/tests/driver_tsl4531x/Makefile +++ b/tests/driver_tsl4531x/Makefile @@ -1,12 +1,6 @@ -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/README.md b/tests/driver_tsl4531x/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b6e4b7082600d8aae07f14d2b3d9d4fe39679171 --- /dev/null +++ b/tests/driver_tsl4531x/README.md @@ -0,0 +1,10 @@ +## About + +This is a test application for the TSL4531x Lux sensor series. + +## Usage + +The application first initializes the TSL2561x sensor. + +After initialization, the test application runs through a series of tests to +allow the user to manually verify the correct operation of the sensor driver. diff --git a/tests/driver_tsl4531x/main.c b/tests/driver_tsl4531x/main.c index 644b6d1ad12d4e985aade472b41799697c98e1f2..ae96b592a3e5c84d43d1c9d26722f00398b0ff33 100644 --- a/tests/driver_tsl4531x/main.c +++ b/tests/driver_tsl4531x/main.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Inria + * Copyright (C) 2018 Freie Universität Berlin * * 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 @@ -11,9 +12,9 @@ * @{ * * @file - * @brief Test application for the TSL2561 Lux sensor + * @brief Test application for the TSL4531x Lux sensor * - * @author Alexandre Abadie <alexandre.abadie@inria.fr> + * @author Daniel Petry <daniel.petry@fu-berlin.de> * * @} */ @@ -26,6 +27,7 @@ #include "periph/i2c.h" #include "tsl4531x.h" +#include "tsl4531x_params.h" #define _100ms_in_us (100 * 1000u) /* 1 second delay between printf */ @@ -36,22 +38,79 @@ int main(void) 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)); + if ((err = tsl4531x_init(&dev, tsl4531x_params)) < 0) { + printf("[Error] Device not initialised. Error code: %d\n", err); return 1; } - puts("Initialized, will begin measurements."); + puts("[Info] Initialized, beginning test."); + 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); + printf("-------------------------------------------------------------"); + printf("-------------------------\n"); + + /* Set into high power mode */ + tsl4531x_set_low_power_mode(&dev, false); + + /* Test simple read - high power mode */ + lux = tsl4531x_simple_read(&dev); + printf("Illuminance | High power mode | Synchronous read |"); + printf(" [lx] | %u\n", lux); + + /* Determine the actual integration time - how long does it take for a + value to change? + Note that if the sensor value doesn't change between integration + cycles, this will sum the previous integration times. This mostly + won't happen, but it's best to let this run for a few cycles and take + the minimum. */ + uint16_t lux_last = lux; + uint8_t changes = 0; + uint32_t change_times[2]; + while (changes < 2) { + lux = tsl4531x_get_sample(&dev); + if (lux != lux_last) { + lux_last = lux; + change_times[changes] = xtimer_now_usec(); + changes++; + } } + printf("Sample ready time | High power mode | From device |"); + printf(" [us] | %lu\n", (unsigned long)(change_times[1] - change_times[0])); + + /* Set into low power mode */ + tsl4531x_set_low_power_mode(&dev, true); + + /* This tests what happens when you read without asking for a sample in + low power mode. */ + lux = tsl4531x_get_sample(&dev); + printf("Illuminance | Low power mode | Immediate read after mode change |"); + printf(" [lx] | %u\n", lux); + xtimer_usleep(tsl4531x_time_until_sample_ready(&dev)); + lux = tsl4531x_get_sample(&dev); + printf("Illuminance | Low power mode | One cycle time after mode change |"); + printf(" [lx] | %u\n", lux); + + /* Test synchronous read - low power mode */ + lux = tsl4531x_simple_read(&dev); + printf("Illuminance | Low power mode | Synchronous read |"); + printf(" [lx] | %u\n", lux); + + /* Test asynchronous read - low power mode */ + tsl4531x_start_sample(&dev); + + /* Verify that the stated time until sample ready is reasonable. */ + uint32_t t = tsl4531x_time_until_sample_ready(&dev); + xtimer_usleep(t); + lux = tsl4531x_get_sample(&dev); + printf("Illuminance | Low power mode | Asynchronous read |"); + printf(" [lx] | %u\n", lux); + printf("Sample ready time | Low power mode | From driver |"); + printf(" [us] | %lu\n", (unsigned long)t); + xtimer_usleep(_100ms_in_us); }