diff --git a/src/displayapp/UserApps.h b/src/displayapp/UserApps.h index 3f05ebdd..c7a719d8 100644 --- a/src/displayapp/UserApps.h +++ b/src/displayapp/UserApps.h @@ -17,6 +17,7 @@ #include "displayapp/screens/WatchFaceTerminal.h" #include "displayapp/screens/WatchFaceHorizon.h" #include "displayapp/screens/WatchFaceAccurateWords.h" +#include "displayapp/screens/WatchFaceGravel.h" namespace Pinetime { namespace Applications { diff --git a/src/displayapp/apps/Apps.h.in b/src/displayapp/apps/Apps.h.in index c05fb834..8cc34943 100644 --- a/src/displayapp/apps/Apps.h.in +++ b/src/displayapp/apps/Apps.h.in @@ -59,6 +59,7 @@ namespace Pinetime { CasioStyleG7710, Horizon, AccurateWords, + Gravel }; template diff --git a/src/displayapp/apps/CMakeLists.txt b/src/displayapp/apps/CMakeLists.txt index 379605bd..85281926 100644 --- a/src/displayapp/apps/CMakeLists.txt +++ b/src/displayapp/apps/CMakeLists.txt @@ -32,6 +32,7 @@ else() set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::CasioStyleG7710") set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Horizon") set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::AccurateWords") + set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Gravel") set(WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}" CACHE STRING "List of watch faces to build into the firmware") endif() diff --git a/src/displayapp/screens/WatchFaceGravel.cpp b/src/displayapp/screens/WatchFaceGravel.cpp index 05a1c07f..2bb4c47b 100644 --- a/src/displayapp/screens/WatchFaceGravel.cpp +++ b/src/displayapp/screens/WatchFaceGravel.cpp @@ -1,6 +1,5 @@ #include "displayapp/screens/WatchFaceGravel.h" -#include #include #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" @@ -26,18 +25,16 @@ namespace Style { static constexpr lv_color_t barBackground = LV_COLOR_MAKE(0x38, 0x38, 0x38); } -WatchFaceGravel::WatchFaceGravel(DisplayApp* app, - Controllers::DateTime& dateTimeController, - Controllers::Battery& batteryController, +WatchFaceGravel::WatchFaceGravel(Controllers::DateTime& dateTimeController, + const Controllers::Battery& batteryController, Controllers::Settings& settingsController, Controllers::MotionController& motionController, Controllers::FS& filesystem) - : Screen(app), - currentDateTime {{}}, + : currentDateTime {{}}, dateTimeController {dateTimeController}, batteryController {batteryController}, settingsController {settingsController}, - motionController(motionController) { + motionController {motionController} { lfs_file f = {}; if (filesystem.FileOpen(&f, "/fonts/SquareRegular_72.bin", LFS_O_RDONLY) >= 0) { @@ -116,47 +113,36 @@ void WatchFaceGravel::Refresh() { currentDateTime = dateTimeController.CurrentDateTime(); if (currentDateTime.IsUpdated()) { - auto newDateTime = currentDateTime.Get(); + uint8_t hour = dateTimeController.Hours(); + uint8_t minute = dateTimeController.Minutes(); - auto dp = date::floor(newDateTime); - auto time = date::make_time(newDateTime - dp); - uint8_t hour = time.hours().count(); - uint8_t minute = time.minutes().count(); - - if (displayedHour != hour || displayedMinute != minute) { - displayedHour = hour; - displayedMinute = minute; - - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { - char ampmChar[3] = "AM"; - if (hour == 0) { - hour = 12; - } else if (hour == 12) { - ampmChar[0] = 'P'; - } else if (hour > 12) { - hour = hour - 12; - ampmChar[0] = 'P'; - } - lv_label_set_text(labelTimeAMPM, ampmChar); + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { + char ampmChar[3] = "AM"; + if (hour == 0) { + hour = 12; + } else if (hour == 12) { + ampmChar[0] = 'P'; + } else if (hour > 12) { + hour = hour - 12; + ampmChar[0] = 'P'; } - - lv_label_set_text_fmt(labelTime, "%02d:%02d", hour, minute); - lv_obj_align_origo(labelTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + lv_label_set_text(labelTimeAMPM, ampmChar); } - auto yearMonthDay = date::year_month_day(dp); - auto month = static_cast(static_cast(yearMonthDay.month())); - auto day = static_cast(yearMonthDay.day()); - if ((day != currentDay) || (month != currentMonth)) { - lv_label_set_text_fmt(labelDate, "%d %s", day, Pinetime::Controllers::DateTime::MonthShortToStringLow(month)); + lv_label_set_text_fmt(labelTime, "%02d:%02d", hour, minute); + lv_obj_align_origo(labelTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + + + currentDate = std::chrono::time_point_cast(currentDateTime.Get()); + if (currentDate.IsUpdated()) { + lv_label_set_text_fmt(labelDate, "%d %s", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString()); } lv_obj_realign(labelDate); } stepCount = motionController.NbSteps(); - motionSensorOk = motionController.IsSensorOk(); - if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) { + if (stepCount.IsUpdated()) { uint16_t pointCount = refreshStepLinePoints(std::min(stepCount.Get(), settingsController.GetStepsGoal())); lv_line_set_points(stepLine, stepLinePoints.data(), pointCount); } @@ -177,6 +163,21 @@ void WatchFaceGravel::Refresh() { } } +bool WatchFaceGravel::IsAvailable(Pinetime::Controllers::FS& filesystem) { + lfs_file file = {}; + + if (filesystem.FileOpen(&file, "/fonts/SquareRegular_72.bin", LFS_O_RDONLY) < 0) { + return false; + } + filesystem.FileClose(&file); + + if (filesystem.FileOpen(&file, "/fonts/SquareRegular_20.bin", LFS_O_RDONLY) < 0) { + return false; + } + filesystem.FileClose(&file); + return true; +} + void WatchFaceGravel::updateBatteryBar(uint8_t percent) { lv_bar_set_value(batteryBar, percent, LV_ANIM_ON); if (percent >= 70) { @@ -188,8 +189,9 @@ void WatchFaceGravel::updateBatteryBar(uint8_t percent) { } } -void WatchFaceGravel::toggleBatteryChargingAnimation(bool enabled, uint8_t percent) { - if (enabled) { +void WatchFaceGravel::toggleBatteryChargingAnimation(bool, uint8_t) { +//void WatchFaceGravel::toggleBatteryChargingAnimation(bool enabled, uint8_t percent) { + /*if (enabled) { lv_obj_set_style_local_bg_color(batteryBar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, Style::green); lv_anim_del(batteryBar, (lv_anim_exec_xcb_t) lv_bar_set_value); lv_anim_set_exec_cb(&animationBatteryCharging, (lv_anim_exec_xcb_t) lv_bar_set_value); @@ -200,7 +202,8 @@ void WatchFaceGravel::toggleBatteryChargingAnimation(bool enabled, uint8_t perce } else { lv_anim_del(batteryBar, (lv_anim_exec_xcb_t) lv_bar_set_value); updateBatteryBar(batteryPercentRemaining.Get()); - } + }*/ + } WatchFaceGravel::DrawStop WatchFaceGravel::getDrawEnd(float percent, uint16_t width, uint16_t height) { @@ -317,18 +320,3 @@ uint16_t WatchFaceGravel::refreshStepLinePoints(uint32_t stepCount) { return currentPointIndex; } - -bool WatchFaceGravel::IsAvailable(Pinetime::Controllers::FS& filesystem) { - lfs_file file = {}; - - if (filesystem.FileOpen(&file, "/fonts/SquareRegular_72.bin", LFS_O_RDONLY) < 0) { - return false; - } - filesystem.FileClose(&file); - - if (filesystem.FileOpen(&file, "/fonts/SquareRegular_20.bin", LFS_O_RDONLY) < 0) { - return false; - } - filesystem.FileClose(&file); - return true; -} diff --git a/src/displayapp/screens/WatchFaceGravel.h b/src/displayapp/screens/WatchFaceGravel.h index 7faf7fae..480985e4 100644 --- a/src/displayapp/screens/WatchFaceGravel.h +++ b/src/displayapp/screens/WatchFaceGravel.h @@ -5,9 +5,11 @@ #include #include #include +#include "displayapp/Controllers.h" #include "components/ble/BleController.h" #include "components/datetime/DateTimeController.h" #include "displayapp/screens/Screen.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -21,12 +23,10 @@ namespace Pinetime { namespace Applications { namespace Screens { - class WatchFaceGravel : public Screen { public: - WatchFaceGravel(DisplayApp* app, - Controllers::DateTime& dateTimeController, - Controllers::Battery& batteryController, + WatchFaceGravel(Controllers::DateTime& dateTimeController, + const Controllers::Battery& batteryController, Controllers::Settings& settingsController, Controllers::MotionController& motionController, Controllers::FS& filesystem); @@ -43,11 +43,12 @@ namespace Pinetime { uint8_t currentDay = 0; std::array stepLinePoints = {0}; - DirtyValue> currentDateTime {}; - DirtyValue motionSensorOk {}; - DirtyValue stepCount {}; - DirtyValue batteryPercentRemaining {}; - DirtyValue isCharging {}; + Utility::DirtyValue> currentDateTime {}; + Utility::DirtyValue motionSensorOk {}; + Utility::DirtyValue stepCount {}; + Utility::DirtyValue batteryPercentRemaining {}; + Utility::DirtyValue isCharging {}; + Utility::DirtyValue> currentDate; lv_obj_t* labelTime; lv_obj_t* labelTimeAMPM; @@ -62,9 +63,9 @@ namespace Pinetime { lv_font_t* font_SquareRegular20 = nullptr; Controllers::DateTime& dateTimeController; + const Controllers::Battery& batteryController; Controllers::Settings& settingsController; Controllers::MotionController& motionController; - Controllers::Battery& batteryController; lv_task_t* taskRefresh; @@ -80,5 +81,23 @@ namespace Pinetime { void toggleBatteryChargingAnimation(bool enabled, uint8_t percent); }; } + + template <> + struct WatchFaceTraits { + static constexpr WatchFace watchFace = WatchFace::Gravel; + static constexpr const char* name = "Pebble face"; + + static Screens::Screen* Create(AppControllers& controllers) { + return new Screens::WatchFaceGravel(controllers.dateTimeController, + controllers.batteryController, + controllers.settingsController, + controllers.motionController, + controllers.filesystem); + }; + + static bool IsAvailable(Pinetime::Controllers::FS& filesystem) { + return Screens::WatchFaceGravel::IsAvailable(filesystem); + } + }; } } diff --git a/src/resources/fonts/SquareRegular.ttf b/src/resources/fonts/SquareRegular.ttf new file mode 100644 index 00000000..9243923e Binary files /dev/null and b/src/resources/fonts/SquareRegular.ttf differ