diff --git a/src/driver/lcd4l.cpp b/src/driver/lcd4l.cpp index c97a70522..4d1660c60 100644 --- a/src/driver/lcd4l.cpp +++ b/src/driver/lcd4l.cpp @@ -1029,16 +1029,16 @@ void CLCD4l::ParseInfo(uint64_t parseID, bool newID, bool firstRun) int forecast = 1; // days for forecast - std::string wtemp = CWeather::getInstance()->getActTemp(); + std::string wtemp = CWeather::getInstance()->getCurrentTemperature(); for (int i = 0; i < 1 + forecast; i++) - wtemp += "\n" + CWeather::getInstance()->getForecastTemp(i); + wtemp += "\n" + CWeather::getInstance()->getForecastTemperatureMax(i); if (m_wtemp.compare(wtemp)) { WriteFile(WEATHER_TEMP, wtemp); m_wtemp = wtemp; } - std::string wicon = CWeather::getInstance()->getActIcon(); + std::string wicon = CWeather::getInstance()->getCurrentIcon(); for (int i = 0; i < 1 + forecast; i++) wicon += "\n" + CWeather::getInstance()->getForecastIcon(i); if (m_wicon.compare(wicon)) diff --git a/src/gui/weather.cpp b/src/gui/weather.cpp index 94ddd146e..a107521e3 100644 --- a/src/gui/weather.cpp +++ b/src/gui/weather.cpp @@ -53,14 +53,13 @@ CWeather *CWeather::getInstance() CWeather::CWeather() { - act_temp = 0; - act_wicon = "unknown.png"; key = g_settings.weather_api_key; - form = NULL; v_forecast.clear(); last_time = 0; coords = ""; city = ""; + + form = NULL; } CWeather::~CWeather() @@ -126,32 +125,32 @@ bool CWeather::GetWeatherDetails() if (found > 0) { timezone = DataValues["timezone"].asString(); - act_temp = DataValues["currently"].get("temperature", "").asFloat(); - act_wicon = DataValues["currently"].get("icon", "").asString(); - if (act_wicon.empty()) - act_wicon = "unknown.png"; + current.temperature = DataValues["currently"].get("temperature", "").asFloat(); + current.icon = DataValues["currently"].get("icon", "").asString(); + if (current.icon.empty()) + current.icon = "unknown.png"; else - act_wicon = act_wicon + ".png"; - printf("[CWeather]: temp in %s (%s): %.1f - %s\n", city.c_str(), timezone.c_str(), act_temp, act_wicon.c_str()); + current.icon = current.icon + ".png"; + printf("[CWeather]: temp in %s (%s): %.1f - %s\n", city.c_str(), timezone.c_str(), current.temperature, current.icon.c_str()); - forecast_data weatherinfo; + forecast_data daily_data; Json::Value elements = DataValues["daily"]["data"]; for (unsigned int i = 0; i < elements.size(); i++) { - weatherinfo.timestamp = elements[i].get("time", 0).asDouble(); - weatherinfo.wicon = elements[i].get("icon", "").asString(); - if (weatherinfo.wicon.empty()) - weatherinfo.wicon = "unknown.png"; + daily_data.timestamp = elements[i].get("time", 0).asDouble(); + daily_data.icon = elements[i].get("icon", "").asString(); + if (daily_data.icon.empty()) + daily_data.icon = "unknown.png"; else - weatherinfo.wicon = weatherinfo.wicon + ".png"; - weatherinfo.min_temp = elements[i].get("temperatureMin", "").asFloat(); - weatherinfo.max_temp = elements[i].get("temperatureMax", "").asFloat(); + daily_data.icon = daily_data.icon + ".png"; + daily_data.temperatureMin = elements[i].get("temperatureMin", "").asFloat(); + daily_data.temperatureMax = elements[i].get("temperatureMax", "").asFloat(); struct tm *timeinfo; - timeinfo = localtime(&weatherinfo.timestamp); + timeinfo = localtime(&daily_data.timestamp); - printf("[CWeather]: temp %d.%d.%d: min %.1f - max %.1f -> %s\n", timeinfo->tm_mday, timeinfo->tm_mon, timeinfo->tm_year + 1900, weatherinfo.min_temp, weatherinfo.max_temp, weatherinfo.wicon.c_str()); - v_forecast.push_back(weatherinfo); + printf("[CWeather]: temp %d.%d.%d: min %.1f - max %.1f -> %s\n", timeinfo->tm_mday, timeinfo->tm_mon, timeinfo->tm_year + 1900, daily_data.temperatureMin, daily_data.temperatureMax, daily_data.icon.c_str()); + v_forecast.push_back(daily_data); } return true; } @@ -168,11 +167,11 @@ void CWeather::show(int x, int y) if (!g_settings.weather_enabled || coords.empty()) return; - CComponentsPicture *ptmp = new CComponentsPicture(RADIUS_MID, RADIUS_MID, getActIcon()); + CComponentsPicture *ptmp = new CComponentsPicture(RADIUS_MID, RADIUS_MID, getCurrentIcon()); ptmp->setColorBody(form->getColorBody()); form->addCCItem(ptmp); - CComponentsText *temp = new CComponentsText(ptmp->getWidth() + 2*RADIUS_MID, ptmp->getHeight()/2 + RADIUS_MID - g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_NUMBER]->getHeight()/2, 0, 0, getActTemp() + "°C", CTextBox::AUTO_WIDTH, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_NUMBER]); + CComponentsText *temp = new CComponentsText(ptmp->getWidth() + 2*RADIUS_MID, ptmp->getHeight()/2 + RADIUS_MID - g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_NUMBER]->getHeight()/2, 0, 0, getCurrentTemperature() + "°C", CTextBox::AUTO_WIDTH, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_NUMBER]); temp->doPaintBg(false); temp->setTextColor(COL_INFOBAR_TEXT); form->addCCItem(temp); diff --git a/src/gui/weather.h b/src/gui/weather.h index 79b12eba4..772ec60e2 100644 --- a/src/gui/weather.h +++ b/src/gui/weather.h @@ -35,12 +35,23 @@ #include +struct current_data +{ + std::string icon; + float temperature; + + current_data(): + icon(""), + temperature(0) + {} +}; + typedef struct { - std::string wicon; - float min_temp; - float max_temp; time_t timestamp; + std::string icon; + float temperatureMin; + float temperatureMax; } forecast_data; class CWeather @@ -49,8 +60,7 @@ class CWeather std::string coords; std::string city; std::string timezone; - std::string act_wicon; - float act_temp; + current_data current; std::vector v_forecast; CComponentsForm *form; std::string key; @@ -63,28 +73,30 @@ class CWeather ~CWeather(); bool checkUpdate(bool forceUpdate = false); void setCoords(std::string new_coords, std::string new_city = "Unknown"); - void show(int x = 50, int y = 50); - void hide(); + std::string getCity() { return city; }; - std::string getActTemp() + std::string getCurrentTemperature() { - return to_string((int)(act_temp + 0.5)); + return to_string((int)(current.temperature + 0.5)); }; - std::string getForecastTemp(int i = 0) + std::string getCurrentIcon() { - return to_string((int)(v_forecast[i].max_temp + 0.5)); + return ICONSDIR"/weather/" + current.icon; }; - std::string getActIcon() + std::string getForecastTemperatureMax(int i = 0) { - return ICONSDIR"/weather/" + act_wicon; + return to_string((int)(v_forecast[i].temperatureMax + 0.5)); }; std::string getForecastIcon(int i = 0) { - return ICONSDIR"/weather/" + v_forecast[i].wicon; + return ICONSDIR"/weather/" + v_forecast[i].icon; }; + + void show(int x = 50, int y = 50); + void hide(); }; #endif