From 29ad09f4ef54126831d36fe1b99e794059fc5421 Mon Sep 17 00:00:00 2001 From: FintasticMan Date: Tue, 20 Feb 2024 11:25:02 +0100 Subject: weather: Refactor temperature type for type safety There is now a Temperature struct in the weather service, which holds the internal representation. There is also a temperature struct in the Applications namespace, which holds the temperature in either Celsius or Fahrenheit. --- src/components/ble/SimpleWeatherService.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/components/ble/SimpleWeatherService.h') diff --git a/src/components/ble/SimpleWeatherService.h b/src/components/ble/SimpleWeatherService.h index 30cc5c03..ee40fd6f 100644 --- a/src/components/ble/SimpleWeatherService.h +++ b/src/components/ble/SimpleWeatherService.h @@ -61,13 +61,17 @@ namespace Pinetime { Unknown = 255 }; + struct Temperature { + int16_t temp; + }; + using Location = std::array; // 32 char + \0 (end of string) struct CurrentWeather { CurrentWeather(uint64_t timestamp, - int16_t temperature, - int16_t minTemperature, - int16_t maxTemperature, + Temperature temperature, + Temperature minTemperature, + Temperature maxTemperature, Icons iconId, Location&& location) : timestamp {timestamp}, @@ -79,9 +83,9 @@ namespace Pinetime { } uint64_t timestamp; - int16_t temperature; - int16_t minTemperature; - int16_t maxTemperature; + Temperature temperature; + Temperature minTemperature; + Temperature maxTemperature; Icons iconId; Location location; @@ -93,8 +97,8 @@ namespace Pinetime { uint8_t nbDays; struct Day { - int16_t minTemperature; - int16_t maxTemperature; + Temperature minTemperature; + Temperature maxTemperature; Icons iconId; bool operator==(const Day& other) const; @@ -108,10 +112,6 @@ namespace Pinetime { std::optional Current() const; std::optional GetForecast() const; - static int16_t CelsiusToFahrenheit(int16_t celsius) { - return celsius * 9 / 5 + 3200; - } - private: // 00050000-78fc-48fe-8e23-433b3a1942d0 static constexpr ble_uuid128_t BaseUuid() { -- cgit v1.2.3-70-g09d2