diff --git a/.arduino-ci.yml b/.arduino-ci.yml new file mode 100644 index 0000000..ff5659b --- /dev/null +++ b/.arduino-ci.yml @@ -0,0 +1,7 @@ +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + - uno + - leonardo + - due + - zero diff --git a/.github/workflows/arduino_test_runner.yml b/.github/workflows/arduino_test_runner.yml new file mode 100644 index 0000000..476456b --- /dev/null +++ b/.github/workflows/arduino_test_runner.yml @@ -0,0 +1,13 @@ +--- +name: Arduino CI + +on: [push, pull_request] + +jobs: + arduino_ci: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: Arduino-CI/action@master + # Arduino-CI/action@v0.1.1 diff --git a/LICENSE b/LICENSE index ed401f2..d29d575 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2020 Rob Tillaart +Copyright (c) 2017-2021 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e6de0ce..9fce1f2 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,55 @@ + +[![Arduino CI](https://github.com/RobTillaart/Temperature/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Temperature/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/Temperature.svg?maxAge=3600)](https://github.com/RobTillaart/Temperature/releases) + + # Temperature Arduino library with dewPoint, humidex, heatIndex and windchill functions. + ## Description -This library contains some weather related functions. These functions -are approximations based on work of NOAA a.o. +This library contains weather related functions. +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 ones to make a weather station application. +DHT22 or Sensirion, to make a weather station application. + + +## Interface + +TO elaborate + +### Conversion + +- **float Fahrenheit(celsius)** idem +- **float Celsius(fahrenheit)** idem +- **float Kelvin(celsius)** idem + + +### DewPoint, humidex + +- **float dewPoint(celsius, humidity)** idem +- **float dewPointFast(celsius, humidity)** idem +- **float humidex(celsius, dewpoint)** idem + + +### heatIndex + +- **float heatIndex(fahrenheit, humidity)** idem +- **float heatIndexC(celsius, humidity)** idem + + +### WindChill + +Windspeed @ 10 meter, if convert is true => windspeed will be converted to 1.5 meter +else ==> formula assumes windspeed @ 1.5 meter + +- **float WindChill_F_mph(fahrenheit, milesPerHour, convert = true)** +- **float WindChill_C_kmph(celcius, kilometerPerHour, convert = true)** +- **float WindChill_C_mps(celsius, meterPerSecond, convert = true)** ## Operations diff --git a/examples/dewpoint_test/dewpoint_test.ino b/examples/dewpoint_test/dewpoint_test.ino index 6b24a22..cc2bce4 100644 --- a/examples/dewpoint_test/dewpoint_test.ino +++ b/examples/dewpoint_test/dewpoint_test.ino @@ -4,10 +4,11 @@ // VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-04-04 -// + #include "temperature.h" + uint32_t start; uint32_t duration1; uint32_t duration2; diff --git a/examples/heatindexC_table/heatindexC_table.ino b/examples/heatindexC_table/heatindexC_table.ino index 6cf1b21..d263edf 100644 --- a/examples/heatindexC_table/heatindexC_table.ino +++ b/examples/heatindexC_table/heatindexC_table.ino @@ -4,10 +4,11 @@ // VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-04-04 -// + #include "temperature.h" + volatile float hi; void setup() diff --git a/examples/heatindexC_test/heatindexC_test.ino b/examples/heatindexC_test/heatindexC_test.ino index 0208169..2d2c827 100644 --- a/examples/heatindexC_test/heatindexC_test.ino +++ b/examples/heatindexC_test/heatindexC_test.ino @@ -4,10 +4,11 @@ // VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-04-04 -// + #include "temperature.h" + uint32_t start; uint32_t duration1; diff --git a/examples/heatindex_table/heatindex_table.ino b/examples/heatindex_table/heatindex_table.ino index 5317b8b..69f1467 100644 --- a/examples/heatindex_table/heatindex_table.ino +++ b/examples/heatindex_table/heatindex_table.ino @@ -4,10 +4,11 @@ // VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-04-04 -// + #include "temperature.h" + volatile float hi; void setup() diff --git a/examples/humidex_table/humidex_table.ino b/examples/humidex_table/humidex_table.ino index 6785263..250d446 100644 --- a/examples/humidex_table/humidex_table.ino +++ b/examples/humidex_table/humidex_table.ino @@ -4,10 +4,11 @@ // VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-04-05 -// + #include "temperature.h" + void setup() { Serial.begin(115200); diff --git a/examples/humidex_test/humidex_test.ino b/examples/humidex_test/humidex_test.ino index 1a9c126..e5c962c 100644 --- a/examples/humidex_test/humidex_test.ino +++ b/examples/humidex_test/humidex_test.ino @@ -4,10 +4,11 @@ // VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-04-05 -// + #include "temperature.h" + uint32_t start; uint32_t duration1; diff --git a/library.json b/library.json index 47ad568..07a4922 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Temperature" }, - "version":"0.2.3", + "version":"0.2.4", "frameworks": "arduino", "platforms": "*" } diff --git a/library.properties b/library.properties index 1aadf22..5e31641 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Temperature -version=0.2.3 +version=0.2.4 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library with weather related functions. diff --git a/temperature.h b/temperature.h index 31b5fc1..63c4bef 100644 --- a/temperature.h +++ b/temperature.h @@ -1,21 +1,22 @@ #pragma once // // FILE: temperature.h -// VERSION: 0.2.3 +// VERSION: 0.2.4 // PURPOSE: temperature functions // -// HISTORY: -// 0.1.0 - 2015-03-29 initial version -// 0.1.1 - 2017-07-26 double to float (issue #33) -// 0.2.0 - 2020-04-04 #pragma once, removed WProgram.h, readme.md, comments -// replaced obsolete links with new ones, -// tested and removed some code -// 0.2.1 2020-05-26 added windchill formulas -// 0.2.2 2020-06-19 fix library.json -// 0.2.3 2020-08-27 fix #5 order of functions, typo, fixed 1 example +// HISTORY: +// 0.1.0 2015-03-29 initial version +// 0.1.1 2017-07-26 double to float (issue #33) +// 0.2.0 2020-04-04 #pragma once, removed WProgram.h, readme.md, comments +// replaced obsolete links with new ones, +// tested and removed some code +// 0.2.1 2020-05-26 added windchill formulas +// 0.2.2 2020-06-19 fix library.json +// 0.2.3 2020-08-27 fix #5 order of functions, typo, fixed 1 example +// 0.2.4 2021-01-08 Arduino-CI + unit tests -#define TEMPERATURE_VERSION "0.2.3" +#define TEMPERATURE_VERSION (F("0.2.4")) inline float Fahrenheit(float celsius) @@ -137,6 +138,7 @@ float heatIndexC(float celcius, float humidity) // if convert is true => windspeed will be converted to 1.5 meter // else ==> formula assumes windspeed @ 1.5 meter + // US float WindChill_F_mph(const float fahrenheit, const float milesPerHour, const bool convert = true) { @@ -145,6 +147,7 @@ float WindChill_F_mph(const float fahrenheit, const float milesPerHour, const bo return 35.74 + 0.6125 * fahrenheit + (0.4275 * fahrenheit - 35.75) * windSpeed; } + // METRIC float WindChill_C_kmph(const float celcius, const float kilometerPerHour, const bool convert = true) { @@ -153,6 +156,7 @@ float WindChill_C_kmph(const float celcius, const float kilometerPerHour, const return 13.12 + 0.6215 * celcius + (0.3965 * celcius - 11.37) * windSpeed; } + float WindChill_C_mps(const float celcius, const float meterPerSecond, const bool convert = true) { return WindChill_C_kmph(celcius, meterPerSecond * 3.6, convert); diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp new file mode 100644 index 0000000..dde3972 --- /dev/null +++ b/test/unit_test_001.cpp @@ -0,0 +1,88 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2021-01-01 +// PURPOSE: unit tests for the temperature library +// https://github.com/RobTillaart/Temperature +// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md +// + +// supported assertions +// ---------------------------- +// assertEqual(expected, actual); // a == b +// assertNotEqual(unwanted, actual); // a != b +// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b)) +// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b)) +// assertLess(upperBound, actual); // a < b +// assertMore(lowerBound, actual); // a > b +// assertLessOrEqual(upperBound, actual); // a <= b +// assertMoreOrEqual(lowerBound, actual); // a >= b +// assertTrue(actual); +// assertFalse(actual); +// assertNull(actual); + +// // special cases for floats +// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon +// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon +// assertInfinity(actual); // isinf(a) +// assertNotInfinity(actual); // !isinf(a) +// assertNAN(arg); // isnan(a) +// assertNotNAN(arg); // !isnan(a) + +#include + + +#include "Arduino.h" +#include "temperature.h" + + + +unittest_setup() +{ +} + +unittest_teardown() +{ +} + + +unittest(test_conversion) +{ + fprintf(stderr, "VERSION: %s\n", TEMPERATURE_VERSION); + + assertEqualFloat(-40, Fahrenheit(-40), 0.001); + assertEqualFloat(-40, Celsius(-40), 0.001); + assertEqualFloat(273.15, Kelvin(0), 0.001); +} + + +unittest(test_dewpoint) +{ + assertEqualFloat(9.27985, dewPoint(20, 50), 0.001); + assertEqualFloat(9.25489, dewPointFast(20, 50), 0.001); + assertEqualFloat(21.2829, humidex(20, 10), 0.001); +} + + +unittest(test_heatIndex) +{ + assertEqualFloat(206.46, heatIndex(20, 50), 0.001); + assertEqualFloat(77.3509, heatIndex(68, 50), 0.001); + assertEqualFloat(25.1949, heatIndexC(20, 50), 0.001); +} + + +unittest(test_windChill) +{ + assertEqualFloat(107.108, WindChill_F_mph (100, 10, true), 0.001); + assertEqualFloat(40.8862, WindChill_C_kmph(37, 10, true), 0.001); + assertEqualFloat(41.9713, WindChill_C_mps (37, 10, true), 0.001); + assertEqualFloat(166.99, WindChill_F_mph (100, 10, false), 0.001); + assertEqualFloat(69.1205, WindChill_C_kmph(37, 10, false), 0.001); + assertEqualFloat(154.934, WindChill_C_mps (37, 10, false), 0.001); +} + + +unittest_main() + +// --------