0.1.0 pressure

This commit is contained in:
rob tillaart 2021-11-26 09:30:38 +01:00
parent bf245088e1
commit 163e74e3f8
12 changed files with 499 additions and 0 deletions

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021-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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,87 @@
[![Arduino CI](https://github.com/RobTillaart/pressure/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/pressure/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/pressure/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/pressure/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/pressure/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/pressure/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/pressure.svg?maxAge=3600)](https://github.com/RobTillaart/pressure/releases)
# pressure
Arduino library for pressure conversion.
## Description
Simple library to convert between several pressure formats.
It consists of a number of setters and getters and internally it uses millibar.
In fact it just hides all conversion constants.
Pressure is implemented as a float so this limits the precision of the value.
Note: as the conversion is 2 steps the conversion error might be larger than in a single conversion step.
Note: constants need to be verified.
## Interface
#### Constructor
- **pressure(float value = 0.0)** Constructor, with optional initial value.
#### setters
- **void setMilliBar(float value)** sets pressure in milliBar.
- **void setBar(float value)** sets pressure in bar.
- **void setPSI(float value)** sets pressure in PSI = Pounds per Square Inch.
- **void setATM(float value)** sets pressure in Atmosphere.
- **void setDynes(float value)** sets pressure in Dynes.
- **void setInchHg(float value)** sets pressure in inches mercury.
- **void setInchH2O(float value)** sets pressure in inches water.
- **void setPascal(float value)** sets pressure in Pascal. Note this is the **SI** unit.
- **void setTORR(float value)** sets pressure in TORR.
- **void setCmHg(float value)** sets pressure in centimetre mercury.
- **void setCmH2O(float value)** sets pressure in centimetre water.
- **void setMSW(float value)** sets pressure in Meters of Sea Water. (under water pressure unit).
#### getters
- **float getMilliBar()** returns pressure in milliBar.
- **float getBar()** returns pressure in bar.
- **float getPSI()** returns pressure in PSI = Pounds per Square Inch.
- **float getATM()** returns pressure in Atmosphere.
- **float getDynes()** returns pressure in Dynes.
- **float getInchHg()** returns pressure in inches mercury.
- **float getInchH2O()** returns pressure in inches water.
- **float getPascal()** returns pressure in Pascal. Note this is the **SI** unit.
- **float getTORR()** returns pressure in TORR.
- **float getCmHg()** returns pressure in centimetre mercury.
- **float getCmH2O()** returns pressure in centimetre water.
- **float getMSW()** returns pressure in Meters of Sea Water. (under water pressure unit).
## Operation
```cpp
pressure P;
...
P.setDynes(1000);
Serial.print("mBar: ");
Serial.println(P.getMilliBar()); // 1000 Dynes in mBar
Serial.print("TORR: ");
Serial.println(P.getTORR()); // 1000 Dynes in Torr
```
## Future
- update documentation
- find a good reference for conversion formula constants.

View File

@ -0,0 +1,44 @@
//
// FILE: pressure_demo.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2021-11-25
// URL: https://github.com/RobTillaart/pressure
#include "pressure.h"
pressure P;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PRESSURE_LIB_VERSION: ");
Serial.println(PRESSURE_LIB_VERSION);
// convert one pressure to 12 output units.
P.setMilliBar(1019.1);
Serial.print("mBar: \t"); Serial.println(P.getMilliBar(),3);
Serial.print("Bar: \t"); Serial.println(P.getBar(),3);
Serial.print("PSI: \t"); Serial.println(P.getPSI(),3);
Serial.print("ATM: \t"); Serial.println(P.getATM(),3);
Serial.print("DYN: \t"); Serial.println(P.getDynes(),3);
Serial.print("InchHg: \t"); Serial.println(P.getInchHg(),3);
Serial.print("InchH20: \t"); Serial.println(P.getInchH2O(),3);
Serial.print("Pascal: \t"); Serial.println(P.getPascal(),3);
Serial.print("TORR: \t"); Serial.println(P.getTORR(),3);
Serial.print("CmHg: \t"); Serial.println(P.getCmHg(),3);
Serial.print("CMH20: \t"); Serial.println(P.getCmH2O(),3);
Serial.print("MSW: \t"); Serial.println(P.getMSW(),3);
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,38 @@
# Syntax Colouring Map For I2C_ASDX
# Data types (KEYWORD1)
pressure KEYWORD1
# Methods and Functions (KEYWORD2)
setMilliBar KEYWORD2
setBar KEYWORD2
setPSI KEYWORD2
setATM KEYWORD2
setDynes KEYWORD2
setInchHg KEYWORD2
setInchH2O KEYWORD2
setPascal KEYWORD2
setTORR KEYWORD2
setCmHg KEYWORD2
setCmH2O KEYWORD2
setMSW KEYWORD2
getMilliBar KEYWORD2
getBar KEYWORD2
getPSI KEYWORD2
getATM KEYWORD2
getDynes KEYWORD2
getInchHg KEYWORD2
getInchH2O KEYWORD2
getPascal KEYWORD2
getTORR KEYWORD2
getCmHg KEYWORD2
getCmH2O KEYWORD2
getMSW KEYWORD2
# Constants (LITERAL1)

View File

@ -0,0 +1,23 @@
{
"name": "pressure",
"keywords": "HG, H20, ATM, Bar, mBar",
"description": "Arduino library for pressure conversion.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/pressure.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
"headers": "pressure.h"
}

View File

@ -0,0 +1,11 @@
name=pressure
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for pressure conversion
paragraph=
category=Signal Input/Output
url=https://github.com/RobTillaart/pressure.git
architectures=*
includes=pressure.h
depends=

View File

@ -0,0 +1,83 @@
#pragma once
//
// FILE: pressure.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: Arduino library for pressure conversion
// URL: https://github.com/RobTillaart/pressure
//
// CONSTANTS NEED TO BE VERIFIED
// Temperature 25°C ?
// CONSTANTS SETTERS
#define BAR2MILLIBAR 1000
#define ATM2MILLIBAR 1013.25
#define PSI2MILLIBAR 68.9475729318
#define DYNES2MILLIBAR 0.001
#define INHG2MILLIBAR 33.85355
#define INH202MILLIBAR 2.4908890833333
#define PASCAL2MILLIBAR 0.01
#define TORR2MILLIBAR 1.33322368
#define CMHG2MILLIBAR 13.3322368
#define CMH2O2MILLIBAR 0.980665
#define MSW2MILLIBAR 0.01
// CONSTANTS GETTERS
#define MILLIBAR2BAR 0.001
#define MILLIBAR2ATM 9.86923267e-4
#define MILLIBAR2PSI 0.0145037738
#define MILLIBAR2DYNES 1000
#define MILLIBAR2INHG 2.9539e-2
#define MILLIBAR2INH2O 0.40146307866177
#define MILLIBAR2PASCAL 100
#define MILLIBAR2TORR 0.750061683
#define MILLIBAR2CMHG 0.0750061683
#define MILLIBAR2CMH2O 1.0197162129779
#define MILLIBAR2MSW 100
#define PRESSURE_LIB_VERSION (F("0.1.0"))
class pressure
{
public:
// CONSTRUCTOR
pressure(float value = 0) { _pressure = value; };
void setMilliBar(float value) { _pressure = value; };
void setBar(float value) { _pressure = value * MILLIBAR2BAR; };
void setPSI(float value) { _pressure = value * MILLIBAR2PSI; };
void setATM(float value) { _pressure = value * MILLIBAR2ATM; }
void setDynes(float value) { _pressure = value * MILLIBAR2DYNES; }
void setInchHg(float value) { _pressure = value * MILLIBAR2INHG; }
void setInchH2O(float value) { _pressure = value * MILLIBAR2INH2O; }
void setPascal(float value) { _pressure = value * MILLIBAR2PASCAL; }
void setTORR(float value) { _pressure = value * MILLIBAR2TORR; }
void setCmHg(float value) { _pressure = value * MILLIBAR2CMHG; }
void setCmH2O(float value) { _pressure = value * MILLIBAR2CMH2O; }
void setMSW(float value) { _pressure = value * MILLIBAR2MSW; }
float getMilliBar() { return _pressure; };
float getBar() { return _pressure * MILLIBAR2BAR; };
float getPSI() { return _pressure * MILLIBAR2PSI; };
float getATM() { return _pressure * MILLIBAR2ATM; }
float getDynes() { return _pressure * MILLIBAR2DYNES; }
float getInchHg() { return _pressure * MILLIBAR2INHG; }
float getInchH2O() { return _pressure * MILLIBAR2INH2O; }
float getPascal() { return _pressure * MILLIBAR2PASCAL; }
float getTORR() { return _pressure * MILLIBAR2TORR; }
float getCmHg() { return _pressure * MILLIBAR2CMHG; }
float getCmH2O() { return _pressure * MILLIBAR2CMH2O; }
float getMSW() { return _pressure * MILLIBAR2MSW; }
private:
float _pressure;
};
// -- END OF FILE --

View File

@ -0,0 +1,133 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2020-12-03
// PURPOSE: unit tests for the pressure library
// https://github.com/RobTillaart/pressure
// 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 "pressure.h"
unittest_setup()
{
}
unittest_teardown()
{
}
unittest(test_constructor)
{
fprintf(stderr, "PRESSURE_LIB_VERSION: %s\n", (char *) PRESSURE_LIB_VERSION);
pressure P;
assertEqualFloat(0.0, P.getMilliBar(), 1e-4);
assertEqualFloat(0.0, P.getBar(), 1e-4);
assertEqualFloat(0.0, P.getPSI(), 1e-4);
assertEqualFloat(0.0, P.getATM(), 1e-4);
assertEqualFloat(0.0, P.getDynes(), 1e-4);
assertEqualFloat(0.0, P.getInchHg(), 1e-4);
assertEqualFloat(0.0, P.getInchH2O(), 1e-4);
assertEqualFloat(0.0, P.getPascal(), 1e-4);
assertEqualFloat(0.0, P.getTORR(), 1e-4);
assertEqualFloat(0.0, P.getCmHg(), 1e-4);
assertEqualFloat(0.0, P.getCmH2O(), 1e-4);
assertEqualFloat(0.0, P.getMSW(), 1e-4);
}
unittest(test_constants_setter)
{
fprintf(stderr, "PRESSURE_LIB_VERSION: %s\n", (char *) PRESSURE_LIB_VERSION);
fprintf(stderr, "Test conversion constants\n");
assertEqualFloat(1000, BAR2MILLIBAR, 1);
assertEqualFloat(1013.25, ATM2MILLIBAR, 1e-4);
assertEqualFloat(68.9475729318, PSI2MILLIBAR, 1e-4);
assertEqualFloat(0.001, DYNES2MILLIBAR, 1e-7);
assertEqualFloat(33.85355, INHG2MILLIBAR, 1e-4);
assertEqualFloat(2.49088908333, INH202MILLIBAR, 1e-4);
assertEqualFloat(0.01, PASCAL2MILLIBAR, 1e-4);
assertEqualFloat(1.33322368, TORR2MILLIBAR, 1e-5);
assertEqualFloat(13.3322368, CMHG2MILLIBAR, 1e-5);
assertEqualFloat(0.980665, CMH2O2MILLIBAR, 1e-5);
assertEqualFloat(0.01, MSW2MILLIBAR, 1e-3);
}
unittest(test_constants_getter)
{
fprintf(stderr, "PRESSURE_LIB_VERSION: %s\n", (char *) PRESSURE_LIB_VERSION);
fprintf(stderr, "Test conversion constants\n");
assertEqualFloat(0.001, MILLIBAR2BAR, 1e-7);
assertEqualFloat(9.86923267e-4, MILLIBAR2ATM, 1e-7);
assertEqualFloat(0.0145037738, MILLIBAR2PSI, 1e-4);
assertEqualFloat(1000, MILLIBAR2DYNES, 1);
assertEqualFloat(2.9539e-2, MILLIBAR2INHG, 1e-5);
assertEqualFloat(0.40146307866, MILLIBAR2INH2O, 1e-4);
assertEqualFloat(100, MILLIBAR2PASCAL, 1e-3);
assertEqualFloat(0.750061683, MILLIBAR2TORR, 1e-5);
assertEqualFloat(0.0750061683, MILLIBAR2CMHG, 1e-6);
assertEqualFloat(1.0197162129, MILLIBAR2CMH2O, 1e-5);
assertEqualFloat(100, MILLIBAR2MSW, 1);
}
unittest(test_constants_3)
{
fprintf(stderr, "PRESSURE_LIB_VERSION: %s\n", (char *) PRESSURE_LIB_VERSION);
fprintf(stderr, "Test conversion constants\n");
assertEqualFloat(1.0, BAR2MILLIBAR * MILLIBAR2BAR, 1e-5);
assertEqualFloat(1.0, ATM2MILLIBAR * MILLIBAR2ATM, 1e-5);
assertEqualFloat(1.0, PSI2MILLIBAR * MILLIBAR2PSI, 1e-5);
assertEqualFloat(1.0, DYNES2MILLIBAR * MILLIBAR2DYNES, 1e-5);
assertEqualFloat(1.0, INHG2MILLIBAR * MILLIBAR2INHG, 1e-5);
assertEqualFloat(1.0, INH202MILLIBAR * MILLIBAR2INH2O, 1e-5);
assertEqualFloat(1.0, PASCAL2MILLIBAR * MILLIBAR2PASCAL, 1e-5);
assertEqualFloat(1.0, TORR2MILLIBAR * MILLIBAR2TORR, 1e-5);
assertEqualFloat(1.0, CMHG2MILLIBAR * MILLIBAR2CMHG, 1e-5);
assertEqualFloat(1.0, CMH2O2MILLIBAR * MILLIBAR2CMH2O, 1e-5);
assertEqualFloat(1.0, MSW2MILLIBAR * MILLIBAR2MSW, 1e-5);
}
unittest_main()
// --------