From c89646a7d3fe55d57136bc81893da683ceecc8ad Mon Sep 17 00:00:00 2001 From: TangoCash Date: Sat, 23 Mar 2019 13:33:35 +0100 Subject: [PATCH] weather: add more data to struct Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/a78f974ca037b60c58427c8e0bad0d9830a743b8 Author: TangoCash Date: 2019-03-23 (Sat, 23 Mar 2019) Origin message was: ------------------ - weather: add more data to struct --- src/gui/weather.cpp | 14 ++++++++++---- src/gui/weather.h | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/gui/weather.cpp b/src/gui/weather.cpp index 3169b8585..47bb069aa 100644 --- a/src/gui/weather.cpp +++ b/src/gui/weather.cpp @@ -43,9 +43,10 @@ #define UPDATE_CYCLE 15 // minutes +CWeather *weather = NULL; + CWeather *CWeather::getInstance() { - static CWeather *weather = NULL; if (!weather) weather = new CWeather(); return weather; @@ -74,7 +75,7 @@ void CWeather::setCoords(std::string new_coords, std::string new_city) { coords = new_coords; city = new_city; - GetWeatherDetails(); + checkUpdate(true); } } @@ -127,8 +128,10 @@ bool CWeather::GetWeatherDetails() timezone = DataValues["timezone"].asString(); current.timestamp = DataValues["currently"].get("time", 0).asDouble(); current.temperature = DataValues["currently"].get("temperature", "").asFloat(); - current.windSpeed = DataValues["currently"].get("windSpeed", 0).asFloat(); - current.windBearing = DataValues["currently"].get("windBearing", 0).asDouble(); + current.pressure = DataValues["currently"].get("pressure", "").asFloat(); + current.humidity = DataValues["currently"].get("humidity", "").asFloat(); + current.windSpeed = DataValues["currently"].get("windSpeed", "").asFloat(); + current.windBearing = DataValues["currently"].get("windBearing", "").asDouble(); current.icon = DataValues["currently"].get("icon", "").asString(); if (current.icon.empty()) current.icon = "unknown.png"; @@ -141,6 +144,7 @@ bool CWeather::GetWeatherDetails() for (unsigned int i = 0; i < elements.size(); i++) { daily_data.timestamp = elements[i].get("time", 0).asDouble(); + daily_data.weekday = (int)(localtime(&daily_data.timestamp)->tm_wday); daily_data.icon = elements[i].get("icon", "").asString(); if (daily_data.icon.empty()) daily_data.icon = "unknown.png"; @@ -148,6 +152,8 @@ bool CWeather::GetWeatherDetails() daily_data.icon = daily_data.icon + ".png"; daily_data.temperatureMin = elements[i].get("temperatureMin", "").asFloat(); daily_data.temperatureMax = elements[i].get("temperatureMax", "").asFloat(); + daily_data.sunriseTime = elements[i].get("sunriseTime", 0).asDouble(); + daily_data.sunsetTime = elements[i].get("sunsetTime", 0).asDouble(); daily_data.windSpeed = elements[i].get("windSpeed", 0).asFloat(); daily_data.windBearing = elements[i].get("windBearing", 0).asDouble(); diff --git a/src/gui/weather.h b/src/gui/weather.h index 717a5f440..f1162ac8f 100644 --- a/src/gui/weather.h +++ b/src/gui/weather.h @@ -40,13 +40,17 @@ struct current_data time_t timestamp; std::string icon; float temperature; + float humidity; + float pressure; float windSpeed; int windBearing; current_data(): timestamp(0), - icon(""), + icon("unknown.png"), temperature(0), + humidity(0), + pressure(0), windSpeed(0), windBearing(0) {} @@ -55,9 +59,12 @@ struct current_data typedef struct { time_t timestamp; + int weekday; // 0=Sunday, 1=Monday, ... std::string icon; float temperatureMin; float temperatureMax; + time_t sunriseTime; + time_t sunsetTime; float windSpeed; int windBearing; } forecast_data; @@ -82,10 +89,13 @@ class CWeather bool checkUpdate(bool forceUpdate = false); void setCoords(std::string new_coords, std::string new_city = "Unknown"); + // globals std::string getCity() { return city; }; + + // current conditions #if 0 std::string getCurrentTimestamp() { @@ -100,6 +110,14 @@ class CWeather { return to_string((int)(current.temperature + 0.5)); }; + std::string getCurrentHumidity() + { + return to_string((int)(current.humidity * 100.0)); + }; + std::string getCurrentPressure() + { + return to_string(current.pressure); + }; std::string getCurrentWindSpeed() { return to_string(current.windSpeed); @@ -112,24 +130,46 @@ class CWeather { return ICONSDIR"/weather/" + current.icon; }; + + // forecast conditions + int getForecastSize() + { + return (int)v_forecast.size(); + }; + int getForecastWeekday(int i = 0) + { + if (i > (int)v_forecast.size()) + i = (int)v_forecast.size(); + return v_forecast[i].weekday; + }; std::string getForecastTemperatureMin(int i = 0) { + if (i > (int)v_forecast.size()) + i = (int)v_forecast.size(); return to_string((int)(v_forecast[i].temperatureMin + 0.5)); }; std::string getForecastTemperatureMax(int i = 0) { + if (i > (int)v_forecast.size()) + i = (int)v_forecast.size(); return to_string((int)(v_forecast[i].temperatureMax + 0.5)); }; std::string getForecastWindSpeed(int i = 0) { + if (i > (int)v_forecast.size()) + i = (int)v_forecast.size(); return to_string(v_forecast[i].windSpeed); }; std::string getForecastWindBearing(int i = 0) { + if (i > (int)v_forecast.size()) + i = (int)v_forecast.size(); return to_string(v_forecast[i].windBearing); }; std::string getForecastIcon(int i = 0) { + if (i > (int)v_forecast.size()) + i = (int)v_forecast.size(); return ICONSDIR"/weather/" + v_forecast[i].icon; };