Skip to content

Commit

Permalink
more functions + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotak committed Jan 2, 2019
1 parent 889bad9 commit 9d485c8
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 33 deletions.
43 changes: 39 additions & 4 deletions MeteoFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,41 @@ float MeteoFunctions::msToKmh(float ms) {
return ms * 18 / 5;
}

/**
* Converts km/h to m/s
*/
float MeteoFunctions::kmhToMs(float kmh) {
return kmh * 5 / 18;
}

/**
* Converts m/s to m/h
*/
float MeteoFunctions::msToMph(float ms) {
return ms / 0.44704;
}

/**
* Converts m/h to m/h m/s
*/
float MeteoFunctions::mphToMs(float mph) {
return mph * 2.236936;
}

/**
* Converts m/s to knots
*/
uint16_t MeteoFunctions::msToKn(float ms) {
float MeteoFunctions::msToKn(float ms) {
return ms * 1.94384449;
}

/**
* Converts knots to m/s
*/
float MeteoFunctions::knToMs(float kn) {
return kn * 0.5144444;
}

/**
* Converts meters to feet
*/
Expand All @@ -72,6 +93,20 @@ float MeteoFunctions::ft_m(float feet) {
return feet / 3.2808399;
}

/**
* Converts hPa to inHg
*/
float MeteoFunctions::hPa_inHg(float hPa) {
return 0.02952998751 * hPa;
}

/**
* Converts inHg to hPa
*/
float MeteoFunctions::inHg_hPa(float inHg) {
return inHg / 0.02952998751;
}

/**
* Calculates humidex in Celsius
*/
Expand Down Expand Up @@ -99,7 +134,7 @@ float MeteoFunctions::dewPoint_c(float temp_c, float humidity) {
* Calculates dew point in Fahrenheit
*/
float MeteoFunctions::dewPoint_f(float temp_f, float humidity) {
return dewPoint_c(f_c(temp_f), humidity);
return c_f(dewPoint_c(f_c(temp_f), humidity));
}

/**
Expand Down Expand Up @@ -148,7 +183,7 @@ float MeteoFunctions::windChill_c(float temp_c, float wind_speed_ms) {
* Calculates wind chill in Fahrenheit
*/
float MeteoFunctions::windChill_f(float temp_f, float wind_speed_ms) {
return windChill_c(f_c(temp_f), wind_speed_ms);
return c_f(windChill_c(f_c(temp_f), wind_speed_ms));
}

/**
Expand Down Expand Up @@ -204,7 +239,7 @@ float MeteoFunctions::apparentTemp_c(float temp_c, float humidity, float wind_sp
* Calculates apparent temperature in Celsius
*/
float MeteoFunctions::apparentTemp_f(float temp_f, float humidity, float wind_speed_ms) {
return apparentTemp_c(f_c(temp_f), humidity, wind_speed_ms);
return c_f(apparentTemp_c(f_c(temp_f), humidity, wind_speed_ms));
}

/**
Expand Down
49 changes: 27 additions & 22 deletions MeteoFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,33 @@ SOFTWARE.
class MeteoFunctions {
public:
MeteoFunctions();
float c_f(float temp_c);
float f_c(float temp_f);
float msToKmh(float ms);
float msToMph(float ms);
uint16_t msToKn(float ms);
float m_ft(float meters);
float ft_m(float feet);
float humidex_c(float temp_c, float humidity);
float humidex_f(float temp_f, float humidity);
float dewPoint_c(float temp_c, float humidity);
float dewPoint_f(float temp_f, float humidity);
uint8_t beaufort(float wind_speed_ms);
float windChill_c(float temp_c, float wind_speed_ms);
float windChill_f(float temp_f, float wind_speed_ms);
float heatIndex_c(float temp_c, float humidity);
float heatIndex_f(float temp_f, float humidity);
float apparentTemp_c(float temp_c, float humidity, float wind_speed_ms);
float apparentTemp_f(float temp_f, float humidity, float wind_speed_ms);
float cloudBase_m(float temp_c, float humidity);
float cloudBase_f(float temp_f, float humidity);
float relativePressure_c(float abs_pressure, float height_m, float temp_c);
float relativePressure_f(float abs_pressure, float height_ft, float temp_f);
float c_f(float temp_c);
float f_c(float temp_f);
float msToKmh(float ms);
float kmhToMs(float kmh);
float msToMph(float ms);
float mphToMs(float mph);
float msToKn(float ms);
float knToMs(float kn);
float m_ft(float meters);
float ft_m(float feet);
float hPa_inHg(float hPa);
float inHg_hPa(float inHg);
float humidex_c(float temp_c, float humidity);
float humidex_f(float temp_f, float humidity);
float dewPoint_c(float temp_c, float humidity);
float dewPoint_f(float temp_f, float humidity);
uint8_t beaufort(float wind_speed_ms);
float windChill_c(float temp_c, float wind_speed_ms);
float windChill_f(float temp_f, float wind_speed_ms);
float heatIndex_c(float temp_c, float humidity);
float heatIndex_f(float temp_f, float humidity);
float apparentTemp_c(float temp_c, float humidity, float wind_speed_ms);
float apparentTemp_f(float temp_f, float humidity, float wind_speed_ms);
float cloudBase_m(float temp_c, float humidity);
float cloudBase_f(float temp_f, float humidity);
float relativePressure_c(float abs_pressure, float height_m, float temp_c);
float relativePressure_f(float abs_pressure, float height_ft, float temp_f);
};

#endif // METEOFUNCTIONS_H
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MeteoFunctions calc;
float wind_speed = 2.0; // m/s
float temp = 21.0; // °C
float humidity = 60.0; // %
float pressure = 975.8; // Pa
float pressure = 975.8; // hPa
float above_sea = 408.0; // m

void setup() {
Expand Down
8 changes: 4 additions & 4 deletions examples/MeteoFunctions/MeteoFunctions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ MeteoFunctions calc;
float wind_speed = 2; // m/s
float temp = 21.0; // °C
float humidity = 60.0; // %
float pressure = 975.8; // Pa
float pressure = 975.8; // hPa
float above_sea = 408.0; // m
#elif defined(FAHRENHEIT)
float wind_speed = 2; // m/s
float temp = 69.8; // °F
float humidity = 60.0; // %
float pressure = 975.8; // Pa
float pressure = 975.8; // hPa
float above_sea = 1338.5; // ft
#endif

Expand Down Expand Up @@ -98,8 +98,8 @@ void loop() {
Serial.print(calc.cloudBase_f(temp, humidity));

Serial.print(" feet\n: ");
Serial.print(calc.relativePressure_f(pressure, above_sea, temp));
Serial.println(" Pa");
Serial.print(calc.hPa_inHg(calc.relativePressure_f(pressure, above_sea, temp)));
Serial.println(" inHg");
#endif
delay(5000);
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"email": "info@pavelslama.cz",
"url": "https://github.com/pilotak"
},
"version": "1.0.1",
"version": "1.0.2",
"frameworks": "arduino, mbed",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ paragraph=extend your meteo station by calculating other meteorologist values
url=https://github.com/pilotak/MeteoFunctions
includes=MeteoFunctions.h
category=Data Processing
version=1.0.1
version=1.0.2
architectures=*

0 comments on commit 9d485c8

Please sign in to comment.