weather: add getDirectionString() function

Origin commit data
------------------
Branch: ni/coolstream
Commit: 4a53e91c48
Author: vanhofen <vanhofen@gmx.de>
Date: 2022-01-23 (Sun, 23 Jan 2022)

Origin message was:
------------------
- weather: add getDirectionString() function

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2022-01-23 23:59:08 +01:00
parent 7475ee0803
commit de20a1df65
6 changed files with 103 additions and 0 deletions

View File

@@ -3037,6 +3037,22 @@ videomenu.zappingmode Umschaltverhalten
videomenu.zappingmode_mute Schwarzes Bild videomenu.zappingmode_mute Schwarzes Bild
videomenu.zappingmode_hold Standbild videomenu.zappingmode_hold Standbild
weather.api_key Wetter API Schlüssel (OpenWeather) weather.api_key Wetter API Schlüssel (OpenWeather)
weather.direction_e O
weather.direction_ene ONO
weather.direction_ese OSO
weather.direction_n N
weather.direction_ne NO
weather.direction_nne NNO
weather.direction_nnw NNW
weather.direction_nw NW
weather.direction_s S
weather.direction_se SO
weather.direction_sse SSO
weather.direction_ssw SSW
weather.direction_sw SW
weather.direction_w W
weather.direction_wnw WNW
weather.direction_wsw WSW
weather.enabled Wetter-Unterstützung weather.enabled Wetter-Unterstützung
weather.location Wetter-Standort weather.location Wetter-Standort
weather.postalcode Wetter-Standort per Postleitzahl weather.postalcode Wetter-Standort per Postleitzahl

View File

@@ -3037,6 +3037,22 @@ videomenu.zappingmode Zapping mode
videomenu.zappingmode_mute Black screen videomenu.zappingmode_mute Black screen
videomenu.zappingmode_hold Hold screen videomenu.zappingmode_hold Hold screen
weather.api_key Weather API key (OpenWeather) weather.api_key Weather API key (OpenWeather)
weather.direction_e E
weather.direction_ene ENE
weather.direction_ese ESE
weather.direction_n N
weather.direction_ne NE
weather.direction_nne NNE
weather.direction_nnw NNW
weather.direction_nw NW
weather.direction_s S
weather.direction_se SE
weather.direction_sse SSE
weather.direction_ssw SSW
weather.direction_sw SW
weather.direction_w W
weather.direction_wnw WNW
weather.direction_wsw WSW
weather.enabled Weather support weather.enabled Weather support
weather.location Weather location weather.location Weather location
weather.postalcode Weather location by postal code weather.postalcode Weather location by postal code

View File

@@ -182,6 +182,34 @@ bool CWeather::GetWeatherDetails()
return false; return false;
} }
std::string CWeather::getDirectionString(int degree)
{
std::string direction("n/a");
float step = 11.25;
float deg = degree;
if (deg <= step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_N); }
else if (deg <= 3 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_NNE); }
else if (deg <= 5 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_NE); }
else if (deg <= 7 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_ENE); }
else if (deg <= 9 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_E); }
else if (deg <= 11 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_ESE); }
else if (deg <= 13 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_SE); }
else if (deg <= 15 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_SSE); }
else if (deg <= 17 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_S); }
else if (deg <= 19 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_SSW); }
else if (deg <= 21 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_SW); }
else if (deg <= 23 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_WSW); }
else if (deg <= 25 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_W); }
else if (deg <= 27 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_WNW); }
else if (deg <= 29 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_NW); }
else if (deg <= 31 * step) { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_NNW); }
else { direction = g_Locale->getText(LOCALE_WEATHER_DIRECTION_N); }
return direction;
}
bool CWeather::FindCoords(std::string postalcode, std::string country) bool CWeather::FindCoords(std::string postalcode, std::string country)
{ {
std::string data = "http://api.openweathermap.org/geo/1.0/zip?zip=" + postalcode + "," + country + "&appid=" + key; std::string data = "http://api.openweathermap.org/geo/1.0/zip?zip=" + postalcode + "," + country + "&appid=" + key;

View File

@@ -84,6 +84,7 @@ class CWeather
std::string key; std::string key;
bool GetWeatherDetails(); bool GetWeatherDetails();
time_t last_time; time_t last_time;
std::string getDirectionString(int degree);
public: public:
static CWeather *getInstance(); static CWeather *getInstance();
@@ -130,6 +131,10 @@ class CWeather
{ {
return to_string(current.windBearing); return to_string(current.windBearing);
}; };
std::string getCurrentWindDirection()
{
return getDirectionString(current.windBearing);
};
std::string getCurrentIcon() std::string getCurrentIcon()
{ {
return ICONSDIR"/weather/" + current.icon; return ICONSDIR"/weather/" + current.icon;
@@ -174,6 +179,12 @@ class CWeather
i = (int)v_forecast.size(); i = (int)v_forecast.size();
return to_string(v_forecast[i].windBearing); return to_string(v_forecast[i].windBearing);
}; };
std::string getForecastWindDirection(int i = 0)
{
if (i > (int)v_forecast.size())
i = (int)v_forecast.size();
return getDirectionString(v_forecast[i].windBearing);
};
std::string getForecastIcon(int i = 0) std::string getForecastIcon(int i = 0)
{ {
if (i > (int)v_forecast.size()) if (i > (int)v_forecast.size())

View File

@@ -3064,6 +3064,22 @@ typedef enum
LOCALE_VIDEOMENU_ZAPPINGMODE_MUTE, LOCALE_VIDEOMENU_ZAPPINGMODE_MUTE,
LOCALE_VIDEOMENU_ZAPPINGMODE_HOLD, LOCALE_VIDEOMENU_ZAPPINGMODE_HOLD,
LOCALE_WEATHER_API_KEY, LOCALE_WEATHER_API_KEY,
LOCALE_WEATHER_DIRECTION_E,
LOCALE_WEATHER_DIRECTION_ENE,
LOCALE_WEATHER_DIRECTION_ESE,
LOCALE_WEATHER_DIRECTION_N,
LOCALE_WEATHER_DIRECTION_NE,
LOCALE_WEATHER_DIRECTION_NNE,
LOCALE_WEATHER_DIRECTION_NNW,
LOCALE_WEATHER_DIRECTION_NW,
LOCALE_WEATHER_DIRECTION_S,
LOCALE_WEATHER_DIRECTION_SE,
LOCALE_WEATHER_DIRECTION_SSE,
LOCALE_WEATHER_DIRECTION_SSW,
LOCALE_WEATHER_DIRECTION_SW,
LOCALE_WEATHER_DIRECTION_W,
LOCALE_WEATHER_DIRECTION_WNW,
LOCALE_WEATHER_DIRECTION_WSW,
LOCALE_WEATHER_ENABLED, LOCALE_WEATHER_ENABLED,
LOCALE_WEATHER_LOCATION, LOCALE_WEATHER_LOCATION,
LOCALE_WEATHER_POSTALCODE, LOCALE_WEATHER_POSTALCODE,

View File

@@ -3064,6 +3064,22 @@ const char * locale_real_names[] =
"videomenu.zappingmode_mute", "videomenu.zappingmode_mute",
"videomenu.zappingmode_hold", "videomenu.zappingmode_hold",
"weather.api_key", "weather.api_key",
"weather.direction_e",
"weather.direction_ene",
"weather.direction_ese",
"weather.direction_n",
"weather.direction_ne",
"weather.direction_nne",
"weather.direction_nnw",
"weather.direction_nw",
"weather.direction_s",
"weather.direction_se",
"weather.direction_sse",
"weather.direction_ssw",
"weather.direction_sw",
"weather.direction_w",
"weather.direction_wnw",
"weather.direction_wsw",
"weather.enabled", "weather.enabled",
"weather.location", "weather.location",
"weather.postalcode", "weather.postalcode",