From c45965ec6d563570f0d650b59e948a502bdd1df4 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Fri, 7 Jan 2022 08:57:45 +0100 Subject: [PATCH] fix adjustment (#12) --- README.md | 10 +++++- examples/heatindex_table/heatindex_table.ino | 16 ++++++++++ library.json | 2 +- library.properties | 2 +- temperature.h | 2 +- test/unit_test_001.cpp | 33 ++++++++++++++++++++ 6 files changed, 61 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 22461d9..f632cd6 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ These functions are approximations based on work of NOAA a.o. These functions can be used with temperature and humidity sensors e.g. DHT22 or Sensirion, to make a weather station application. +Note: pre-0.3.1 versions have incorrect heat-index. + ## Interface @@ -42,7 +44,9 @@ DHT22 or Sensirion, to make a weather station application. - **float heatIndex(float Fahrenheit, float humidity)** idem. - **float heatIndexC(float Celsius, float humidity)** idem. -**0.3.0** + +#### 0.3.0 + The formula for the **heatIndex()** was taken from https://en.wikipedia.org/wiki/Heat_index. Since version 0.3.0 the more elaborated version of https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml will be used. Note: there will be performance differences. @@ -57,6 +61,10 @@ Indicative table | 105-129 | 40-54 | very hot | red | | > 130 | > 54 | extreme hot | purple | +#### 0.3.1 + +Fixed the adjustment which was incorrectly added. + ### WindChill diff --git a/examples/heatindex_table/heatindex_table.ino b/examples/heatindex_table/heatindex_table.ino index 75af7d7..84da848 100644 --- a/examples/heatindex_table/heatindex_table.ino +++ b/examples/heatindex_table/heatindex_table.ino @@ -28,6 +28,21 @@ void setup() Serial.println(); Serial.println(); + for (int hum = 0; hum <= 100; hum += 2) + { + Serial.print(hum); + for (int t = 80; t <= 110; t += 2) + { + float hi = heatIndex(t, hum); + Serial.print("\t"); + Serial.print(round(hi)); + } + Serial.println(); + } + Serial.println(); + Serial.println(); + + /* for (int hum = 40; hum <= 100; hum += 5) { Serial.print(hum); @@ -41,6 +56,7 @@ void setup() } Serial.println(); Serial.println(); + */ Serial.print("Done..."); } diff --git a/library.json b/library.json index 6eeafb4..7341d46 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Temperature" }, - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 5f70f19..616af33 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Temperature -version=0.3.0 +version=0.3.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library with weather related functions. diff --git a/temperature.h b/temperature.h index 92b11e8..7d2d605 100644 --- a/temperature.h +++ b/temperature.h @@ -117,7 +117,7 @@ float heatIndex(float TF, float RH) HI = A + B + C; if ((RH < 13) && (TF <= 112)) { - HI += ((13 - RH) / 4) * sqrt((17 - abs(TF - 95.0)) / 17); + HI -= ((13 - RH) / 4) * sqrt((17 - abs(TF - 95.0)) / 17); } if ((RH > 87) && (TF < 87)) { diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index e776a88..075f566 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -75,6 +75,39 @@ unittest(test_heatIndex) } +unittest(test_heatIndex_2) +{ + // Fahrenheit reference points + assertEqualFloat( 77, heatIndex(80, 00), 1); + assertEqualFloat( 78, heatIndex(80, 10), 1); + assertEqualFloat( 80, heatIndex(80, 40), 1); + assertEqualFloat( 82, heatIndex(80, 60), 1); + assertEqualFloat( 86, heatIndex(80, 90), 1); + assertEqualFloat( 89, heatIndex(80, 100), 1); + fprintf(stderr, "\n"); + assertEqualFloat( 84, heatIndex(90, 00), 1); + assertEqualFloat( 85, heatIndex(90, 10), 1); + assertEqualFloat( 91, heatIndex(90, 40), 1); + assertEqualFloat(100, heatIndex(90, 60), 1); + assertEqualFloat(122, heatIndex(90, 90), 1); + assertEqualFloat(132, heatIndex(90, 100), 1); + fprintf(stderr, "\n"); + assertEqualFloat( 91, heatIndex(100, 00), 1); + assertEqualFloat( 94, heatIndex(100, 10), 1); + assertEqualFloat(109, heatIndex(100, 40), 1); + assertEqualFloat(129, heatIndex(100, 60), 1); + assertEqualFloat(176, heatIndex(100, 90), 1); + assertEqualFloat(195, heatIndex(100, 100), 1); + fprintf(stderr, "\n"); + assertEqualFloat( 99, heatIndex(110, 00), 1); + assertEqualFloat(104, heatIndex(110, 10), 1); + assertEqualFloat(136, heatIndex(110, 40), 1); + assertEqualFloat(171, heatIndex(110, 60), 1); + assertEqualFloat(247, heatIndex(110, 90), 1); + assertEqualFloat(278, heatIndex(110, 100), 1); +} + + unittest(test_windChill) { assertEqualFloat(107.108, WindChill_F_mph (100, 10, true), 0.001);