Skip to content

Commit d8a0959

Browse files
committed
weather: Add function for converting to units
Handles rounding correctly.
1 parent c2c53bc commit d8a0959

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/components/ble/SimpleWeatherService.h

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ namespace Pinetime {
112112
return celsius * 9 / 5 + 3200;
113113
}
114114

115+
static int16_t TempToUnits(int16_t temp) {
116+
return temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
117+
}
118+
115119
private:
116120
// 00050000-78fc-48fe-8e23-433b3a1942d0
117121
static constexpr ble_uuid128_t BaseUuid() {

src/displayapp/screens/WatchFaceDigital.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void WatchFaceDigital::Refresh() {
180180
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
181181
tempUnit = 'F';
182182
}
183-
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
183+
temp = Controllers::SimpleWeatherService::TempToUnits(temp);
184184
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
185185
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
186186
} else {

src/displayapp/screens/WatchFacePineTimeStyle.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ void WatchFacePineTimeStyle::Refresh() {
547547
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
548548
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
549549
}
550-
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
550+
temp = Controllers::SimpleWeatherService::TempToUnits(temp);
551551
lv_label_set_text_fmt(temperature, "%d°", temp);
552552
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
553553
} else {

0 commit comments

Comments
 (0)