- weather/lcd4l: add some more weather data

Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
svenhoefer
2019-03-23 11:04:46 +01:00
committed by Thilo Graf
parent 9d5698865e
commit e04de3136e
4 changed files with 75 additions and 3 deletions

View File

@@ -105,7 +105,9 @@ extern CPictureViewer *g_PicViewer;
#define PBCOLOR LCD_DATADIR "pbcolor" #define PBCOLOR LCD_DATADIR "pbcolor"
#define WEATHER_CITY LCD_DATADIR "weather_city" #define WEATHER_CITY LCD_DATADIR "weather_city"
#define WEATHER_TIMESTAMP LCD_DATADIR "weather_timestamp"
#define WEATHER_TEMP LCD_DATADIR "weather_temp" #define WEATHER_TEMP LCD_DATADIR "weather_temp"
#define WEATHER_WIND LCD_DATADIR "weather_wind"
#define WEATHER_ICON LCD_DATADIR "weather_icon" #define WEATHER_ICON LCD_DATADIR "weather_icon"
#define FLAG_LCD4LINUX "/tmp/.lcd4linux" #define FLAG_LCD4LINUX "/tmp/.lcd4linux"
@@ -300,7 +302,9 @@ void CLCD4l::Init()
m_End = "00:00"; m_End = "00:00";
m_wcity = ""; m_wcity = "";
m_wtimestamp = "";
m_wtemp = ""; m_wtemp = "";
m_wwind = "";
m_wicon = ""; m_wicon = "";
if (!access(LCD_DATADIR, F_OK) == 0) if (!access(LCD_DATADIR, F_OK) == 0)
@@ -1064,17 +1068,40 @@ void CLCD4l::ParseInfo(uint64_t parseID, bool newID, bool firstRun)
m_wcity = wcity; m_wcity = wcity;
} }
int forecast = 1; // days for forecast std::string wtimestamp = to_string((int)CWeather::getInstance()->getCurrentTimestamp());
if (m_wtimestamp.compare(wtimestamp))
{
WriteFile(WEATHER_TIMESTAMP, wtimestamp);
m_wtimestamp = wtimestamp;
}
int forecast = 5; // days for forecast
std::string wtemp = CWeather::getInstance()->getCurrentTemperature(); std::string wtemp = CWeather::getInstance()->getCurrentTemperature();
for (int i = 0; i < 1 + forecast; i++) for (int i = 0; i < 1 + forecast; i++)
wtemp += "\n" + CWeather::getInstance()->getForecastTemperatureMax(i); {
wtemp += "\n" + CWeather::getInstance()->getForecastTemperatureMin(i);
wtemp += "|" + CWeather::getInstance()->getForecastTemperatureMax(i);
}
if (m_wtemp.compare(wtemp)) if (m_wtemp.compare(wtemp))
{ {
WriteFile(WEATHER_TEMP, wtemp); WriteFile(WEATHER_TEMP, wtemp);
m_wtemp = wtemp; m_wtemp = wtemp;
} }
std::string wwind = CWeather::getInstance()->getCurrentWindSpeed();
wwind += "|" + CWeather::getInstance()->getCurrentWindBearing();
for (int i = 0; i < 1 + forecast; i++)
{
wwind += "\n" + CWeather::getInstance()->getForecastWindSpeed(i);
wwind += "|" + CWeather::getInstance()->getForecastWindBearing(i);
}
if (m_wwind.compare(wwind))
{
WriteFile(WEATHER_WIND, wwind);
m_wwind = wwind;
}
std::string wicon = CWeather::getInstance()->getCurrentIcon(); std::string wicon = CWeather::getInstance()->getCurrentIcon();
for (int i = 0; i < 1 + forecast; i++) for (int i = 0; i < 1 + forecast; i++)
wicon += "\n" + CWeather::getInstance()->getForecastIcon(i); wicon += "\n" + CWeather::getInstance()->getForecastIcon(i);

View File

@@ -129,7 +129,9 @@ class CLCD4l
std::string m_pbcolor; std::string m_pbcolor;
std::string m_wcity; std::string m_wcity;
std::string m_wtimestamp;
std::string m_wtemp; std::string m_wtemp;
std::string m_wwind;
std::string m_wicon; std::string m_wicon;
}; };

View File

@@ -128,7 +128,10 @@ bool CWeather::GetWeatherDetails()
if (found > 0) if (found > 0)
{ {
timezone = DataValues["timezone"].asString(); timezone = DataValues["timezone"].asString();
current.timestamp = DataValues["currently"].get("time", 0).asDouble();
current.temperature = DataValues["currently"].get("temperature", "").asFloat(); current.temperature = DataValues["currently"].get("temperature", "").asFloat();
current.windSpeed = DataValues["currently"].get("windSpeed", 0).asFloat();
current.windBearing = DataValues["currently"].get("windBearing", 0).asDouble();
current.icon = DataValues["currently"].get("icon", "").asString(); current.icon = DataValues["currently"].get("icon", "").asString();
if (current.icon.empty()) if (current.icon.empty())
current.icon = "unknown.png"; current.icon = "unknown.png";
@@ -148,6 +151,8 @@ bool CWeather::GetWeatherDetails()
daily_data.icon = daily_data.icon + ".png"; daily_data.icon = daily_data.icon + ".png";
daily_data.temperatureMin = elements[i].get("temperatureMin", "").asFloat(); daily_data.temperatureMin = elements[i].get("temperatureMin", "").asFloat();
daily_data.temperatureMax = elements[i].get("temperatureMax", "").asFloat(); daily_data.temperatureMax = elements[i].get("temperatureMax", "").asFloat();
daily_data.windSpeed = elements[i].get("windSpeed", 0).asFloat();
daily_data.windBearing = elements[i].get("windBearing", 0).asDouble();
struct tm *timeinfo; struct tm *timeinfo;
timeinfo = localtime(&daily_data.timestamp); timeinfo = localtime(&daily_data.timestamp);

View File

@@ -36,12 +36,18 @@
struct current_data struct current_data
{ {
time_t timestamp;
std::string icon; std::string icon;
float temperature; float temperature;
float windSpeed;
int windBearing;
current_data(): current_data():
timestamp(0),
icon(""), icon(""),
temperature(0) temperature(0),
windSpeed(0),
windBearing(0)
{} {}
}; };
@@ -51,6 +57,8 @@ typedef struct
std::string icon; std::string icon;
float temperatureMin; float temperatureMin;
float temperatureMax; float temperatureMax;
float windSpeed;
int windBearing;
} forecast_data; } forecast_data;
class CWeather class CWeather
@@ -77,18 +85,48 @@ class CWeather
{ {
return city; return city;
}; };
#if 0
std::string getCurrentTimestamp()
{
return to_string((int)(current.timestamp));
};
#endif
time_t getCurrentTimestamp()
{
return current.timestamp;
};
std::string getCurrentTemperature() std::string getCurrentTemperature()
{ {
return to_string((int)(current.temperature + 0.5)); return to_string((int)(current.temperature + 0.5));
}; };
std::string getCurrentWindSpeed()
{
return to_string(current.windSpeed);
};
std::string getCurrentWindBearing()
{
return to_string(current.windBearing);
};
std::string getCurrentIcon() std::string getCurrentIcon()
{ {
return ICONSDIR"/weather/" + current.icon; return ICONSDIR"/weather/" + current.icon;
}; };
std::string getForecastTemperatureMin(int i = 0)
{
return to_string((int)(v_forecast[i].temperatureMin + 0.5));
};
std::string getForecastTemperatureMax(int i = 0) std::string getForecastTemperatureMax(int i = 0)
{ {
return to_string((int)(v_forecast[i].temperatureMax + 0.5)); return to_string((int)(v_forecast[i].temperatureMax + 0.5));
}; };
std::string getForecastWindSpeed(int i = 0)
{
return to_string(v_forecast[i].windSpeed);
};
std::string getForecastWindBearing(int i = 0)
{
return to_string(v_forecast[i].windBearing);
};
std::string getForecastIcon(int i = 0) std::string getForecastIcon(int i = 0)
{ {
return ICONSDIR"/weather/" + v_forecast[i].icon; return ICONSDIR"/weather/" + v_forecast[i].icon;