Skip to content

Commit

Permalink
feat: add option to switch which segment gets replaced with weather
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghoelian committed Nov 25, 2024
1 parent db9e91a commit eb6c362
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 46 deletions.
14 changes: 14 additions & 0 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ namespace Pinetime {
PTSWeather weatherEnable = PTSWeather::Off;
};

enum class CasioWeatherSegment : uint8_t { WeekNumber, DayCounter, DayOfWeek };

struct CasioStyleG7710 {
PTSWeather weatherEnable = PTSWeather::Off;
CasioWeatherSegment weatherSegment = CasioWeatherSegment::DayCounter;
};

struct WatchFaceInfineat {
Expand Down Expand Up @@ -168,6 +171,17 @@ namespace Pinetime {
return settings.casio.weatherEnable;
}

void SetCasioWeatherSegment(CasioWeatherSegment weatherSegment) {
if (weatherSegment != settings.casio.weatherSegment)
settingsChanged = true;

settings.casio.weatherSegment = weatherSegment;
}

CasioWeatherSegment GetCasioWeatherSegment() const {
return settings.casio.weatherSegment;
}

void SetAppMenu(uint8_t menu) {
appMenu = menu;
};
Expand Down
178 changes: 132 additions & 46 deletions src/displayapp/screens/WatchFaceCasioStyleG7710.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,12 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi
lv_obj_set_style_local_text_color(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text);
lv_obj_set_style_local_text_font(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_segment40);
lv_label_set_text_static(label_day_of_year, "181-184");
if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) {
lv_obj_set_hidden(label_day_of_year, true);
} else {
lv_obj_set_hidden(label_day_of_year, false);
}

weatherIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text);
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
lv_label_set_text_static(weatherIcon, "");
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 110, 30);

lv_obj_set_auto_realign(weatherIcon, true);
if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) {
lv_obj_set_hidden(weatherIcon, false);
Expand All @@ -121,13 +116,18 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi

label_temperature = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(label_temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text);
lv_obj_set_style_local_text_font(label_temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_segment40);
lv_label_set_text(label_temperature, "");
lv_obj_align(label_temperature, nullptr, LV_ALIGN_IN_TOP_RIGHT, -5, 30);

label_temperature_segment = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(label_temperature_segment, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text);
lv_obj_set_style_local_text_font(label_temperature_segment, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_segment40);
lv_label_set_text(label_temperature_segment, "");

lv_obj_set_hidden(label_temperature_segment, true);
lv_obj_set_hidden(label_temperature, true);

if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) {
lv_obj_set_hidden(label_temperature, false);
} else {
lv_obj_set_hidden(label_temperature, true);
UpdateWeatherPosition();
}

lv_style_init(&style_line);
Expand Down Expand Up @@ -218,6 +218,16 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi
lv_obj_set_event_cb(btnWeather, event_handler);
lv_obj_set_hidden(btnWeather, true);

btnSegment = lv_btn_create(lv_scr_act(), nullptr);
btnSegment->user_data = this;
lv_obj_set_size(btnSegment, 160, 60);
lv_obj_align(btnSegment, lv_scr_act(), LV_ALIGN_CENTER, 0, 80);
lv_obj_set_style_local_bg_opa(btnSegment, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50);
lv_obj_t* lblSegment = lv_label_create(btnSegment, nullptr);
lv_label_set_text_static(lblSegment, "Segment");
lv_obj_set_event_cb(btnSegment, event_handler);
lv_obj_set_hidden(btnSegment, true);

btnClose = lv_btn_create(lv_scr_act(), nullptr);
btnClose->user_data = this;
lv_obj_set_size(btnClose, 60, 60);
Expand Down Expand Up @@ -372,30 +382,7 @@ void WatchFaceCasioStyleG7710::Refresh() {
}

if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) {
currentWeather = weatherService.Current();

if (currentWeather.IsUpdated()) {
auto optCurrentWeather = currentWeather.Get();

if (optCurrentWeather) {
int16_t temp = optCurrentWeather->temperature.Celsius();
char tempUnit = 'C';

if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
temp = optCurrentWeather->temperature.Fahrenheit();
tempUnit = 'F';
}

lv_label_set_text_fmt(label_temperature, "%d°%c", temp, tempUnit);
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
} else {
lv_label_set_text_static(label_temperature, "");
lv_label_set_text(weatherIcon, "");
}

lv_obj_realign(label_temperature);
lv_obj_realign(weatherIcon);
}
DrawWeather();
}

if (!lv_obj_get_hidden(btnClose)) {
Expand All @@ -406,6 +393,80 @@ void WatchFaceCasioStyleG7710::Refresh() {
}
}

void WatchFaceCasioStyleG7710::UpdateWeatherPosition() {
lv_obj_set_hidden(label_day_of_year, false);
lv_obj_set_hidden(label_week_number, false);
lv_obj_set_hidden(label_day_of_week, false);

lv_obj_set_hidden(weatherIcon, true);
lv_obj_set_hidden(label_temperature_segment, true);
lv_obj_set_hidden(label_temperature, true);

if (settingsController.GetCasioWeather() == Controllers::Settings::PTSWeather::Off) {
return;
}

lv_obj_set_hidden(weatherIcon, false);

switch (settingsController.GetCasioWeatherSegment()) {
case Controllers::Settings::CasioWeatherSegment::DayCounter:
lv_obj_set_hidden(label_day_of_year, true);

lv_obj_set_hidden(label_temperature_segment, false);
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 110, 30);
lv_obj_align(label_temperature_segment, nullptr, LV_ALIGN_IN_TOP_RIGHT, -5, 30);
break;
case Controllers::Settings::CasioWeatherSegment::WeekNumber:
lv_obj_set_hidden(label_week_number, true);

lv_obj_set_hidden(label_temperature, false);
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 35, 15);
lv_label_set_align(label_temperature, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_temperature, nullptr, LV_ALIGN_IN_TOP_LEFT, 20, 40);
break;
case Controllers::Settings::CasioWeatherSegment::DayOfWeek:
lv_obj_set_hidden(label_day_of_week, true);

lv_obj_set_hidden(label_temperature, false);
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 35, 55);
lv_label_set_align(label_temperature, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_temperature, nullptr, LV_ALIGN_IN_TOP_LEFT, 20, 80);
break;
}

DrawWeather();
}

void WatchFaceCasioStyleG7710::DrawWeather() {
currentWeather = weatherService.Current();

if (currentWeather.IsUpdated()) {
auto optCurrentWeather = currentWeather.Get();

if (optCurrentWeather) {
int16_t temp = optCurrentWeather->temperature.Celsius();
char tempUnit = 'C';

if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
temp = optCurrentWeather->temperature.Fahrenheit();
tempUnit = 'F';
}

lv_label_set_text_fmt(label_temperature, "%d°%c", temp, tempUnit);
lv_label_set_text_fmt(label_temperature_segment, "%d°%c", temp, tempUnit);
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
} else {
lv_label_set_text_static(label_temperature, "");
lv_label_set_text_static(label_temperature_segment, "");
lv_label_set_text(weatherIcon, "");
}

lv_obj_realign(label_temperature);
lv_obj_realign(label_temperature_segment);
lv_obj_realign(weatherIcon);
}
}

bool WatchFaceCasioStyleG7710::IsAvailable(Pinetime::Controllers::FS& filesystem) {
lfs_file file = {};

Expand Down Expand Up @@ -433,6 +494,8 @@ bool WatchFaceCasioStyleG7710::OnTouchEvent(Pinetime::Applications::TouchEvents
}
if ((event == Pinetime::Applications::TouchEvents::LongTap) && lv_obj_get_hidden(btnClose)) {
lv_obj_set_hidden(btnWeather, false);
lv_obj_set_hidden(btnSegment, false);

lv_obj_set_hidden(btnClose, false);
savedTick = lv_tick_get();
return true;
Expand All @@ -446,6 +509,8 @@ bool WatchFaceCasioStyleG7710::OnTouchEvent(Pinetime::Applications::TouchEvents
void WatchFaceCasioStyleG7710::CloseMenu() {
settingsController.SaveSettings();
lv_obj_set_hidden(btnWeather, true);
lv_obj_set_hidden(btnSegment, true);

lv_obj_set_hidden(btnClose, true);
}

Expand All @@ -458,21 +523,42 @@ bool WatchFaceCasioStyleG7710::OnButtonPushed() {
return false;
}

void WatchFaceCasioStyleG7710::HandleWeatherButton() {
if (lv_obj_get_hidden(weatherIcon)) {
settingsController.SetCasioWeather(Controllers::Settings::PTSWeather::On);
} else {
settingsController.SetCasioWeather(Controllers::Settings::PTSWeather::Off);
}

UpdateWeatherPosition();
}

void WatchFaceCasioStyleG7710::HandleSegmentButton() {
switch (settingsController.GetCasioWeatherSegment()) {
case Controllers::Settings::CasioWeatherSegment::DayCounter:
settingsController.SetCasioWeatherSegment(Controllers::Settings::CasioWeatherSegment::WeekNumber);
break;
case Controllers::Settings::CasioWeatherSegment::WeekNumber:
settingsController.SetCasioWeatherSegment(Controllers::Settings::CasioWeatherSegment::DayOfWeek);
break;
case Controllers::Settings::CasioWeatherSegment::DayOfWeek:
settingsController.SetCasioWeatherSegment(Controllers::Settings::CasioWeatherSegment::DayCounter);
break;
}

UpdateWeatherPosition();
}

void WatchFaceCasioStyleG7710::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_CLICKED) {
if (object == btnWeather) {
if (lv_obj_get_hidden(weatherIcon)) {
lv_obj_set_hidden(weatherIcon, false);
lv_obj_set_hidden(label_temperature, false);
lv_obj_set_hidden(label_day_of_year, true);
settingsController.SetCasioWeather(Controllers::Settings::PTSWeather::On);
} else {
lv_obj_set_hidden(weatherIcon, true);
lv_obj_set_hidden(label_temperature, true);
lv_obj_set_hidden(label_day_of_year, false);
settingsController.SetCasioWeather(Controllers::Settings::PTSWeather::Off);
}
HandleWeatherButton();
}

if (object == btnSegment) {
HandleSegmentButton();
}

if (object == btnClose) {
CloseMenu();
}
Expand Down
8 changes: 8 additions & 0 deletions src/displayapp/screens/WatchFaceCasioStyleG7710.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ namespace Pinetime {

void Refresh() override;

void UpdateWeatherPosition();
void DrawWeather();

static bool IsAvailable(Pinetime::Controllers::FS& filesystem);

private:
Expand Down Expand Up @@ -95,9 +98,11 @@ namespace Pinetime {
lv_obj_t* notificationIcon;
lv_obj_t* line_icons;
lv_obj_t* btnWeather;
lv_obj_t* btnSegment;
lv_obj_t* btnClose;
lv_obj_t* weatherIcon;
lv_obj_t* label_temperature;
lv_obj_t* label_temperature_segment;

BatteryIcon batteryIcon;

Expand All @@ -114,8 +119,11 @@ namespace Pinetime {
lv_font_t* font_dot40 = nullptr;
lv_font_t* font_segment40 = nullptr;
lv_font_t* font_segment115 = nullptr;
lv_font_t* font_teko_light = nullptr;

void CloseMenu();
void HandleWeatherButton();
void HandleSegmentButton();
};
}

Expand Down

0 comments on commit eb6c362

Please sign in to comment.