Skip to content

Commit

Permalink
Arduino ci (#7)
Browse files Browse the repository at this point in the history
* add Arduino-CI
* add unit test
  • Loading branch information
RobTillaart committed Jan 8, 2021
1 parent 82ec951 commit 82aecbb
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
13 changes: 13 additions & 0 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 44 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion examples/dewpoint_test/dewpoint_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion examples/heatindexC_table/heatindexC_table.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-04-04
//


#include "temperature.h"


volatile float hi;

void setup()
Expand Down
3 changes: 2 additions & 1 deletion examples/heatindexC_test/heatindexC_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-04-04
//


#include "temperature.h"


uint32_t start;
uint32_t duration1;

Expand Down
3 changes: 2 additions & 1 deletion examples/heatindex_table/heatindex_table.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-04-04
//


#include "temperature.h"


volatile float hi;

void setup()
Expand Down
3 changes: 2 additions & 1 deletion examples/humidex_table/humidex_table.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-04-05
//


#include "temperature.h"


void setup()
{
Serial.begin(115200);
Expand Down
3 changes: 2 additions & 1 deletion examples/humidex_test/humidex_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-04-05
//


#include "temperature.h"


uint32_t start;
uint32_t duration1;

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/Temperature"
},
"version":"0.2.3",
"version":"0.2.4",
"frameworks": "arduino",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Temperature
version=0.2.3
version=0.2.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library with weather related functions.
Expand Down
26 changes: 15 additions & 11 deletions temperature.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
88 changes: 88 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
@@ -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 <ArduinoUnitTests.h>


#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()

// --------

0 comments on commit 82aecbb

Please sign in to comment.