From 49dd104fd67bceb7f2bc475417fd2fe5ede12368 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 14 Jan 2016 12:14:06 +0100 Subject: [PATCH] tests: added test app for the bh1750fvi driver --- tests/driver_bh1750/Makefile | 7 ++++++ tests/driver_bh1750/README.md | 15 +++++++++++ tests/driver_bh1750/main.c | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/driver_bh1750/Makefile create mode 100644 tests/driver_bh1750/README.md create mode 100644 tests/driver_bh1750/main.c diff --git a/tests/driver_bh1750/Makefile b/tests/driver_bh1750/Makefile new file mode 100644 index 000000000000..1c1d05f88e77 --- /dev/null +++ b/tests/driver_bh1750/Makefile @@ -0,0 +1,7 @@ +APPLICATION = driver_pir +include ../Makefile.tests_common + +USEMODULE += xtimer +USEMODULE += bh1750fvi + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_bh1750/README.md b/tests/driver_bh1750/README.md new file mode 100644 index 000000000000..31a98ec92be1 --- /dev/null +++ b/tests/driver_bh1750/README.md @@ -0,0 +1,15 @@ +# About +This test application is created for testing/demonstrating the BH1750FVI driver. +It uses the default device parameters as specified in +`drivers/bh1750fvi/include/bh1750fvi_params.h`. To override these setting, you +can simply do this by defining these parameters as compiler flags while uilding, +e.g.: +``` +$ CFLAGS="-DBH1750FVI_PARAM_I2C=I2C_DEV(1)"" make all +``` + +# Usage +Simply flash this example to your board and it will read the sensor value 5 +times per second and print the sampled value to STDIO. You can verify the values +by simply covering the sensor or holding it in front of a bright light and see +the change in the sensor readings accordingly. diff --git a/tests/driver_bh1750/main.c b/tests/driver_bh1750/main.c new file mode 100644 index 000000000000..d3fe8a9bbe0c --- /dev/null +++ b/tests/driver_bh1750/main.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2016 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 + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test application for the BH1750FVI ambient light sensor driver + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "xtimer.h" +#include "bh1750fvi.h" +#include "bh1750fvi_params.h" + +#define RATE (200 * MS_IN_USEC) /* 200ms */ + +int main(void) +{ + bh1750fvi_t dev; + uint32_t last = xtimer_now(); + + puts("BH1750FVI ambient light sensor test\n"); + + /* initialize the device */ + bh1750fvi_init(&dev, (bh1750fvi_params_t *)(&bh1750fvi_params)); + + /* periodically sample the sensor */ + while(1) { + uint16_t val = bh1750fvi_sample(&dev); + printf("value: %5i lux\n", (int)val); + xtimer_usleep_until(&last, RATE); + } + + return 0; +}