Skip to content

Commit

Permalink
WatchFaceAnalog: Add weather widget
Browse files Browse the repository at this point in the history
  • Loading branch information
vkareh committed Mar 18, 2024
1 parent d19a70d commit 8f10997
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
45 changes: 42 additions & 3 deletions src/displayapp/screens/WatchFaceAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "displayapp/screens/BleIcon.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/screens/NotificationIcon.h"
#include "displayapp/screens/WeatherSymbols.h"
#include "components/ble/SimpleWeatherService.h"
#include "components/heartrate/HeartRateController.h"
#include "components/motion/MotionController.h"
#include "components/settings/Settings.h"
Expand Down Expand Up @@ -49,7 +51,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController)
Controllers::MotionController& motionController,
Controllers::SimpleWeatherService& weatherService)
: currentDateTime {{}},
batteryIcon(true),
dateTimeController {dateTimeController},
Expand All @@ -58,7 +61,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
notificationManager {notificationManager},
settingsController {settingsController},
heartRateController {heartRateController},
motionController {motionController} {
motionController {motionController},
weatherService {weatherService} {

sHour = 99;
sMinute = 99;
Expand Down Expand Up @@ -117,13 +121,25 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);

// Date - Day / Week day

label_date_day = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange);
lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day());
lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_date_day, nullptr, LV_ALIGN_CENTER, 50, 0);

if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) {
weatherIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
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_CENTER, -50, -12);

temperature = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
lv_label_set_text(temperature, "");
lv_obj_align(temperature, nullptr, LV_ALIGN_CENTER, -50, 12);
}

minute_body = lv_line_create(lv_scr_act(), nullptr);
minute_body_trace = lv_line_create(lv_scr_act(), nullptr);
hour_body = lv_line_create(lv_scr_act(), nullptr);
Expand Down Expand Up @@ -317,4 +333,27 @@ void WatchFaceAnalog::Refresh() {
lv_obj_realign(stepIcon);
}
}

if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) {
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);
}
}
}
11 changes: 9 additions & 2 deletions src/displayapp/screens/WatchFaceAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "components/ble/SimpleWeatherService.h"
#include "displayapp/screens/BatteryIcon.h"
#include "utility/DirtyValue.h"

Expand All @@ -33,7 +34,8 @@ namespace Pinetime {
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController);
Controllers::MotionController& motionController,
Controllers::SimpleWeatherService& weather);
~WatchFaceAnalog() override;

void Refresh() override;
Expand All @@ -50,6 +52,7 @@ namespace Pinetime {
Utility::DirtyValue<bool> heartbeatRunning {};
Utility::DirtyValue<bool> notificationState {false};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
Utility::DirtyValue<std::optional<Pinetime::Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {};

lv_obj_t* minor_scales;
lv_obj_t* major_scales;
Expand Down Expand Up @@ -83,6 +86,8 @@ namespace Pinetime {
lv_obj_t* heartbeatValue;
lv_obj_t* stepIcon;
lv_obj_t* stepValue;
lv_obj_t* weatherIcon;
lv_obj_t* temperature;

BatteryIcon batteryIcon;

Expand All @@ -93,6 +98,7 @@ namespace Pinetime {
Controllers::Settings& settingsController;
Controllers::HeartRateController& heartRateController;
Controllers::MotionController& motionController;
Controllers::SimpleWeatherService& weatherService;

void UpdateClock();
void SetBatteryIcon();
Expand All @@ -113,7 +119,8 @@ namespace Pinetime {
controllers.notificationManager,
controllers.settingsController,
controllers.heartRateController,
controllers.motionController);
controllers.motionController,
*controllers.weatherController);
};

static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
Expand Down

0 comments on commit 8f10997

Please sign in to comment.