mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-26 06:53:52 +01:00
tests/tsl4531x: Add tests to cover API changes.
The changes to the test correspond to the change in the API and design of the driver, as described in the previous commit and in tsl4531x.h.
This commit is contained in:
parent
a1a834a726
commit
6fcb9ad552
@ -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
|
||||
|
||||
10
tests/driver_tsl4531x/README.md
Normal file
10
tests/driver_tsl4531x/README.md
Normal file
@ -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.
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user