Add DHT temp/humidity getters.

+float mgos_prometheus_sensors_dht_get_temp(uint8_t idx);
+float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx);

They return NAN if the index is invalid, or the sensor couldn't be
found. Otherwise, they return the last measured temperature or humidity
values as floats.
This commit is contained in:
Pim van Pelt
2018-03-04 17:01:17 +01:00
parent 0d48de1ba8
commit f43dea1d7b
2 changed files with 19 additions and 0 deletions

View File

@ -4,4 +4,7 @@
#include "mgos.h" #include "mgos.h"
#include "mgos_gpio.h" #include "mgos_gpio.h"
float mgos_prometheus_sensors_dht_get_temp(uint8_t idx);
float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx);
#endif // __MGOS_PROMETHEUS_SENSORS_H #endif // __MGOS_PROMETHEUS_SENSORS_H

View File

@ -91,6 +91,22 @@ static bool dht_sensor_create(int pin, enum dht_type type) {
return true; return true;
} }
float mgos_prometheus_sensors_dht_get_temp(uint8_t idx) {
if (idx>=s_num_dht)
return NAN;
if (!s_dht_sensor[idx])
return NAN;
return s_dht_sensor[idx]->temp;
}
float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx) {
if (idx>=s_num_dht)
return NAN;
if (!s_dht_sensor[idx])
return NAN;
return s_dht_sensor[idx]->humidity;
}
void dht_init() { void dht_init() {
char *tok; char *tok;