Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchface: add weather option to Casio style watchface #2099

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ src/arm-none-eabi

# clangd
.cache/

node_modules/
30 changes: 30 additions & 0 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ 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 {
bool showSideCover = true;
int colorIndex = 0;
Expand Down Expand Up @@ -154,6 +161,27 @@ namespace Pinetime {
return settings.PTS.weatherEnable;
};

void SetCasioWeather(PTSWeather weatherEnable) {
if (weatherEnable != settings.casio.weatherEnable)
settingsChanged = true;
settings.casio.weatherEnable = weatherEnable;
}

PTSWeather GetCasioWeather() const {
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 Expand Up @@ -319,6 +347,8 @@ namespace Pinetime {

PineTimeStyle PTS;

CasioStyleG7710 casio;

WatchFaceInfineat watchFaceInfineat;

std::bitset<5> wakeUpMode {0};
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/apps/Apps.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Pinetime {
PineTimeStyle,
Terminal,
Infineat,
CasioStyleG7710,
CasioStyleG7710
};

template <Apps>
Expand Down
238 changes: 235 additions & 3 deletions src/displayapp/screens/WatchFaceCasioStyleG7710.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,33 @@
#include "displayapp/screens/BleIcon.h"
#include "displayapp/screens/NotificationIcon.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/screens/WeatherSymbols.h"
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "components/heartrate/HeartRateController.h"
#include "components/motion/MotionController.h"
#include "components/settings/Settings.h"
#include "components/ble/SimpleWeatherService.h"

using namespace Pinetime::Applications::Screens;

namespace {
void event_handler(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<WatchFaceCasioStyleG7710*>(obj->user_data);
screen->UpdateSelected(obj, event);
}
}

WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController,
Controllers::FS& filesystem)
Controllers::FS& filesystem,
Controllers::SimpleWeatherService& weatherService)
: currentDateTime {{}},
batteryIcon(false),
dateTimeController {dateTimeController},
Expand All @@ -30,7 +41,8 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi
notificatioManager {notificatioManager},
settingsController {settingsController},
heartRateController {heartRateController},
motionController {motionController} {
motionController {motionController},
weatherService {weatherService} {

lfs_file f = {};
if (filesystem.FileOpen(&f, "/fonts/lv_font_dots_40.bin", LFS_O_RDONLY) >= 0) {
Expand Down Expand Up @@ -90,6 +102,34 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi
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");

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_set_auto_realign(weatherIcon, true);
if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) {
lv_obj_set_hidden(weatherIcon, false);
} else {
lv_obj_set_hidden(weatherIcon, true);
}

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_label_set_text(label_temperature, "");

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) {
UpdateWeatherPosition();
}

lv_style_init(&style_line);
lv_style_set_line_width(&style_line, LV_STATE_DEFAULT, 2);
lv_style_set_line_color(&style_line, LV_STATE_DEFAULT, color_text);
Expand All @@ -116,7 +156,7 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi
lv_obj_align(line_day_of_year, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 60);

label_date = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 100, 70);
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -45, 70);
lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text);
lv_obj_set_style_local_text_font(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_segment40);
lv_label_set_text_static(label_date, "6-30");
Expand Down Expand Up @@ -168,6 +208,36 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi
lv_label_set_text_static(stepIcon, Symbols::shoe);
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);

btnWeather = lv_btn_create(lv_scr_act(), nullptr);
btnWeather->user_data = this;
lv_obj_set_size(btnWeather, 160, 60);
lv_obj_align(btnWeather, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_local_bg_opa(btnWeather, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50);
lv_obj_t* lblWeather = lv_label_create(btnWeather, nullptr);
lv_label_set_text_static(lblWeather, "Weather");
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);
lv_obj_align(btnClose, lv_scr_act(), LV_ALIGN_CENTER, 0, -80);
lv_obj_set_style_local_bg_opa(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50);
lv_obj_t* lblClose = lv_label_create(btnClose, nullptr);
lv_label_set_text_static(lblClose, "X");
lv_obj_set_event_cb(btnClose, event_handler);
lv_obj_set_hidden(btnClose, true);

taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
Refresh();
}
Expand Down Expand Up @@ -310,6 +380,91 @@ void WatchFaceCasioStyleG7710::Refresh() {
lv_obj_realign(stepValue);
lv_obj_realign(stepIcon);
}

if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) {
DrawWeather();
}

if (!lv_obj_get_hidden(btnClose)) {
if ((savedTick > 0) && (lv_tick_get() - savedTick > 3000)) {
CloseMenu();
savedTick = 0;
}
}
}

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, label_day_of_week, LV_ALIGN_CENTER, 0, -50);
lv_label_set_align(label_temperature, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_temperature, label_day_of_week, LV_ALIGN_CENTER, 0, -27);
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, label_day_of_week, LV_ALIGN_CENTER, 0, -12);
lv_label_set_align(label_temperature, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_temperature, label_day_of_week, LV_ALIGN_CENTER, 0, 11);
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) {
Expand All @@ -332,3 +487,80 @@ bool WatchFaceCasioStyleG7710::IsAvailable(Pinetime::Controllers::FS& filesystem
filesystem.FileClose(&file);
return true;
}

bool WatchFaceCasioStyleG7710::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
if (lv_obj_get_hidden(btnClose) == false) {
savedTick = lv_tick_get();
}
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;
}
if ((event == Pinetime::Applications::TouchEvents::DoubleTap) && (lv_obj_get_hidden(btnClose) == false)) {
return true;
}
return false;
}

void WatchFaceCasioStyleG7710::CloseMenu() {
settingsController.SaveSettings();
lv_obj_set_hidden(btnWeather, true);
lv_obj_set_hidden(btnSegment, true);

lv_obj_set_hidden(btnClose, true);
}

bool WatchFaceCasioStyleG7710::OnButtonPushed() {
if (!lv_obj_get_hidden(btnClose)) {
CloseMenu();
return true;
}

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) {
HandleWeatherButton();
}

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

if (object == btnClose) {
CloseMenu();
}
}
}
Loading