diff options
Diffstat (limited to 'src/localtemp.cpp')
| -rw-r--r-- | src/localtemp.cpp | 120 |
1 files changed, 87 insertions, 33 deletions
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: "); } |
