diff --git a/src/driver/drv_dht.c b/src/driver/drv_dht.c index 3e7365461..367ed8e7c 100644 --- a/src/driver/drv_dht.c +++ b/src/driver/drv_dht.c @@ -10,7 +10,10 @@ #include "drv_local.h" #include "drv_dht_internal.h" -dht_t *test = 0; +// test device +static dht_t *test = 0; +// per-pin devices +static dht_t **g_dhts = 0; // simplest demo void DHT_DoMyDHTTest() { @@ -26,7 +29,64 @@ void DHT_DoMyDHTTest() { addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "DHT says %f %f", humid, temp); } } - +int translateDHTType(int role) { + if (role == IOR_DHT11) + return DHT11; + if (role == IOR_DHT12) + return DHT12; + if (role == IOR_DHT21) + return DHT21; + if (role == IOR_DHT22) + return DHT22; + return 0; +} void DHT_OnEverySecond() { + int i; + int bHasDHT; + + bHasDHT = false; + + for (i = 0; i < PLATFORM_GPIO_MAX; i++) { + if (IS_PIN_DHT_ROLE(g_cfg.pins.roles[i])) { + bHasDHT = true; + } + } + if (bHasDHT == false) { + if (g_dhts) { + free(g_dhts); + g_dhts = 0; + } + // nothing to do here + return; + } + if (g_dhts==0) { + g_dhts = (dht_t**)malloc(sizeof(dht_t*)*PLATFORM_GPIO_MAX); + memset(g_dhts, 0, sizeof(dht_t*)*PLATFORM_GPIO_MAX); + } + for (i = 0; i < PLATFORM_GPIO_MAX; i++) { + if (IS_PIN_DHT_ROLE(g_cfg.pins.roles[i])) { + if (g_dhts[i] == 0) { + g_dhts[i] = DHT_Create(i, translateDHTType(g_cfg.pins.roles[i])); + } + if (g_dhts[i]) { + float temp, humid; + + humid = DHT_readHumidity(g_dhts[i], false); + temp = DHT_readTemperature(g_dhts[i], false, false); + + // don't want to loose accuracy, so multiply by 10 + // We have a channel types to handle that + CHANNEL_Set(g_cfg.pins.channels[i], (int)(temp * 10), 0); + CHANNEL_Set(g_cfg.pins.channels2[i], (int)(humid), 0); + } + } + else { + if (g_dhts[i] != 0) { + free(g_dhts[i]); + g_dhts[i] = 0; + } + } + } + } diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index b58e3c90b..635d03287 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -349,6 +349,21 @@ int http_fn_index(http_request_t* request) { poststr(request, ""); poststr(request, "
| ");
+ iValue = CHANNEL_Get(PIN_GetPinChannelForPinIndex(i));
+ hprintf255(request, "Sensor %s on pin %i temperature %.2fC", PIN_RoleToString(role), i,(float) (iValue*0.1f));
+ iValue = CHANNEL_Get(PIN_GetPinChannel2ForPinIndex(i));
+ hprintf255(request, ", humidity %.1f%% ", (float)iValue); + poststr(request, " |