@@ -24,16 +24,22 @@ namespace {
2424 }
2525}
2626
27- Weather::Weather (Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService)
28- : settingsController {settingsController}, weatherService {weatherService} {
27+ Weather::Weather (Controllers::Settings& settingsController,
28+ Controllers::SimpleWeatherService& weatherService,
29+ Controllers::DateTime& dateTimeController)
30+ : settingsController {settingsController}, weatherService {weatherService}, dateTimeController {dateTimeController} {
2931
3032 temperature = lv_label_create (lv_scr_act (), nullptr );
3133 lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , LV_COLOR_WHITE );
3234 lv_obj_set_style_local_text_font (temperature, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , &jetbrains_mono_42);
3335 lv_label_set_text (temperature, " ---" );
34- lv_obj_align (temperature, nullptr , LV_ALIGN_CENTER , 0 , -30 );
36+ lv_obj_align (temperature, nullptr , LV_ALIGN_CENTER , 0 , -32 );
3537 lv_obj_set_auto_realign (temperature, true );
3638
39+ lastUpdated = lv_label_create (lv_scr_act (), nullptr );
40+ lv_obj_set_style_local_text_color (lastUpdated, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , Colors::bg);
41+ lv_label_set_text (lastUpdated, " " );
42+
3743 minTemperature = lv_label_create (lv_scr_act (), nullptr );
3844 lv_obj_set_style_local_text_color (minTemperature, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , Colors::bg);
3945 lv_label_set_text (minTemperature, " " );
@@ -123,10 +129,41 @@ void Weather::Refresh() {
123129 lv_label_set_text_fmt (temperature, " %d°%c" , temp, tempUnit);
124130 lv_label_set_text_fmt (minTemperature, " %d°" , minTemp);
125131 lv_label_set_text_fmt (maxTemperature, " %d°" , maxTemp);
132+
133+ auto secondsSinceEpoch = std::chrono::duration_cast<std::chrono::seconds>(dateTimeController.CurrentDateTime ().time_since_epoch ());
134+ int32_t secondsSinceWeatherUpdate = secondsSinceEpoch.count () - optCurrentWeather->timestamp ;
135+ int8_t minutesSinceWeatherUpdate = secondsSinceWeatherUpdate / 60 ;
136+ int8_t hoursSinceWeatherUpdate = secondsSinceWeatherUpdate / 3600 ;
137+
138+ constexpr uint8_t Y_POSITION = 108 ;
139+ constexpr uint8_t X_SINGLE_DIGIT_POSITION = 90 ;
140+ constexpr uint8_t X_TWO_DIGIT_POSITION = 78 ;
141+ constexpr uint8_t X_NOW_POSITION = 102 ;
142+
143+ lv_obj_set_pos (lastUpdated, X_SINGLE_DIGIT_POSITION , Y_POSITION );
144+
145+ if (hoursSinceWeatherUpdate > 0 ) {
146+ if (hoursSinceWeatherUpdate > 9 ) {
147+ lv_obj_set_pos (lastUpdated, X_TWO_DIGIT_POSITION , Y_POSITION );
148+ }
149+ lv_label_set_text_fmt (lastUpdated, " %dh ago" , hoursSinceWeatherUpdate);
150+ } else if (minutesSinceWeatherUpdate > 0 ) {
151+ if (minutesSinceWeatherUpdate > 9 ) {
152+ lv_obj_set_pos (lastUpdated, X_TWO_DIGIT_POSITION , Y_POSITION );
153+ }
154+ lv_label_set_text_fmt (lastUpdated, " %dm ago" , minutesSinceWeatherUpdate);
155+ } else if (secondsSinceWeatherUpdate > 30 ) {
156+ lv_obj_set_pos (lastUpdated, X_TWO_DIGIT_POSITION , Y_POSITION );
157+ lv_label_set_text_fmt (lastUpdated, " %ds ago" , secondsSinceWeatherUpdate);
158+ } else if (secondsSinceWeatherUpdate < 31 ) {
159+ lv_obj_set_pos (lastUpdated, X_NOW_POSITION , Y_POSITION );
160+ lv_label_set_text_fmt (lastUpdated, " Now" , secondsSinceWeatherUpdate);
161+ }
126162 } else {
127163 lv_label_set_text (icon, " " );
128164 lv_label_set_text (condition, " " );
129165 lv_label_set_text (temperature, " ---" );
166+ lv_label_set_text (lastUpdated, " " );
130167 lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT , LV_COLOR_WHITE );
131168 lv_label_set_text (minTemperature, " " );
132169 lv_label_set_text (maxTemperature, " " );
0 commit comments