summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dwgo.cpp4
-rw-r--r--src/localtemp.cpp120
-rw-r--r--src/localtemp.h2
3 files changed, 90 insertions, 36 deletions
diff --git a/src/dwgo.cpp b/src/dwgo.cpp
index cae2e4e..4ffa462 100644
--- a/src/dwgo.cpp
+++ b/src/dwgo.cpp
@@ -71,7 +71,7 @@ typedef struct
typedef struct
{
- char station[5]; // Metar ID [ 4 characters + \0
+ char station[6]; // Metar ID [ 5 characters + \0
char name[16]; // Station name (it's for you). It's short to fit in.
} T_Station;
@@ -616,7 +616,7 @@ void displaytemp(XDraw *image, const DwgoConf cfg, localtemp *local_stt, int tm_
image->drawString(sttext.x, sttext.y, sttext.z, txcolor, (char*)txt_font, (char*)local_stt->location_name.data());
if ((sttime.y>-1) && (local_stt->loaded))
{
- time_taking=local_stt->info_time+tm_diff; // Translates to local time
+ time_taking=local_stt->info_time; // Translates to local time
moment=localtime(&time_taking);
sprintf(tmp_disp, "%.2d:%.2d", moment->tm_hour,moment->tm_min); // Makes it 00:00
image->drawString(sttime.x, sttime.y, sttime.z, ticolor, (char*)tim_font, (char*)tmp_disp);
diff --git a/src/localtemp.cpp b/src/localtemp.cpp
index 3a64200..d423bf9 100644
--- a/src/localtemp.cpp
+++ b/src/localtemp.cpp
@@ -123,45 +123,97 @@ void localtemp::set_humidity(int hum)
* Date Author Modification *
* *
*************************************************************/
-void localtemp::get_ob_info(double precip10m)
+void localtemp::get_ob_info(
+ double precip10m,
+ double sun10m,
+ time_t observation_time
+)
{
- mInfo.CB=false;
- mInfo.fog=undef_fog; // Not reported by Amedas
+ mInfo.CB = false;
+ mInfo.sky = undef_sky;
+ mInfo.rain = undef_rain;
+ mInfo.fog = undef_fog;
- if (precip10m>0.0)
- {
- if (this->celsius<=2)
- mInfo.rain=snow;
+ theme = DEFAULT_THEME;
+
+ /*
+ * Precipitation has the highest priority.
+ */
+ if (precip10m > 0.0)
+ {
+ if (this->celsius <= 2)
+ {
+ mInfo.rain = snow;
+ theme = SNOWY_THEME;
+ }
+ else
+ {
+ mInfo.rain = rain;
+ theme = RAINY_THEME;
+ }
+
+ return;
+ }
+
+ struct tm *local_observation =
+ localtime(&observation_time);
+
+ if (local_observation == NULL)
+ {
+ theme = DEFAULT_THEME;
+ return;
+ }
+
+ int hour = local_observation->tm_hour;
+ int month = local_observation->tm_mon + 1;
+
+ int sunrise_hour;
+ int sunset_hour;
+
+ if (month >= 5 && month <= 8)
+ {
+ sunrise_hour = 4;
+ sunset_hour = 19;
+ }
+ else if (month == 4 || month == 9)
+ {
+ sunrise_hour = 5;
+ sunset_hour = 18;
+ }
else
- mInfo.rain=rain;
- mInfo.sky=undef_sky;
- }
- else
- {
- mInfo.rain=undef_rain;
- mInfo.sky=clear;
- }
+ {
+ sunrise_hour = 6;
+ sunset_hour = 17;
+ }
- // The most important for the display theme is rain, then fog and then sky conditions
- if (mInfo.rain!=undef_rain)
+ bool daytime =
+ hour >= sunrise_hour &&
+ hour < sunset_hour;
+
+ if (!daytime)
{
- switch (mInfo.rain)
- {
- case rain: theme=RAINY_THEME; break;
- case snow: theme=SNOWY_THEME; break;
- default: break;
- }
+ theme = DEFAULT_THEME;
+ return;
+ }
+
+ /*
+ * sun10m is the sunshine duration during the preceding
+ * ten minutes, not direct solar irradiance.
+ */
+ if(sun10m<0.0)
+ {
+ theme=DEFAULT_THEME;
}
- else if (mInfo.sky!=undef_sky)
+ else if(sun10m>0.0)
{
- switch (mInfo.sky)
- {
- case clear : theme=CLEAR_THEME; break;
- default: break;
- }
+ mInfo.sky = clear;
+ theme = CLEAR_THEME;
+ }
+ else
+ {
+ mInfo.sky = cloudy;
+ theme = CLOUDY_THEME;
}
- else
- theme=DEFAULT_THEME; // Nothing significant found.
}
/*************************************************************
@@ -285,7 +337,7 @@ bool localtemp::getInfo()
HTTP_Request *http;
string yyyymmdd, hhmmss, block3h;
time_t obs_utc;
- double temp_c, hum, precip10m;
+ double temp_c, hum, precip10m, sun10m;
this->error=0; // No error
this->loaded=false;
@@ -368,8 +420,10 @@ bool localtemp::getInfo()
this->set_humidity((int)hum);
if (!extract_json_number(this->ob, "precipitation10m", precip10m))
precip10m=0.0;
+ if (!extract_json_number(this->ob, "sun10m", sun10m))
+ sun10m=-1.0;
this->info_time=obs_utc; // Actual observation instant, in UTC
- get_ob_info(precip10m); // Work out theme from precipitation/temperature
+ get_ob_info(precip10m, sun10m, this->info_time); // Work out theme from precipitation/temperature
this->loaded=true;
verbsth(VERB_ASTTO, "Close connection: ");
}
diff --git a/src/localtemp.h b/src/localtemp.h
index 2e238cf..e199a9a 100644
--- a/src/localtemp.h
+++ b/src/localtemp.h
@@ -59,6 +59,6 @@ public:
private:
void set_temp(double temp_c);
void set_humidity(int hum);
- void get_ob_info(double precip10m);
+ void get_ob_info(double precip10m, double sun10m, time_t observation_time);
bool fetch_latest_time(std::string &yyyymmdd, std::string &hhmmss, std::string &block3h, time_t &obs_utc); bool extract_json_number(const std::string &json, const std::string &key, double &value);
};