Skip to content

Commit 9d485c8

Browse files
committed
more functions + fixes
1 parent 889bad9 commit 9d485c8

File tree

6 files changed

+73
-33
lines changed

6 files changed

+73
-33
lines changed

MeteoFunctions.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,41 @@ float MeteoFunctions::msToKmh(float ms) {
4444
return ms * 18 / 5;
4545
}
4646

47+
/**
48+
* Converts km/h to m/s
49+
*/
50+
float MeteoFunctions::kmhToMs(float kmh) {
51+
return kmh * 5 / 18;
52+
}
53+
4754
/**
4855
* Converts m/s to m/h
4956
*/
5057
float MeteoFunctions::msToMph(float ms) {
5158
return ms / 0.44704;
5259
}
5360

61+
/**
62+
* Converts m/h to m/h m/s
63+
*/
64+
float MeteoFunctions::mphToMs(float mph) {
65+
return mph * 2.236936;
66+
}
67+
5468
/**
5569
* Converts m/s to knots
5670
*/
57-
uint16_t MeteoFunctions::msToKn(float ms) {
71+
float MeteoFunctions::msToKn(float ms) {
5872
return ms * 1.94384449;
5973
}
6074

75+
/**
76+
* Converts knots to m/s
77+
*/
78+
float MeteoFunctions::knToMs(float kn) {
79+
return kn * 0.5144444;
80+
}
81+
6182
/**
6283
* Converts meters to feet
6384
*/
@@ -72,6 +93,20 @@ float MeteoFunctions::ft_m(float feet) {
7293
return feet / 3.2808399;
7394
}
7495

96+
/**
97+
* Converts hPa to inHg
98+
*/
99+
float MeteoFunctions::hPa_inHg(float hPa) {
100+
return 0.02952998751 * hPa;
101+
}
102+
103+
/**
104+
* Converts inHg to hPa
105+
*/
106+
float MeteoFunctions::inHg_hPa(float inHg) {
107+
return inHg / 0.02952998751;
108+
}
109+
75110
/**
76111
* Calculates humidex in Celsius
77112
*/
@@ -99,7 +134,7 @@ float MeteoFunctions::dewPoint_c(float temp_c, float humidity) {
99134
* Calculates dew point in Fahrenheit
100135
*/
101136
float MeteoFunctions::dewPoint_f(float temp_f, float humidity) {
102-
return dewPoint_c(f_c(temp_f), humidity);
137+
return c_f(dewPoint_c(f_c(temp_f), humidity));
103138
}
104139

105140
/**
@@ -148,7 +183,7 @@ float MeteoFunctions::windChill_c(float temp_c, float wind_speed_ms) {
148183
* Calculates wind chill in Fahrenheit
149184
*/
150185
float MeteoFunctions::windChill_f(float temp_f, float wind_speed_ms) {
151-
return windChill_c(f_c(temp_f), wind_speed_ms);
186+
return c_f(windChill_c(f_c(temp_f), wind_speed_ms));
152187
}
153188

154189
/**
@@ -204,7 +239,7 @@ float MeteoFunctions::apparentTemp_c(float temp_c, float humidity, float wind_sp
204239
* Calculates apparent temperature in Celsius
205240
*/
206241
float MeteoFunctions::apparentTemp_f(float temp_f, float humidity, float wind_speed_ms) {
207-
return apparentTemp_c(f_c(temp_f), humidity, wind_speed_ms);
242+
return c_f(apparentTemp_c(f_c(temp_f), humidity, wind_speed_ms));
208243
}
209244

210245
/**

MeteoFunctions.h

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,33 @@ SOFTWARE.
3232
class MeteoFunctions {
3333
public:
3434
MeteoFunctions();
35-
float c_f(float temp_c);
36-
float f_c(float temp_f);
37-
float msToKmh(float ms);
38-
float msToMph(float ms);
39-
uint16_t msToKn(float ms);
40-
float m_ft(float meters);
41-
float ft_m(float feet);
42-
float humidex_c(float temp_c, float humidity);
43-
float humidex_f(float temp_f, float humidity);
44-
float dewPoint_c(float temp_c, float humidity);
45-
float dewPoint_f(float temp_f, float humidity);
46-
uint8_t beaufort(float wind_speed_ms);
47-
float windChill_c(float temp_c, float wind_speed_ms);
48-
float windChill_f(float temp_f, float wind_speed_ms);
49-
float heatIndex_c(float temp_c, float humidity);
50-
float heatIndex_f(float temp_f, float humidity);
51-
float apparentTemp_c(float temp_c, float humidity, float wind_speed_ms);
52-
float apparentTemp_f(float temp_f, float humidity, float wind_speed_ms);
53-
float cloudBase_m(float temp_c, float humidity);
54-
float cloudBase_f(float temp_f, float humidity);
55-
float relativePressure_c(float abs_pressure, float height_m, float temp_c);
56-
float relativePressure_f(float abs_pressure, float height_ft, float temp_f);
35+
float c_f(float temp_c);
36+
float f_c(float temp_f);
37+
float msToKmh(float ms);
38+
float kmhToMs(float kmh);
39+
float msToMph(float ms);
40+
float mphToMs(float mph);
41+
float msToKn(float ms);
42+
float knToMs(float kn);
43+
float m_ft(float meters);
44+
float ft_m(float feet);
45+
float hPa_inHg(float hPa);
46+
float inHg_hPa(float inHg);
47+
float humidex_c(float temp_c, float humidity);
48+
float humidex_f(float temp_f, float humidity);
49+
float dewPoint_c(float temp_c, float humidity);
50+
float dewPoint_f(float temp_f, float humidity);
51+
uint8_t beaufort(float wind_speed_ms);
52+
float windChill_c(float temp_c, float wind_speed_ms);
53+
float windChill_f(float temp_f, float wind_speed_ms);
54+
float heatIndex_c(float temp_c, float humidity);
55+
float heatIndex_f(float temp_f, float humidity);
56+
float apparentTemp_c(float temp_c, float humidity, float wind_speed_ms);
57+
float apparentTemp_f(float temp_f, float humidity, float wind_speed_ms);
58+
float cloudBase_m(float temp_c, float humidity);
59+
float cloudBase_f(float temp_f, float humidity);
60+
float relativePressure_c(float abs_pressure, float height_m, float temp_c);
61+
float relativePressure_f(float abs_pressure, float height_ft, float temp_f);
5762
};
5863

5964
#endif // METEOFUNCTIONS_H

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MeteoFunctions calc;
2424
float wind_speed = 2.0; // m/s
2525
float temp = 21.0; // °C
2626
float humidity = 60.0; // %
27-
float pressure = 975.8; // Pa
27+
float pressure = 975.8; // hPa
2828
float above_sea = 408.0; // m
2929

3030
void setup() {

examples/MeteoFunctions/MeteoFunctions.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ MeteoFunctions calc;
99
float wind_speed = 2; // m/s
1010
float temp = 21.0; // °C
1111
float humidity = 60.0; // %
12-
float pressure = 975.8; // Pa
12+
float pressure = 975.8; // hPa
1313
float above_sea = 408.0; // m
1414
#elif defined(FAHRENHEIT)
1515
float wind_speed = 2; // m/s
1616
float temp = 69.8; // °F
1717
float humidity = 60.0; // %
18-
float pressure = 975.8; // Pa
18+
float pressure = 975.8; // hPa
1919
float above_sea = 1338.5; // ft
2020
#endif
2121

@@ -98,8 +98,8 @@ void loop() {
9898
Serial.print(calc.cloudBase_f(temp, humidity));
9999

100100
Serial.print(" feet\n: ");
101-
Serial.print(calc.relativePressure_f(pressure, above_sea, temp));
102-
Serial.println(" Pa");
101+
Serial.print(calc.hPa_inHg(calc.relativePressure_f(pressure, above_sea, temp)));
102+
Serial.println(" inHg");
103103
#endif
104104
delay(5000);
105105
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"email": "[email protected]",
1414
"url": "https://github.com/pilotak"
1515
},
16-
"version": "1.0.1",
16+
"version": "1.0.2",
1717
"frameworks": "arduino, mbed",
1818
"platforms": "*"
1919
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ paragraph=extend your meteo station by calculating other meteorologist values
77
url=https://github.com/pilotak/MeteoFunctions
88
includes=MeteoFunctions.h
99
category=Data Processing
10-
version=1.0.1
10+
version=1.0.2
1111
architectures=*

0 commit comments

Comments
 (0)