WatchFaceDigital: Add weather display
If weather is available, display the cloud icon and temperature.
This commit is contained in:
parent
a6cd3679eb
commit
2135e12b33
|
@ -4,11 +4,13 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "displayapp/screens/NotificationIcon.h"
|
#include "displayapp/screens/NotificationIcon.h"
|
||||||
#include "displayapp/screens/Symbols.h"
|
#include "displayapp/screens/Symbols.h"
|
||||||
|
#include "displayapp/screens/WeatherSymbols.h"
|
||||||
#include "components/battery/BatteryController.h"
|
#include "components/battery/BatteryController.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
#include "components/ble/NotificationManager.h"
|
#include "components/ble/NotificationManager.h"
|
||||||
#include "components/heartrate/HeartRateController.h"
|
#include "components/heartrate/HeartRateController.h"
|
||||||
#include "components/motion/MotionController.h"
|
#include "components/motion/MotionController.h"
|
||||||
|
#include "components/ble/SimpleWeatherService.h"
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
|
|
||||||
using namespace Pinetime::Applications::Screens;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
@ -19,13 +21,15 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
|
||||||
Controllers::NotificationManager& notificationManager,
|
Controllers::NotificationManager& notificationManager,
|
||||||
Controllers::Settings& settingsController,
|
Controllers::Settings& settingsController,
|
||||||
Controllers::HeartRateController& heartRateController,
|
Controllers::HeartRateController& heartRateController,
|
||||||
Controllers::MotionController& motionController)
|
Controllers::MotionController& motionController,
|
||||||
|
Controllers::SimpleWeatherService& weatherService)
|
||||||
: currentDateTime {{}},
|
: currentDateTime {{}},
|
||||||
dateTimeController {dateTimeController},
|
dateTimeController {dateTimeController},
|
||||||
notificationManager {notificationManager},
|
notificationManager {notificationManager},
|
||||||
settingsController {settingsController},
|
settingsController {settingsController},
|
||||||
heartRateController {heartRateController},
|
heartRateController {heartRateController},
|
||||||
motionController {motionController},
|
motionController {motionController},
|
||||||
|
weatherService {weatherService},
|
||||||
statusIcons(batteryController, bleController) {
|
statusIcons(batteryController, bleController) {
|
||||||
|
|
||||||
statusIcons.Create();
|
statusIcons.Create();
|
||||||
|
@ -35,6 +39,18 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
|
||||||
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false));
|
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false));
|
||||||
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||||
|
|
||||||
|
weatherIcon = lv_label_create(lv_scr_act(), nullptr);
|
||||||
|
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
||||||
|
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
|
||||||
|
lv_label_set_text(weatherIcon, "");
|
||||||
|
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_MID, -20, 0);
|
||||||
|
lv_obj_set_auto_realign(weatherIcon, true);
|
||||||
|
|
||||||
|
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_label_set_text(temperature, "");
|
||||||
|
lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 0);
|
||||||
|
|
||||||
label_date = lv_label_create(lv_scr_act(), nullptr);
|
label_date = lv_label_create(lv_scr_act(), nullptr);
|
||||||
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60);
|
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60);
|
||||||
lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
|
lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
|
||||||
|
@ -153,4 +169,25 @@ void WatchFaceDigital::Refresh() {
|
||||||
lv_obj_realign(stepValue);
|
lv_obj_realign(stepValue);
|
||||||
lv_obj_realign(stepIcon);
|
lv_obj_realign(stepIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
|
||||||
|
} else {
|
||||||
|
lv_label_set_text_static(temperature, "");
|
||||||
|
lv_label_set_text(weatherIcon, "");
|
||||||
|
}
|
||||||
|
lv_obj_realign(temperature);
|
||||||
|
lv_obj_realign(weatherIcon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
|
#include "components/ble/SimpleWeatherService.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
#include "displayapp/widgets/StatusIcons.h"
|
#include "displayapp/widgets/StatusIcons.h"
|
||||||
#include "utility/DirtyValue.h"
|
#include "utility/DirtyValue.h"
|
||||||
|
@ -32,7 +33,8 @@ namespace Pinetime {
|
||||||
Controllers::NotificationManager& notificationManager,
|
Controllers::NotificationManager& notificationManager,
|
||||||
Controllers::Settings& settingsController,
|
Controllers::Settings& settingsController,
|
||||||
Controllers::HeartRateController& heartRateController,
|
Controllers::HeartRateController& heartRateController,
|
||||||
Controllers::MotionController& motionController);
|
Controllers::MotionController& motionController,
|
||||||
|
Controllers::SimpleWeatherService& weather);
|
||||||
~WatchFaceDigital() override;
|
~WatchFaceDigital() override;
|
||||||
|
|
||||||
void Refresh() override;
|
void Refresh() override;
|
||||||
|
@ -50,6 +52,8 @@ namespace Pinetime {
|
||||||
Utility::DirtyValue<uint8_t> heartbeat {};
|
Utility::DirtyValue<uint8_t> heartbeat {};
|
||||||
Utility::DirtyValue<bool> heartbeatRunning {};
|
Utility::DirtyValue<bool> heartbeatRunning {};
|
||||||
Utility::DirtyValue<bool> notificationState {};
|
Utility::DirtyValue<bool> notificationState {};
|
||||||
|
Utility::DirtyValue<std::optional<Pinetime::Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {};
|
||||||
|
|
||||||
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
|
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
|
||||||
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
|
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
|
||||||
|
|
||||||
|
@ -61,12 +65,15 @@ namespace Pinetime {
|
||||||
lv_obj_t* stepIcon;
|
lv_obj_t* stepIcon;
|
||||||
lv_obj_t* stepValue;
|
lv_obj_t* stepValue;
|
||||||
lv_obj_t* notificationIcon;
|
lv_obj_t* notificationIcon;
|
||||||
|
lv_obj_t* weatherIcon;
|
||||||
|
lv_obj_t* temperature;
|
||||||
|
|
||||||
Controllers::DateTime& dateTimeController;
|
Controllers::DateTime& dateTimeController;
|
||||||
Controllers::NotificationManager& notificationManager;
|
Controllers::NotificationManager& notificationManager;
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
Controllers::HeartRateController& heartRateController;
|
Controllers::HeartRateController& heartRateController;
|
||||||
Controllers::MotionController& motionController;
|
Controllers::MotionController& motionController;
|
||||||
|
Controllers::SimpleWeatherService& weatherService;
|
||||||
|
|
||||||
lv_task_t* taskRefresh;
|
lv_task_t* taskRefresh;
|
||||||
Widgets::StatusIcons statusIcons;
|
Widgets::StatusIcons statusIcons;
|
||||||
|
@ -85,7 +92,8 @@ namespace Pinetime {
|
||||||
controllers.notificationManager,
|
controllers.notificationManager,
|
||||||
controllers.settingsController,
|
controllers.settingsController,
|
||||||
controllers.heartRateController,
|
controllers.heartRateController,
|
||||||
controllers.motionController);
|
controllers.motionController,
|
||||||
|
*controllers.weatherController);
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
|
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
|
||||||
|
|
Loading…
Reference in a new issue