From edce26bb156a321db5a544f59709620805e9ccff Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 21 Jan 2016 18:42:48 +0100 Subject: [PATCH] tests/driver_dht: adjusted to interface changes --- tests/driver_dht/main.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/driver_dht/main.c b/tests/driver_dht/main.c index fdda35cd5b..aa651e0a86 100644 --- a/tests/driver_dht/main.c +++ b/tests/driver_dht/main.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 Ludwig Knüpfer, Christian Mehlis + * 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 @@ -15,6 +16,7 @@ * * @author Ludwig Knüpfer * @author Christian Mehlis + * @author Hauke Petersen * * @} */ @@ -29,22 +31,32 @@ extern dht_t dht_devs[]; int main(void) { - dht_data_t data; - float temp, hum; - puts("DHT temperature and humidity sensor test application\n"); /* periodically read temp and humidity values */ while (1) { for (unsigned i = 0; i < DHT_NUMOF; i++) { dht_t *dev = &dht_devs[i]; + int16_t temp, hum; + int16_t dec_temp, dec_hum, int_temp, int_hum; - if (dht_read_raw(dev, &data) == -1) { + if (dht_read(dev, &temp, &hum) == -1) { puts("error reading data"); + continue; } - dht_parse(dev, &data, &hum, &temp); - printf("raw relative humidity: %i\nraw temperature: %i C\n", data.humidity, data.temperature); - printf("relative humidity: %i\ntemperature: %i C\n", (int) hum, (int) temp); + + /* split up values into integral and fractional parts for nicer + * printing + * TODO: this should be done in some kind of library... */ + int_temp = temp / 10; + dec_temp = temp - (int_temp * 10); + int_hum = hum / 10; + dec_hum = hum - (int_hum * 10); + + printf("DHT device #%i - ", i); + printf("temp: %i.%i°C, ", int_temp, dec_temp); + printf("relative humidity: %i.%i%%\n", int_hum, dec_hum); + xtimer_usleep(2000 * MS_IN_USEC); } }