diff options
| author | FintasticMan <finlay.neon.kid@gmail.com> | 2024-10-02 11:58:32 +0200 |
|---|---|---|
| committer | JF <JF002@users.noreply.github.com> | 2024-11-04 21:22:38 +0100 |
| commit | e247bd701903cc507ba0e0ac4f938ab4616562e7 (patch) | |
| tree | 2b7e71bb5083eb57baa8056b1b78adc8a24946ae /src/components/ble/SimpleWeatherService.h | |
| parent | 29ad09f4ef54126831d36fe1b99e794059fc5421 (diff) | |
Switch to simpler temperature interface
Diffstat (limited to 'src/components/ble/SimpleWeatherService.h')
| -rw-r--r-- | src/components/ble/SimpleWeatherService.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/components/ble/SimpleWeatherService.h b/src/components/ble/SimpleWeatherService.h index ee40fd6f..36bbea48 100644 --- a/src/components/ble/SimpleWeatherService.h +++ b/src/components/ble/SimpleWeatherService.h @@ -61,8 +61,33 @@ namespace Pinetime { Unknown = 255 }; - struct Temperature { - int16_t temp; + class Temperature { + public: + explicit Temperature(int16_t raw = 0) : raw {raw} { + } + + [[nodiscard]] int16_t PreciseCelsius() const { + return raw; + } + + [[nodiscard]] int16_t PreciseFahrenheit() const { + return raw * 9 / 5 + 3200; + } + + [[nodiscard]] int16_t Celsius() const { + return (PreciseCelsius() + 50) / 100; + } + + [[nodiscard]] int16_t Fahrenheit() const { + return (PreciseFahrenheit() + 50) / 100; + } + + bool operator==(const Temperature& other) const { + return raw == other.raw; + } + + private: + int16_t raw; }; using Location = std::array<char, 33>; // 32 char + \0 (end of string) |
