tests/driver_dht: adapted to driver changes
This commit is contained in:
parent
3afc3eb10b
commit
c6aa413320
@ -2,6 +2,7 @@ APPLICATION = driver_dht
|
|||||||
include ../Makefile.tests_common
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
USEMODULE += dht
|
USEMODULE += dht
|
||||||
|
USEMODULE += fmt
|
||||||
USEMODULE += xtimer
|
USEMODULE += xtimer
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Ludwig Knüpfer, Christian Mehlis
|
* Copyright (C) 2015 Ludwig Knüpfer, Christian Mehlis
|
||||||
* 2016 Freie Universität Berlin
|
* 2016-2017 Freie Universität Berlin
|
||||||
*
|
*
|
||||||
* This file is subject to the terms and conditions of the GNU Lesser
|
* 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
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
@ -24,41 +24,48 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
|
#include "timex.h"
|
||||||
|
#include "fmt.h"
|
||||||
#include "dht.h"
|
#include "dht.h"
|
||||||
#include "dht_params.h"
|
#include "dht_params.h"
|
||||||
|
|
||||||
extern dht_t dht_devs[];
|
#define DELAY (2 * US_PER_SEC)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
dht_t dev;
|
||||||
|
int16_t temp, hum;
|
||||||
|
char temp_s[10];
|
||||||
|
char hum_s[10];
|
||||||
|
|
||||||
puts("DHT temperature and humidity sensor test application\n");
|
puts("DHT temperature and humidity sensor test application\n");
|
||||||
|
|
||||||
|
/* initialize first configured sensor */
|
||||||
|
printf("Initializing DHT sensor...\t");
|
||||||
|
if (dht_init(&dev, &dht_params[0]) == DHT_OK) {
|
||||||
|
puts("[OK]\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
puts("[Failed]");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* periodically read temp and humidity values */
|
/* periodically read temp and humidity values */
|
||||||
while (1) {
|
while (1) {
|
||||||
for (unsigned i = 0; i < DHT_NUMOF; i++) {
|
if (dht_read(&dev, &temp, &hum) != DHT_OK) {
|
||||||
dht_t *dev = &dht_devs[i];
|
puts("Error reading values");
|
||||||
int16_t temp, hum;
|
continue;
|
||||||
int16_t dec_temp, dec_hum, int_temp, int_hum;
|
|
||||||
|
|
||||||
if (dht_read(dev, &temp, &hum) == -1) {
|
|
||||||
puts("error reading data");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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 #%u - ", i);
|
|
||||||
printf("temp: %i.%i°C, ", int_temp, dec_temp);
|
|
||||||
printf("relative humidity: %i.%i%%\n", int_hum, dec_hum);
|
|
||||||
|
|
||||||
xtimer_usleep(2000 * US_PER_MS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t n = fmt_s16_dfp(temp_s, temp, 1);
|
||||||
|
temp_s[n] = '\0';
|
||||||
|
n = fmt_s16_dfp(hum_s, hum, 1);
|
||||||
|
hum_s[n] = '\0';
|
||||||
|
|
||||||
|
printf("DHT values - temp: %s°C - relative humidity: %s%%\n",
|
||||||
|
temp_s, hum_s);
|
||||||
|
|
||||||
|
xtimer_usleep(DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user