From fb6c75f6d88a70feab664c183c62f50dfbaf08a7 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Fri, 1 May 2015 15:44:15 +0200 Subject: [PATCH] tests/driver_isl29125: initial import --- tests/driver_isl29125/Makefile | 22 +++++++++ tests/driver_isl29125/README.md | 12 +++++ tests/driver_isl29125/main.c | 86 +++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 tests/driver_isl29125/Makefile create mode 100644 tests/driver_isl29125/README.md create mode 100644 tests/driver_isl29125/main.c diff --git a/tests/driver_isl29125/Makefile b/tests/driver_isl29125/Makefile new file mode 100644 index 0000000000..0450ce888f --- /dev/null +++ b/tests/driver_isl29125/Makefile @@ -0,0 +1,22 @@ +APPLICATION = driver_isl29125 +include ../Makefile.tests_common + +FEATURES_REQUIRED = periph_i2c + +USEMODULE += isl29125 +USEMODULE += vtimer + +ifneq (,$(TEST_ISL29125_I2C)) + CFLAGS += -DTEST_ISL29125_I2C=$(TEST_ISL29125_I2C) +else + # set random default + CFLAGS += -DTEST_ISL29125_I2C=I2C_0 +endif +ifneq (,$(TEST_ISL29125_IRQ_PIN)) + CFLAGS += -DTEST_ISL29125_IRQ_PIN=$(TEST_ISL29125_IRQ_PIN) +else + # set random default + CFLAGS += -DTEST_ISL29125_IRQ_PIN=GPIO_5 +endif + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_isl29125/README.md b/tests/driver_isl29125/README.md new file mode 100644 index 0000000000..4b8ec60983 --- /dev/null +++ b/tests/driver_isl29125/README.md @@ -0,0 +1,12 @@ +# About +This is a manual test application for the ISL29125 light sensor driver. + +# Usage +This test application will initialize the list sensor with the following parameters: + - Mode: All modes are tested once, then RGB mode is used continuously + - Range: 16000 lux + - Resolution: 16 bit + +After initialization, the sensor value is read every 250ms and printed to the stdout. + +Expose the sensor to varying light sources to see changing readouts. diff --git a/tests/driver_isl29125/main.c b/tests/driver_isl29125/main.c new file mode 100644 index 0000000000..0fbe740b90 --- /dev/null +++ b/tests/driver_isl29125/main.c @@ -0,0 +1,86 @@ +/* + * Copyright 2015 Ludwig Ortmann + * + * 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 ISL29125 RGB light sensor + * + * @author Ludwig Ortmann + * + * @} + */ + +#ifndef TEST_ISL29125_I2C +#error "TEST_ISL29125_I2C not defined" +#endif + +#ifndef TEST_ISL29125_IRQ_PIN +#error "ISL29125_IRQ_PIN not defined" +#endif + +#include +#include + +#include "vtimer.h" +#include "isl29125.h" + +#define SLEEP (250 * 1000U) + +int main(void) +{ + isl29125_t dev; + isl29125_rgb_t data; + color_rgb_t data8bit; + memset(&data, 0x00, sizeof(data)); + + puts("ISL29125 light sensor test application\n"); + printf("Initializing ISL29125 sensor at I2C_%i... ", TEST_ISL29125_I2C); + if (isl29125_init(&dev, TEST_ISL29125_I2C, TEST_ISL29125_IRQ_PIN, + ISL29125_MODE_RGB, ISL29125_RANGE_10K, + ISL29125_RESOLUTION_16) == 0) { + puts("[OK]\n"); + } + else { + puts("[Failed]"); + return 1; + } + + /* try out some modes */ + static const isl29125_mode_t modes[] = { + ISL29125_MODE_DOWN, ISL29125_MODE_STANDBY, ISL29125_MODE_RGB, + ISL29125_MODE_R, ISL29125_MODE_G, ISL29125_MODE_B, + ISL29125_MODE_RG, ISL29125_MODE_GB}; + static const char* mode_names[] = { + "ISL29125_MODE_DOWN", "ISL29125_MODE_STANDBY", "ISL29125_MODE_RGB", + "ISL29125_MODE_R", "ISL29125_MODE_G", "ISL29125_MODE_B", + "ISL29125_MODE_RG", "ISL29125_MODE_GB"}; + + for (int i = 0; i < sizeof(modes); i++) { + printf("Setting mode %s\n", mode_names[i]); + isl29125_set_mode(&dev, modes[i]); + vtimer_usleep(SLEEP); + isl29125_read_rgb_color(&dev, &data8bit); + printf("RGB value: (%3i / %3i / %3i) 8 bit\n", + data8bit.r, data8bit.g, data8bit.b); + } + + puts("Resetting mode to RGB and reading continuously"); + isl29125_set_mode(&dev, ISL29125_MODE_RGB); + vtimer_usleep(SLEEP); + while (1) { + isl29125_read_rgb_lux(&dev, &data); + printf("RGB value: (%5i / %5i / %5i) lux\n", + (int)data.red, (int)data.green, (int)data.blue); + vtimer_usleep(SLEEP); + } + + return 0; +}