From d34af3cb0e0313157b782615c1e2b89be063d948 Mon Sep 17 00:00:00 2001 From: Joakim Gebart <joakim.gebart@eistec.se> Date: Thu, 2 Jul 2015 12:09:16 +0200 Subject: [PATCH] tests/driver_hih6130: test application for drivers/hih6130 --- tests/driver_hih6130/Makefile | 22 +++++++++ tests/driver_hih6130/README.md | 7 +++ tests/driver_hih6130/main.c | 81 ++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 tests/driver_hih6130/Makefile create mode 100644 tests/driver_hih6130/README.md create mode 100644 tests/driver_hih6130/main.c diff --git a/tests/driver_hih6130/Makefile b/tests/driver_hih6130/Makefile new file mode 100644 index 0000000000..eecfc85e9c --- /dev/null +++ b/tests/driver_hih6130/Makefile @@ -0,0 +1,22 @@ +APPLICATION = driver_hih6130 +include ../Makefile.tests_common + +FEATURES_REQUIRED = periph_i2c + +USEMODULE += hih6130 +USEMODULE += vtimer + +ifneq (,$(TEST_HIH6130_I2C)) + CFLAGS += -DTEST_HIH6130_I2C=$(TEST_HIH6130_I2C) +else + # set arbitrary default + CFLAGS += -DTEST_HIH6130_I2C=I2C_0 +endif +ifneq (,$(TEST_HIH6130_ADDR)) + CFLAGS += -DTEST_HIH6130_ADDR=$(TEST_HIH6130_ADDR) +else + # factory default address + CFLAGS += -DTEST_HIH6130_ADDR=0x27 +endif + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_hih6130/README.md b/tests/driver_hih6130/README.md new file mode 100644 index 0000000000..fc81bd9124 --- /dev/null +++ b/tests/driver_hih6130/README.md @@ -0,0 +1,7 @@ +# About +This is a manual test application for the HIH6130 humidity and temperature sensor. + +# Usage + +After initialization, the sensor reads the measurement values every 100ms +and prints them to the STDOUT. diff --git a/tests/driver_hih6130/main.c b/tests/driver_hih6130/main.c new file mode 100644 index 0000000000..7585ab21b1 --- /dev/null +++ b/tests/driver_hih6130/main.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2015 Eistec AB + * + * 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 HIH6130 sensor driver + * + * @author Joakim Gebart <joakim.gebart@eistec.se> + * + * @} + */ + +#ifndef TEST_HIH6130_I2C +#error "TEST_HIH6130_I2C not defined" +#endif +#ifndef TEST_HIH6130_ADDR +#error "TEST_HIH6130_ADDR not defined" +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#include "vtimer.h" +#include "hih6130.h" + +#define SLEEP (100 * 1000U) + +int main(void) +{ + hih6130_t dev; + + puts("HIH6130 sensor driver test application\n"); + printf("Initializing I2C_%i... ", TEST_HIH6130_I2C); + if (i2c_init_master(TEST_HIH6130_I2C, I2C_SPEED_FAST) < 0) { + puts("[Failed]"); + return -1; + } + puts("[OK]"); + + printf("Initializing HIH6130 sensor at I2C_%i, address 0x%02x... ", + TEST_HIH6130_I2C, TEST_HIH6130_ADDR); + hih6130_init(&dev, TEST_HIH6130_I2C, TEST_HIH6130_ADDR); + puts("[OK]"); + + while (1) { + float hum = 0.f; + float temp = 0.f; + int status; + float integral = 0.f; + float fractional; + + vtimer_usleep(SLEEP); + + status = hih6130_get_humidity_temperature_float(&dev, &hum, &temp); + if (status < 0) { + printf("Communication error: %d\n", status); + continue; + } else if (status == 1) { + puts("Stale values"); + } + /* Several platforms usually build with nano.specs, (without float printf) */ + /* Split value into two integer parts for printing. */ + fractional = modff(hum, &integral); + printf("humidity: %4d.%04u %%", + (int)integral, (unsigned int)abs(fractional * 10000.f)); + fractional = modff(temp, &integral); + printf(" temperature: %4d.%04u C\n", + (int)integral, (unsigned int)abs(fractional * 10000.f)); + } + + return 0; +} -- GitLab