diff options
| author | FintasticMan <finlay.neon.kid@gmail.com> | 2024-02-20 11:25:02 +0100 |
|---|---|---|
| committer | JF <JF002@users.noreply.github.com> | 2024-11-04 21:22:38 +0100 |
| commit | 29ad09f4ef54126831d36fe1b99e794059fc5421 (patch) | |
| tree | 4699e2008850c8f99297abcf549844317ab0cdb2 /src/components/ble/SimpleWeatherService.h | |
| parent | afeded0126ff3bb30bdd5b1ed55f5dddca8b92d5 (diff) | |
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.
Diffstat (limited to 'src/components/ble/SimpleWeatherService.h')
| -rw-r--r-- | src/components/ble/SimpleWeatherService.h | 24 |
1 files changed, 12 insertions, 12 deletions
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<char, 33>; // 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<CurrentWeather> Current() const; std::optional<Forecast> 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() { |
