From f7c87a700d2d9cd05469f1b5b2966a01808ce0e1 Mon Sep 17 00:00:00 2001 From: FintasticMan Date: Wed, 9 Oct 2024 12:04:53 +0200 Subject: weather: Switch to std::optional for Forecast days Also only iterate over the number of days actually in use, rather than MaxNbForecastDays. --- src/displayapp/screens/Weather.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/displayapp') diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp index 275153e9..6699532a 100644 --- a/src/displayapp/screens/Weather.cpp +++ b/src/displayapp/screens/Weather.cpp @@ -153,22 +153,22 @@ void Weather::Refresh() { if (optCurrentForecast) { std::tm localTime = *std::localtime(reinterpret_cast(&optCurrentForecast->timestamp)); - for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { - int16_t minTemp = optCurrentForecast->days[i].maxTemperature.Celsius(); - int16_t maxTemp = optCurrentForecast->days[i].minTemperature.Celsius(); + for (int i = 0; i < optCurrentForecast->nbDays; i++) { + int16_t minTemp = optCurrentForecast->days[i]->maxTemperature.Celsius(); + int16_t maxTemp = optCurrentForecast->days[i]->minTemperature.Celsius(); if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { - minTemp = optCurrentForecast->days[i].maxTemperature.Fahrenheit(); - maxTemp = optCurrentForecast->days[i].minTemperature.Fahrenheit(); + minTemp = optCurrentForecast->days[i]->maxTemperature.Fahrenheit(); + maxTemp = optCurrentForecast->days[i]->minTemperature.Fahrenheit(); } - lv_table_set_cell_type(forecast, 2, i, TemperatureStyle(optCurrentForecast->days[i].maxTemperature)); - lv_table_set_cell_type(forecast, 3, i, TemperatureStyle(optCurrentForecast->days[i].minTemperature)); + lv_table_set_cell_type(forecast, 2, i, TemperatureStyle(optCurrentForecast->days[i]->maxTemperature)); + lv_table_set_cell_type(forecast, 3, i, TemperatureStyle(optCurrentForecast->days[i]->minTemperature)); uint8_t wday = localTime.tm_wday + i + 1; if (wday > 7) { wday -= 7; } const char* dayOfWeek = Controllers::DateTime::DayOfWeekShortToStringLow(static_cast(wday)); lv_table_set_cell_value(forecast, 0, i, dayOfWeek); - lv_table_set_cell_value(forecast, 1, i, Symbols::GetSymbol(optCurrentForecast->days[i].iconId)); + lv_table_set_cell_value(forecast, 1, i, Symbols::GetSymbol(optCurrentForecast->days[i]->iconId)); // Pad cells based on the largest number of digits on each column char maxPadding[3] = " "; char minPadding[3] = " "; -- cgit v1.2.3-70-g09d2