-
-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
220 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#include "displayapp/screens/Weather.h" | ||
#include <lvgl/lvgl.h> | ||
#include "components/ble/SimpleWeatherService.h" | ||
#include "components/settings/Settings.h" | ||
#include "displayapp/DisplayApp.h" | ||
#include "displayapp/InfiniTimeTheme.h" | ||
#include "displayapp/screens/WeatherSymbols.h" | ||
|
||
using namespace Pinetime::Applications::Screens; | ||
|
||
Weather::Weather(Controllers::Settings& settingsController, | ||
Controllers::SimpleWeatherService& weatherService) | ||
: settingsController {settingsController}, weatherService {weatherService} { | ||
|
||
temperature = lv_label_create(lv_scr_act(), nullptr); | ||
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); | ||
lv_obj_set_style_local_text_font(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); | ||
lv_label_set_text(temperature, "---"); | ||
lv_obj_align(temperature, nullptr, LV_ALIGN_CENTER, 0, 0); | ||
lv_obj_set_auto_realign(temperature, true); | ||
|
||
condition = lv_label_create(lv_scr_act(), nullptr); | ||
lv_obj_set_style_local_text_color(condition, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); | ||
lv_label_set_text(condition, ""); | ||
lv_obj_align(condition, temperature, LV_ALIGN_OUT_TOP_MID, 0, 0); | ||
lv_obj_set_auto_realign(condition, true); | ||
|
||
icon = lv_label_create(lv_scr_act(), nullptr); | ||
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); | ||
lv_obj_set_style_local_text_font(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons); | ||
lv_label_set_text(icon, ""); | ||
lv_obj_align(icon, condition, LV_ALIGN_OUT_TOP_MID, 0, 0); | ||
lv_obj_set_auto_realign(icon, true); | ||
|
||
forecast = lv_table_create(lv_scr_act(), nullptr); | ||
lv_table_set_col_cnt(forecast, Controllers::SimpleWeatherService::MaxNbForecastDays); | ||
lv_table_set_row_cnt(forecast, 2); | ||
lv_obj_set_style_local_pad_all(forecast, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 0); | ||
lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, LV_COLOR_BLACK); | ||
lv_obj_align(forecast, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); | ||
|
||
forecastSym = lv_table_create(lv_scr_act(), nullptr); | ||
lv_table_set_col_cnt(forecastSym, Controllers::SimpleWeatherService::MaxNbForecastDays); | ||
lv_table_set_row_cnt(forecastSym, 1); | ||
lv_obj_set_style_local_pad_all(forecastSym, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 0); | ||
lv_obj_set_style_local_border_color(forecastSym, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, LV_COLOR_BLACK); | ||
lv_obj_set_style_local_text_font(forecastSym, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons); | ||
lv_obj_align(forecastSym, forecast, LV_ALIGN_OUT_TOP_LEFT, 0, 0); | ||
|
||
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { | ||
lv_table_set_col_width(forecastSym, i, 48); | ||
lv_table_set_cell_align(forecastSym, 0, i, LV_LABEL_ALIGN_CENTER); | ||
lv_table_set_col_width(forecast, i, 48); | ||
lv_table_set_cell_align(forecast, 0, i, LV_LABEL_ALIGN_CENTER); | ||
lv_table_set_cell_align(forecast, 1, i, LV_LABEL_ALIGN_CENTER); | ||
} | ||
|
||
taskRefresh = lv_task_create(RefreshTaskCallback, 1000, LV_TASK_PRIO_MID, this); | ||
} | ||
|
||
Weather::~Weather() { | ||
lv_task_del(taskRefresh); | ||
lv_obj_clean(lv_scr_act()); | ||
} | ||
|
||
void Weather::Refresh() { | ||
currentWeather = weatherService.Current(); | ||
if (currentWeather.IsUpdated()) { | ||
auto optCurrentWeather = currentWeather.Get(); | ||
if (optCurrentWeather) { | ||
int16_t temp = optCurrentWeather->temperature; | ||
char tempUnit = 'C'; | ||
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { | ||
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp); | ||
tempUnit = 'F'; | ||
} | ||
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0); | ||
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit); | ||
lv_label_set_text(condition, getCondition(optCurrentWeather->iconId)); | ||
lv_label_set_text(icon, Symbols::GetSymbol(optCurrentWeather->iconId)); | ||
} else { | ||
lv_label_set_text(temperature, "---"); | ||
lv_label_set_text(condition, ""); | ||
lv_label_set_text(icon, ""); | ||
} | ||
} | ||
|
||
currentForecast = weatherService.GetForecast(); | ||
if (currentForecast.IsUpdated()) { | ||
auto optCurrentForecast = currentForecast.Get(); | ||
if (optCurrentForecast) { | ||
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { | ||
int16_t minTemp = optCurrentForecast->days[i].minTemperature; | ||
int16_t maxTemp = optCurrentForecast->days[i].maxTemperature; | ||
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { | ||
minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(minTemp); | ||
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(maxTemp); | ||
} | ||
minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0); | ||
maxTemp = maxTemp / 100 + (maxTemp % 100 >= 50 ? 1 : 0); | ||
lv_table_set_cell_value(forecastSym, 0, i, Symbols::GetSymbol(optCurrentForecast->days[0].iconId)); | ||
lv_table_set_cell_value_fmt(forecast, 0, i, "%d", minTemp); | ||
lv_table_set_cell_value_fmt(forecast, 1, i, "%d", maxTemp); | ||
} | ||
} else { | ||
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { | ||
lv_table_set_cell_value(forecastSym, 0, i, ""); | ||
lv_table_set_cell_value(forecast, 0, i, ""); | ||
lv_table_set_cell_value(forecast, 1, i, ""); | ||
} | ||
} | ||
} | ||
} | ||
|
||
const char* Weather::getCondition(const Pinetime::Controllers::SimpleWeatherService::Icons icon) { | ||
switch (icon) { | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::Sun: | ||
return "Clear sky"; | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudsSun: | ||
return "Few clouds"; | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::Clouds: | ||
return "Scattered clouds"; | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::BrokenClouds: | ||
return "Broken clouds"; | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudShowerHeavy: | ||
return "Shower rain"; | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudSunRain: | ||
return "Rain"; | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::Thunderstorm: | ||
return "Thunderstorm"; | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::Snow: | ||
return "Snow"; | ||
case Pinetime::Controllers::SimpleWeatherService::Icons::Smog: | ||
return "Mist"; | ||
default: | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <lvgl/lvgl.h> | ||
#include "displayapp/screens/Screen.h" | ||
#include "components/ble/SimpleWeatherService.h" | ||
#include "displayapp/apps/Apps.h" | ||
#include "displayapp/Controllers.h" | ||
#include "Symbols.h" | ||
#include "utility/DirtyValue.h" | ||
|
||
namespace Pinetime { | ||
|
||
namespace Controllers { | ||
class Settings; | ||
} | ||
|
||
namespace Applications { | ||
namespace Screens { | ||
|
||
class Weather : public Screen { | ||
public: | ||
Weather(Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService); | ||
~Weather() override; | ||
|
||
void Refresh() override; | ||
|
||
private: | ||
const char* getCondition(const Pinetime::Controllers::SimpleWeatherService::Icons icon); | ||
Controllers::Settings& settingsController; | ||
Controllers::SimpleWeatherService& weatherService; | ||
|
||
Utility::DirtyValue<std::optional<Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {}; | ||
Utility::DirtyValue<std::optional<Controllers::SimpleWeatherService::Forecast>> currentForecast {}; | ||
|
||
lv_obj_t* condition; | ||
lv_obj_t* icon; | ||
lv_obj_t* temperature; | ||
lv_obj_t* forecast; | ||
lv_obj_t* forecastSym; | ||
|
||
lv_task_t* taskRefresh; | ||
}; | ||
} | ||
|
||
template <> | ||
struct AppTraits<Apps::Weather> { | ||
static constexpr Apps app = Apps::Weather; | ||
static constexpr const char* icon = Screens::Symbols::cloudSun; | ||
|
||
static Screens::Screen* Create(AppControllers& controllers) { | ||
return new Screens::Weather(controllers.settingsController, *controllers.weatherController); | ||
}; | ||
}; | ||
} | ||
} |