InfiniTime icon indicating copy to clipboard operation
InfiniTime copied to clipboard

weather: Add function for converting to units

Open FintasticMan opened this issue 1 year ago • 4 comments

Handles rounding correctly.

FintasticMan avatar Feb 12 '24 11:02 FintasticMan

Build size and comparison to main:

Section Size Difference
text 373224B -16B
data 940B 0B
bss 63516B 0B

github-actions[bot] avatar Feb 12 '24 11:02 github-actions[bot]

You could use structs of one int to make the types really safe.

minacode avatar Feb 15 '24 14:02 minacode

I'm ok with the current state. I however thought about another option.

SimpleWeatherService would define a Temperature type : PineTime::Controllers::SimpleWeatherService::Temperature. It's the internal representation of a temperature in the SompleWeatherService expressed in "°C * 100"

struct Temperature {
  int16_t temperature;
}

Somewhere under DisplayApp, we would define another Temperature type : Pinetime::Applications::Temperature. It represent the temperature for the UI side of InfiniTime as an std::variant (TODO : check that the overhead of std::variant is negligible)

struct TemperatureCelsius {
  int16_t temperature;
}

struct TemperatureFahrenheit {
  int16_t temperature;
}

using Temperature = std::variant<TemperatureCelsius, TemperatureFahrenheit temperature

Then, also under DisplayApp, we define a function that converts from SimpleWeatherService Temperature to "display" temperature :

Pinetime::Applications::Temperature Convert(PineTime::Controllers::SimpleWeatherService::Temperature, Controllers::Settings::WeatherFormat format);

This way, all the "temperature" types are strongly typed and it's impossible to implicitly convert from one to another. Also SimpleWeatherService does not have any code related to the UI anymore.

JF002 avatar Feb 15 '24 20:02 JF002