From e247bd701903cc507ba0e0ac4f938ab4616562e7 Mon Sep 17 00:00:00 2001 From: FintasticMan Date: Wed, 2 Oct 2024 11:58:32 +0200 Subject: Switch to simpler temperature interface --- src/components/ble/SimpleWeatherService.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/components/ble/SimpleWeatherService.h') 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; // 32 char + \0 (end of string) -- cgit v1.2.3-70-g09d2