Gravel watchface compiles

This commit is contained in:
Josh 2024-05-09 15:52:57 -04:00
parent 5fb1afd200
commit bf66e64021
6 changed files with 76 additions and 66 deletions

View File

@ -17,6 +17,7 @@
#include "displayapp/screens/WatchFaceTerminal.h" #include "displayapp/screens/WatchFaceTerminal.h"
#include "displayapp/screens/WatchFaceHorizon.h" #include "displayapp/screens/WatchFaceHorizon.h"
#include "displayapp/screens/WatchFaceAccurateWords.h" #include "displayapp/screens/WatchFaceAccurateWords.h"
#include "displayapp/screens/WatchFaceGravel.h"
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {

View File

@ -59,6 +59,7 @@ namespace Pinetime {
CasioStyleG7710, CasioStyleG7710,
Horizon, Horizon,
AccurateWords, AccurateWords,
Gravel
}; };
template <Apps> template <Apps>

View File

@ -32,6 +32,7 @@ else()
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::CasioStyleG7710") 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::Horizon")
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::AccurateWords") 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") set(WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}" CACHE STRING "List of watch faces to build into the firmware")
endif() endif()

View File

@ -1,6 +1,5 @@
#include "displayapp/screens/WatchFaceGravel.h" #include "displayapp/screens/WatchFaceGravel.h"
#include <date/date.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include "components/battery/BatteryController.h" #include "components/battery/BatteryController.h"
#include "components/ble/BleController.h" #include "components/ble/BleController.h"
@ -26,18 +25,16 @@ namespace Style {
static constexpr lv_color_t barBackground = LV_COLOR_MAKE(0x38, 0x38, 0x38); static constexpr lv_color_t barBackground = LV_COLOR_MAKE(0x38, 0x38, 0x38);
} }
WatchFaceGravel::WatchFaceGravel(DisplayApp* app, WatchFaceGravel::WatchFaceGravel(Controllers::DateTime& dateTimeController,
Controllers::DateTime& dateTimeController, const Controllers::Battery& batteryController,
Controllers::Battery& batteryController,
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Controllers::MotionController& motionController, Controllers::MotionController& motionController,
Controllers::FS& filesystem) Controllers::FS& filesystem)
: Screen(app), : currentDateTime {{}},
currentDateTime {{}},
dateTimeController {dateTimeController}, dateTimeController {dateTimeController},
batteryController {batteryController}, batteryController {batteryController},
settingsController {settingsController}, settingsController {settingsController},
motionController(motionController) { motionController {motionController} {
lfs_file f = {}; lfs_file f = {};
if (filesystem.FileOpen(&f, "/fonts/SquareRegular_72.bin", LFS_O_RDONLY) >= 0) { if (filesystem.FileOpen(&f, "/fonts/SquareRegular_72.bin", LFS_O_RDONLY) >= 0) {
@ -116,47 +113,36 @@ void WatchFaceGravel::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get(); uint8_t hour = dateTimeController.Hours();
uint8_t minute = dateTimeController.Minutes();
auto dp = date::floor<date::days>(newDateTime);
auto time = date::make_time(newDateTime - dp);
uint8_t hour = time.hours().count(); if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
uint8_t minute = time.minutes().count(); char ampmChar[3] = "AM";
if (hour == 0) {
if (displayedHour != hour || displayedMinute != minute) { hour = 12;
displayedHour = hour; } else if (hour == 12) {
displayedMinute = minute; ampmChar[0] = 'P';
} else if (hour > 12) {
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { hour = hour - 12;
char ampmChar[3] = "AM"; ampmChar[0] = 'P';
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);
} }
lv_label_set_text(labelTimeAMPM, ampmChar);
lv_label_set_text_fmt(labelTime, "%02d:%02d", hour, minute);
lv_obj_align_origo(labelTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
} }
auto yearMonthDay = date::year_month_day(dp); lv_label_set_text_fmt(labelTime, "%02d:%02d", hour, minute);
auto month = static_cast<Pinetime::Controllers::DateTime::Months>(static_cast<unsigned>(yearMonthDay.month())); lv_obj_align_origo(labelTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
auto day = static_cast<unsigned>(yearMonthDay.day());
if ((day != currentDay) || (month != currentMonth)) {
lv_label_set_text_fmt(labelDate, "%d %s", day, Pinetime::Controllers::DateTime::MonthShortToStringLow(month)); currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get());
if (currentDate.IsUpdated()) {
lv_label_set_text_fmt(labelDate, "%d %s", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString());
} }
lv_obj_realign(labelDate); lv_obj_realign(labelDate);
} }
stepCount = motionController.NbSteps(); stepCount = motionController.NbSteps();
motionSensorOk = motionController.IsSensorOk(); if (stepCount.IsUpdated()) {
if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) {
uint16_t pointCount = refreshStepLinePoints(std::min(stepCount.Get(), settingsController.GetStepsGoal())); uint16_t pointCount = refreshStepLinePoints(std::min(stepCount.Get(), settingsController.GetStepsGoal()));
lv_line_set_points(stepLine, stepLinePoints.data(), pointCount); 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) { void WatchFaceGravel::updateBatteryBar(uint8_t percent) {
lv_bar_set_value(batteryBar, percent, LV_ANIM_ON); lv_bar_set_value(batteryBar, percent, LV_ANIM_ON);
if (percent >= 70) { if (percent >= 70) {
@ -188,8 +189,9 @@ void WatchFaceGravel::updateBatteryBar(uint8_t percent) {
} }
} }
void WatchFaceGravel::toggleBatteryChargingAnimation(bool enabled, uint8_t percent) { void WatchFaceGravel::toggleBatteryChargingAnimation(bool, uint8_t) {
if (enabled) { //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_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_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); 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 { } else {
lv_anim_del(batteryBar, (lv_anim_exec_xcb_t) lv_bar_set_value); lv_anim_del(batteryBar, (lv_anim_exec_xcb_t) lv_bar_set_value);
updateBatteryBar(batteryPercentRemaining.Get()); updateBatteryBar(batteryPercentRemaining.Get());
} }*/
} }
WatchFaceGravel::DrawStop WatchFaceGravel::getDrawEnd(float percent, uint16_t width, uint16_t height) { 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; 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;
}

View File

@ -5,9 +5,11 @@
#include <cstdint> #include <cstdint>
#include <lvgl/src/lv_core/lv_obj.h> #include <lvgl/src/lv_core/lv_obj.h>
#include <memory> #include <memory>
#include "displayapp/Controllers.h"
#include "components/ble/BleController.h" #include "components/ble/BleController.h"
#include "components/datetime/DateTimeController.h" #include "components/datetime/DateTimeController.h"
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "utility/DirtyValue.h"
namespace Pinetime { namespace Pinetime {
namespace Controllers { namespace Controllers {
@ -21,12 +23,10 @@ namespace Pinetime {
namespace Applications { namespace Applications {
namespace Screens { namespace Screens {
class WatchFaceGravel : public Screen { class WatchFaceGravel : public Screen {
public: public:
WatchFaceGravel(DisplayApp* app, WatchFaceGravel(Controllers::DateTime& dateTimeController,
Controllers::DateTime& dateTimeController, const Controllers::Battery& batteryController,
Controllers::Battery& batteryController,
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Controllers::MotionController& motionController, Controllers::MotionController& motionController,
Controllers::FS& filesystem); Controllers::FS& filesystem);
@ -43,11 +43,12 @@ namespace Pinetime {
uint8_t currentDay = 0; uint8_t currentDay = 0;
std::array<lv_point_t, 7> stepLinePoints = {0}; std::array<lv_point_t, 7> stepLinePoints = {0};
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
DirtyValue<bool> motionSensorOk {}; Utility::DirtyValue<bool> motionSensorOk {};
DirtyValue<uint32_t> stepCount {}; Utility::DirtyValue<uint32_t> stepCount {};
DirtyValue<uint8_t> batteryPercentRemaining {}; Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
DirtyValue<bool> isCharging {}; Utility::DirtyValue<bool> isCharging {};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
lv_obj_t* labelTime; lv_obj_t* labelTime;
lv_obj_t* labelTimeAMPM; lv_obj_t* labelTimeAMPM;
@ -62,9 +63,9 @@ namespace Pinetime {
lv_font_t* font_SquareRegular20 = nullptr; lv_font_t* font_SquareRegular20 = nullptr;
Controllers::DateTime& dateTimeController; Controllers::DateTime& dateTimeController;
const Controllers::Battery& batteryController;
Controllers::Settings& settingsController; Controllers::Settings& settingsController;
Controllers::MotionController& motionController; Controllers::MotionController& motionController;
Controllers::Battery& batteryController;
lv_task_t* taskRefresh; lv_task_t* taskRefresh;
@ -80,5 +81,23 @@ namespace Pinetime {
void toggleBatteryChargingAnimation(bool enabled, uint8_t percent); void toggleBatteryChargingAnimation(bool enabled, uint8_t percent);
}; };
} }
template <>
struct WatchFaceTraits<WatchFace::Gravel> {
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);
}
};
} }
} }

Binary file not shown.