Skip to content

Commit

Permalink
weather: Define function to round and render temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
vkareh authored and JF002 committed Feb 18, 2024
1 parent 68ae335 commit 6ab512a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/displayapp/screens/Weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ namespace {
}
return LV_TABLE_PART_CELL5; // normal
}

int16_t RoundTemperature(int16_t temp) {
return temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
}
}

Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService)
Expand Down Expand Up @@ -127,14 +131,11 @@ void Weather::Refresh() {
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(maxTemp);
tempUnit = 'F';
}
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
maxTemp = maxTemp / 100 + (maxTemp % 100 >= 50 ? 1 : 0);
minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0);
lv_label_set_text(icon, Symbols::GetSymbol(optCurrentWeather->iconId));
lv_label_set_text(condition, Symbols::GetCondition(optCurrentWeather->iconId));
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
lv_label_set_text_fmt(minTemperature, "%d°", minTemp);
lv_label_set_text_fmt(maxTemperature, "%d°", maxTemp);
lv_label_set_text_fmt(temperature, "%d°%c", RoundTemperature(temp), tempUnit);
lv_label_set_text_fmt(minTemperature, "%d°", RoundTemperature(minTemp));
lv_label_set_text_fmt(maxTemperature, "%d°", RoundTemperature(maxTemp));
} else {
lv_label_set_text(icon, "");
lv_label_set_text(condition, "");
Expand Down Expand Up @@ -164,8 +165,8 @@ void Weather::Refresh() {
if (wday > 7) {
wday -= 7;
}
maxTemp = maxTemp / 100 + (maxTemp % 100 >= 50 ? 1 : 0);
minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0);
maxTemp = RoundTemperature(maxTemp);
minTemp = RoundTemperature(minTemp);
const char* dayOfWeek = Controllers::DateTime::DayOfWeekShortToStringLow(static_cast<Controllers::DateTime::Days>(wday));
lv_table_set_cell_value(forecast, 0, i, dayOfWeek);
lv_table_set_cell_value(forecast, 1, i, Symbols::GetSymbol(optCurrentForecast->days[i].iconId));
Expand Down

0 comments on commit 6ab512a

Please sign in to comment.