From a3e187e767c7d26131b86f099fc126c8ca28871e Mon Sep 17 00:00:00 2001 From: Johann F Date: Sun, 31 May 2015 15:12:20 +0200 Subject: [PATCH] tests/driver_tcs37727: initial commit for tcs37727 driver test --- tests/driver_tcs37727/Makefile | 22 +++++++++++ tests/driver_tcs37727/README.md | 9 +++++ tests/driver_tcs37727/main.c | 68 +++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 tests/driver_tcs37727/Makefile create mode 100644 tests/driver_tcs37727/README.md create mode 100644 tests/driver_tcs37727/main.c diff --git a/tests/driver_tcs37727/Makefile b/tests/driver_tcs37727/Makefile new file mode 100644 index 000000000..103ef8bba --- /dev/null +++ b/tests/driver_tcs37727/Makefile @@ -0,0 +1,22 @@ +APPLICATION = driver_tcs37727 +include ../Makefile.tests_common + +FEATURES_REQUIRED = periph_i2c + +USEMODULE += tcs37727 +USEMODULE += xtimer + +ifneq (,$(TEST_TCS37727_I2C)) + CFLAGS += -DTEST_TCS37727_I2C=$(TEST_TCS37727_I2C) +else + # set random default + CFLAGS += -DTEST_TCS37727_I2C=I2C_0 +endif +ifneq (,$(TEST_TCS37727_ADDR)) + CFLAGS += -DTEST_TCS37727_ADDR=$(TEST_TCS37727_ADDR) +else + # set random default + CFLAGS += -DTEST_TCS37727_ADDR=0x29 +endif + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_tcs37727/README.md b/tests/driver_tcs37727/README.md new file mode 100644 index 000000000..0b56e735c --- /dev/null +++ b/tests/driver_tcs37727/README.md @@ -0,0 +1,9 @@ +# About +This is a manual test application for the TCS37727 driver. + +# Usage +This test application will initialize the TCS37717 sensor +with the following parameters: Gain 4x, RGBC on, Proximity Detection off + +After initialization, the sensor reads the RGBC ADC data every 1s +and prints them to STDOUT. diff --git a/tests/driver_tcs37727/main.c b/tests/driver_tcs37727/main.c new file mode 100644 index 000000000..d5aed411a --- /dev/null +++ b/tests/driver_tcs37727/main.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015 PHYTEC Messtechnik GmbH + * + * 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 TCS37727 sensor driver. + * + * @author Felix Siebel + * + * @} + */ + +#ifndef TEST_TCS37727_I2C +#error "TEST_TCS37727_I2C not defined" +#endif +#ifndef TEST_TCS37727_ADDR +#error "TEST_TCS37727_ADDR not defined" +#endif + +#include + +#include "xtimer.h" +#include "tcs37727.h" + +#define SLEEP (1000 * 1000U) + +int main(void) +{ + tcs37727_t dev; + tcs37727_data_t data; + + puts("TCS37727 RGBC Data; Sensor driver test application\n"); + printf("Initializing TCS37727 sensor at I2C_%i... ", TEST_TCS37727_I2C); + + if (tcs37727_init(&dev, TEST_TCS37727_I2C, TEST_TCS37727_ADDR, + TCS37727_ATIME_DEFAULT) == 0) { + puts("[OK]\n"); + } + else { + puts("[Failed]"); + return -1; + } + + if (tcs37727_set_rgbc_active(&dev)) { + puts("Measurement start failed."); + return -1; + } + + while (1) { + tcs37727_read(&dev, &data); + printf("R: %5"PRIu32" G: %5"PRIu32" B: %5"PRIu32" C: %5"PRIu32"\n", + data.red, data.green, data.blue, data.clear); + printf("CT : %5"PRIu32" Lux: %6"PRIu32" AGAIN: %2d ATIME %d\n", + data.ct, data.lux, dev.again, dev.atime_us); + + xtimer_usleep(SLEEP); + } + + return 0; +}