From 2c72a53465b0d3b65746db096d8e43e4ce57ab13 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Tue, 30 Jul 2019 02:16:07 +0200 Subject: [PATCH] not a number --- src/main.cpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b5bf0a7..8f73c9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,15 +51,15 @@ XD0OTA ota("esp32-weatherstation"); XD0MQTT mqtt; struct __attribute__((packed)) sensor_readings_t { - float temperature = 0.0; // °C - float humidity = 0.0; // %H - float pressure = 0.0; // Pa + float temperature = NAN; // °C + float humidity = NAN; // %H + float pressure = NAN; // Pa uint32_t voc = 0; // Ohm - float pm10 = 0.0; // µg/m³ - float pm25 = 0.0; // µg/m³ - float uvi = 0.0; - float uva = 0.0; - float uvb = 0.0; + float pm10 = NAN; // µg/m³ + float pm25 = NAN; // µg/m³ + float uvi = NAN; + float uva = NAN; + float uvb = NAN; float temperature_max = NAN; // °C float temperature_min = NAN; // °C } sensor_readings; @@ -266,18 +266,18 @@ void displayValues() { if (sds_active) { pm10 = sensor_readings.pm10; pm25 = sensor_readings.pm25; - } else if (std::isnormal(sensors_a4cf1211c3e4.pm10) || std::isnormal(sensors_a4cf1211c3e4.pm25)) { + } else if (!isnan(sensors_a4cf1211c3e4.pm10) || !isnan(sensors_a4cf1211c3e4.pm25)) { pm10 = sensors_a4cf1211c3e4.pm10; pm25 = sensors_a4cf1211c3e4.pm25; - } else if (std::isnormal(sensors_246f28d1fa5c.pm10) || std::isnormal(sensors_246f28d1fa5c.pm25)) { + } else if (!isnan(sensors_246f28d1fa5c.pm10) || !isnan(sensors_246f28d1fa5c.pm25)) { pm10 = sensors_246f28d1fa5c.pm10; pm25 = sensors_246f28d1fa5c.pm25; - } else if (std::isnormal(sensors_246f28d1a080.pm10) || std::isnormal(sensors_246f28d1a080.pm25)) { + } else if (!isnan(sensors_246f28d1a080.pm10) || !isnan(sensors_246f28d1a080.pm25)) { pm10 = sensors_246f28d1a080.pm10; pm25 = sensors_246f28d1a080.pm25; } else { - pm10 = 0.0; - pm25 = 0.0; + pm10 = NAN; + pm25 = NAN; } display.setCursor(200,y_offset+45); display.println("PM10 / 2.5:"); @@ -291,22 +291,22 @@ void displayValues() { uvi = sensor_readings.uvi; uva = sensor_readings.uva; uvb = sensor_readings.uvb; - } else if (std::isnormal(sensors_a4cf1211c3e4.uvi) || std::isnormal(sensors_a4cf1211c3e4.uva) || std::isnormal(sensors_a4cf1211c3e4.uvb)) { + } else if (!isnan(sensors_a4cf1211c3e4.uvi) || !isnan(sensors_a4cf1211c3e4.uva) || !isnan(sensors_a4cf1211c3e4.uvb)) { uvi = sensors_a4cf1211c3e4.uvi; uva = sensors_a4cf1211c3e4.uva; uvb = sensors_a4cf1211c3e4.uvb; - } else if (std::isnormal(sensors_246f28d1fa5c.uvi) || std::isnormal(sensors_246f28d1fa5c.uva) || std::isnormal(sensors_246f28d1fa5c.uvb)) { + } else if (!isnan(sensors_246f28d1fa5c.uvi) || !isnan(sensors_246f28d1fa5c.uva) || !isnan(sensors_246f28d1fa5c.uvb)) { uvi = sensors_246f28d1fa5c.uvi; uva = sensors_246f28d1fa5c.uva; uvb = sensors_246f28d1fa5c.uvb; - } else if (std::isnormal(sensors_246f28d1a080.uvi) || std::isnormal(sensors_246f28d1a080.uva) || std::isnormal(sensors_246f28d1a080.uvb)) { + } else if (!isnan(sensors_246f28d1a080.uvi) || !isnan(sensors_246f28d1a080.uva) || !isnan(sensors_246f28d1a080.uvb)) { uvi = sensors_246f28d1a080.uvi; uva = sensors_246f28d1a080.uva; uvb = sensors_246f28d1a080.uvb; } else { - uvi = 0.0; - uva = 0.0; - uvb = 0.0; + uvi = NAN; + uva = NAN; + uvb = NAN; } display.setCursor(200,y_offset+85); display.println("UV Index/A/B:"); @@ -532,12 +532,9 @@ void loop() lastDisplayUpdate = millis(); getSensorMeasurements(); - displayValues(); - printValues(); sendValues(); - } if(wifiMulti.run() != WL_CONNECTED) {