@@ -35,16 +35,22 @@ namespace {
3535 }
3636}
3737
38- Weather::Weather (Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService)
39- : settingsController {settingsController}, weatherService {weatherService} {
38+ Weather::Weather (Controllers::Settings& settingsController,
39+ Controllers::SimpleWeatherService& weatherService,
40+ Controllers::DateTime& dateTimeController)
41+ : settingsController {settingsController}, weatherService {weatherService}, dateTimeController {dateTimeController} {
4042
4143 temperature = lv_label_create (lv_scr_act (), nullptr );
4244 lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
4345 lv_obj_set_style_local_text_font (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
4446 lv_label_set_text (temperature, " ---" );
45- lv_obj_align (temperature, nullptr , LV_ALIGN_CENTER, 0 , -30 );
47+ lv_obj_align (temperature, nullptr , LV_ALIGN_CENTER, 0 , -32 );
4648 lv_obj_set_auto_realign (temperature, true );
4749
50+ lastUpdated = lv_label_create (lv_scr_act (), nullptr );
51+ lv_obj_set_style_local_text_color (lastUpdated, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
52+ lv_label_set_text (lastUpdated, " " );
53+
4854 minTemperature = lv_label_create (lv_scr_act (), nullptr );
4955 lv_obj_set_style_local_text_color (minTemperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
5056 lv_label_set_text (minTemperature, " " );
@@ -137,10 +143,44 @@ void Weather::Refresh() {
137143 lv_label_set_text_fmt (temperature, " %d°%c" , temp, tempUnit);
138144 lv_label_set_text_fmt (minTemperature, " %d°" , minTemp);
139145 lv_label_set_text_fmt (maxTemperature, " %d°" , maxTemp);
146+
147+ std::chrono::seconds secondsSinceEpoch =
148+ std::chrono::duration_cast<std::chrono::seconds>(dateTimeController.CurrentDateTime ().time_since_epoch ());
149+ int32_t secondsSinceWeatherUpdate = secondsSinceEpoch.count () - optCurrentWeather->timestamp ;
150+ int8_t minutesSinceWeatherUpdate = secondsSinceWeatherUpdate / 60 ;
151+ int8_t hoursSinceWeatherUpdate = secondsSinceWeatherUpdate / 3600 ;
152+
153+ constexpr uint8_t Y_POSITION = 108 ;
154+ constexpr uint8_t X_SINGLE_DIGIT_POSITION = 90 ;
155+ constexpr uint8_t X_TWO_DIGIT_POSITION = 78 ;
156+ constexpr uint8_t X_NOW_POSITION = 102 ;
157+
158+ lv_obj_set_pos (lastUpdated, X_SINGLE_DIGIT_POSITION, Y_POSITION);
159+
160+ if (hoursSinceWeatherUpdate > 0 ) {
161+ if (hoursSinceWeatherUpdate > 9 ) {
162+ lv_obj_set_pos (lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
163+ }
164+ lv_label_set_text_fmt (lastUpdated, " %dh ago" , hoursSinceWeatherUpdate);
165+ } else if (minutesSinceWeatherUpdate > 0 ) {
166+ if (minutesSinceWeatherUpdate > 9 && minutesSinceWeatherUpdate < 60 ) {
167+ lv_obj_set_pos (lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
168+ }
169+ lv_label_set_text_fmt (lastUpdated, " %dm ago" , minutesSinceWeatherUpdate);
170+ } else if (secondsSinceWeatherUpdate > 30 ) {
171+ if (secondsSinceWeatherUpdate > 9 && secondsSinceWeatherUpdate < 60 ) {
172+ lv_obj_set_pos (lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
173+ }
174+ lv_label_set_text_fmt (lastUpdated, " %ds ago" , secondsSinceWeatherUpdate);
175+ } else if (secondsSinceWeatherUpdate < 31 ) {
176+ lv_obj_set_pos (lastUpdated, X_NOW_POSITION, Y_POSITION);
177+ lv_label_set_text_fmt (lastUpdated, " Now" , secondsSinceWeatherUpdate);
178+ }
140179 } else {
141180 lv_label_set_text (icon, " " );
142181 lv_label_set_text (condition, " " );
143182 lv_label_set_text (temperature, " ---" );
183+ lv_label_set_text (lastUpdated, " " );
144184 lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
145185 lv_label_set_text (minTemperature, " " );
146186 lv_label_set_text (maxTemperature, " " );
0 commit comments