-
-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
weather: Add function for converting to units #2015
base: main
Are you sure you want to change the base?
Conversation
Build size and comparison to main:
|
@@ -112,6 +112,10 @@ namespace Pinetime { | |||
return celsius * 9 / 5 + 3200; | |||
} | |||
|
|||
static int16_t TempToUnits(int16_t temp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this name is not quite representative, since it doesn't include units. Maybe something like "RenderTemp" or "DisplayTemp" or "RoundTemp"? Not entirely sure, naming is hard :/
Other than that, I really like what you're doing centralizing this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the meaning of the input and output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The input is a temperature in units multiplied by 100, and the output is temperature in the actual unit. I wasn't sure of the naming either, it's a surprisingly difficult operation to give a name to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's basically FixedPoint2ToIntRounded? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CentiToUnit
? As in centicelsius to celsius or centifahrenheit to fahrenheit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method could simply be called Convert()
if we used strong types for arguments. Ex:
static DisplayTemperature Convert(const SimpleWeatherService::RawTemperature temperature)
Using stronger types for
- temperature coming from the weather service (in "centi celsius degrees")
- temperature in °C
- temperature in °F
Would probably help with code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just done something like that. I decided not to distinguish between the temperature in C or in F. Do you think this makes sense?
Handles rounding correctly.
d8a0959
to
f07699a
Compare
You could use structs of one int to make the types really safe. |
I'm ok with the current state. I however thought about another option. SimpleWeatherService would define a Temperature type : struct Temperature {
int16_t temperature;
} Somewhere under DisplayApp, we would define another Temperature type : 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. |
Handles rounding correctly.