0.2.0 pressure

This commit is contained in:
rob tillaart 2021-11-26 11:22:33 +01:00
parent 163e74e3f8
commit 3a7b89c679
7 changed files with 184 additions and 19 deletions

View File

@ -64,6 +64,30 @@ Note: constants need to be verified.
- **float getMSW()** returns pressure in Meters of Sea Water. (under water pressure unit).
#### constants
The library has a number of constants to convert units.
These constants can be used to write specific convertors or define specific constants.
A dedicated conversion is faster as it has only one float multiplication runtime.
```cpp
inline float PSI2MSW(float value)
{
return value * (PSI2MILLIBAR * MILLIBAR2MSW);
}
```
or
```cpp
#define PSI2MSW (PSI2MILLIBAR * MILLIBAR2MSW)
...
float out = in * (PSI2MSW);
```
## Operation
```cpp
@ -78,6 +102,10 @@ Serial.print("TORR: ");
Serial.println(P.getTORR()); // 1000 Dynes in Torr
```
#### Obsolete
Version 0.1.0 has incorrect setters. fixed in version 0.2.0.
## Future
@ -85,3 +113,4 @@ Serial.println(P.getTORR()); // 1000 Dynes in Torr
- find a good reference for conversion formula constants.

View File

@ -0,0 +1,76 @@
//
// FILE: pressure_specific.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2021-11-26
// URL: https://github.com/RobTillaart/pressure
#include "pressure.h"
pressure P;
uint32_t start, stop;
float x;
volatile float value = 1.234;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PRESSURE_LIB_VERSION: ");
Serial.println(PRESSURE_LIB_VERSION);
start = micros();
for (int i = 0; i < 1000; i++)
{
P.setPSI(value);
x = P.getMSW();
}
stop = micros();
Serial.print("TIME:\t");
Serial.println(stop - start);
Serial.print("MSW:\t");
Serial.println(x);
delay(10);
start = micros();
for (int i = 0; i < 1000; i++)
{
x = PSI2MSW(value);
}
stop = micros();
Serial.print("TIME:\t");
Serial.println(stop - start);
Serial.print("MSW:\t");
Serial.println(x);
delay(10);
start = micros();
for (int i = 0; i < 1000; i++)
{
x = value * (PSI2MILLIBAR * MILLIBAR2MSW);
}
stop = micros();
Serial.print("TIME:\t");
Serial.println(stop - start);
Serial.print("MSW:\t");
Serial.println(x);
delay(10);
}
void loop()
{
}
inline float PSI2MSW(float value)
{
return value * (PSI2MILLIBAR * MILLIBAR2MSW);
}
// -- END OF FILE --

View File

@ -35,4 +35,27 @@ getMSW KEYWORD2
# Constants (LITERAL1)
BAR2MILLIBAR LITERAL1
ATM2MILLIBAR LITERAL1
PSI2MILLIBAR LITERAL1
DYNES2MILLIBAR LITERAL1
INHG2MILLIBAR LITERAL1
INH202MILLIBAR LITERAL1
PASCAL2MILLIBAR LITERAL1
TORR2MILLIBAR LITERAL1
CMHG2MILLIBAR LITERAL1
CMH2O2MILLIBAR LITERAL1
MSW2MILLIBAR LITERAL1
MILLIBAR2BAR LITERAL1
MILLIBAR2ATM LITERAL1
MILLIBAR2PSI LITERAL1
MILLIBAR2DYNES LITERAL1
MILLIBAR2INHG LITERAL1
MILLIBAR2INH2O LITERAL1
MILLIBAR2PASCAL LITERAL1
MILLIBAR2TORR LITERAL1
MILLIBAR2CMHG LITERAL1
MILLIBAR2CMH2O LITERAL1
MILLIBAR2MSW LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/pressure.git"
},
"version": "0.1.0",
"version": "0.2.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=pressure
version=0.1.0
version=0.2.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for pressure conversion

View File

@ -2,12 +2,15 @@
//
// FILE: pressure.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.2.0
// PURPOSE: Arduino library for pressure conversion
// URL: https://github.com/RobTillaart/pressure
//
#define PRESSURE_LIB_VERSION (F("0.2.0"))
// CONSTANTS NEED TO BE VERIFIED
// Temperature 25°C ?
@ -17,7 +20,7 @@
#define PSI2MILLIBAR 68.9475729318
#define DYNES2MILLIBAR 0.001
#define INHG2MILLIBAR 33.85355
#define INH202MILLIBAR 2.4908890833333
#define INH2O2MILLIBAR 2.4908890833333
#define PASCAL2MILLIBAR 0.01
#define TORR2MILLIBAR 1.33322368
#define CMHG2MILLIBAR 13.3322368
@ -38,7 +41,6 @@
#define MILLIBAR2MSW 100
#define PRESSURE_LIB_VERSION (F("0.1.0"))
class pressure
@ -49,17 +51,17 @@ public:
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; }
void setBar(float value) { _pressure = value * BAR2MILLIBAR; };
void setPSI(float value) { _pressure = value * PSI2MILLIBAR; };
void setATM(float value) { _pressure = value * ATM2MILLIBAR; }
void setDynes(float value) { _pressure = value * DYNES2MILLIBAR; }
void setInchHg(float value) { _pressure = value * INHG2MILLIBAR; }
void setInchH2O(float value) { _pressure = value * INH2O2MILLIBAR; }
void setPascal(float value) { _pressure = value * PASCAL2MILLIBAR; }
void setTORR(float value) { _pressure = value * TORR2MILLIBAR; }
void setCmHg(float value) { _pressure = value * CMHG2MILLIBAR; }
void setCmH2O(float value) { _pressure = value * CMH2O2MILLIBAR; }
void setMSW(float value) { _pressure = value * MSW2MILLIBAR; }
float getMilliBar() { return _pressure; };

View File

@ -78,7 +78,7 @@ unittest(test_constants_setter)
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(2.49088908333, INH2O2MILLIBAR, 1e-4);
assertEqualFloat(0.01, PASCAL2MILLIBAR, 1e-4);
assertEqualFloat(1.33322368, TORR2MILLIBAR, 1e-5);
assertEqualFloat(13.3322368, CMHG2MILLIBAR, 1e-5);
@ -107,7 +107,6 @@ unittest(test_constants_getter)
}
unittest(test_constants_3)
{
fprintf(stderr, "PRESSURE_LIB_VERSION: %s\n", (char *) PRESSURE_LIB_VERSION);
@ -119,7 +118,7 @@ unittest(test_constants_3)
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, INH2O2MILLIBAR * MILLIBAR2INH2O, 1e-5);
assertEqualFloat(1.0, PASCAL2MILLIBAR * MILLIBAR2PASCAL, 1e-5);
assertEqualFloat(1.0, TORR2MILLIBAR * MILLIBAR2TORR, 1e-5);
assertEqualFloat(1.0, CMHG2MILLIBAR * MILLIBAR2CMHG, 1e-5);
@ -128,6 +127,42 @@ unittest(test_constants_3)
}
unittest(test_get_set)
{
fprintf(stderr, "PRESSURE_LIB_VERSION: %s\n", (char *) PRESSURE_LIB_VERSION);
pressure P;
P.setMilliBar(2);
assertEqualFloat(2.0, P.getMilliBar(), 1e-4);
P.setBar(2);
assertEqualFloat(2.0, P.getBar(), 1e-4);
P.setPSI(2);
assertEqualFloat(2.0, P.getPSI(), 1e-4);
P.setATM(2);
assertEqualFloat(2.0, P.getATM(), 1e-4);
P.setDynes(2);
assertEqualFloat(2.0, P.getDynes(), 1e-4);
P.setInchHg(2);
assertEqualFloat(2.0, P.getInchHg(), 1e-4);
P.setInchH2O(2);
assertEqualFloat(2.0, P.getInchH2O(), 1e-4);
P.setPascal(2);
assertEqualFloat(2.0, P.getPascal(), 1e-4);
P.setTORR(2);
assertEqualFloat(2.0, P.getTORR(), 1e-4);
P.setCmHg(2);
assertEqualFloat(2.0, P.getCmHg(), 1e-4);
P.setCmH2O(2);
assertEqualFloat(2.0, P.getCmH2O(), 1e-4);
P.setMSW(2);
assertEqualFloat(2.0, P.getMSW(), 1e-4);
}
unittest_main()
// --------