Skip to content

Commit

Permalink
Create a Color function in SimpleWeatherService's Temperature class
Browse files Browse the repository at this point in the history
Move the TemperatureColor function to SimpleWeatherService's Temperature
class and rename it to Color for simple reuse across the code base.
  • Loading branch information
JustScott committed Dec 30, 2024
1 parent 1bdf756 commit 2a1f143
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/components/ble/SimpleWeatherService.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <array>
#include <memory>

#include <lvgl/lvgl.h>
#include "displayapp/InfiniTimeTheme.h"

#define min // workaround: nimble's min/max macros conflict with libstdc++
#define max
#include <host/ble_gap.h>
Expand Down Expand Up @@ -86,6 +89,17 @@ namespace Pinetime {
return raw == other.raw;
}

[[nodiscard]] lv_color_t Color() const {
if (Celsius() <= 0) { // freezing
return Colors::blue;
} else if (Celsius() <= 4) { // ice
return LV_COLOR_CYAN;
} else if (Celsius() >= 27) { // hot
return Colors::deepOrange;
}
return Colors::orange; // normal
}

private:
int16_t raw;
};
Expand Down
15 changes: 1 addition & 14 deletions src/displayapp/screens/WatchFaceTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@

using namespace Pinetime::Applications::Screens;

namespace {
lv_color_t TemperatureColor(Pinetime::Controllers::SimpleWeatherService::Temperature temp) {
if (temp.Celsius() <= 0) { // freezing
return Colors::blue;
} else if (temp.Celsius() <= 4) { // ice
return LV_COLOR_CYAN;
} else if (temp.Celsius() >= 27) { // hot
return Colors::deepOrange;
}
return Colors::orange; // normal
}
}

WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Expand Down Expand Up @@ -177,7 +164,7 @@ void WatchFaceTerminal::Refresh() {
if (optCurrentWeather) {
int16_t temp = optCurrentWeather->temperature.Celsius();
char tempUnit = 'C';
lv_obj_set_style_local_text_color(weather, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, TemperatureColor(optCurrentWeather->temperature));
lv_obj_set_style_local_text_color(weather, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, optCurrentWeather->temperature.Color());
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
temp = optCurrentWeather->temperature.Fahrenheit();
tempUnit = 'F';
Expand Down

0 comments on commit 2a1f143

Please sign in to comment.