Skip to content

Commit

Permalink
make time font configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart Jahn committed Sep 13, 2023
1 parent e0e8b76 commit 6fdef99
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ namespace Pinetime {
int colorIndex = 0;
};

struct WatchFaceStarTrek {
bool useSystemFont = false;
};

Settings(Pinetime::Controllers::FS& fs);

Settings(const Settings&) = delete;
Expand Down Expand Up @@ -158,6 +162,17 @@ namespace Pinetime {
return settings.PTS.weatherEnable;
};

bool getStarTrekUseSystemFont() const {
return settings.watchFaceStarTrek.useSystemFont;
};

void setStarTrekUseSystemFont(bool useSystemFont) {
if (useSystemFont != settings.watchFaceStarTrek.useSystemFont) {
settings.watchFaceStarTrek.useSystemFont = useSystemFont;
settingsChanged = true;
}
};

void SetAppMenu(uint8_t menu) {
appMenu = menu;
};
Expand Down Expand Up @@ -296,6 +311,8 @@ namespace Pinetime {

WatchFaceInfineat watchFaceInfineat;

WatchFaceStarTrek watchFaceStarTrek;

std::bitset<4> wakeUpMode {0};
uint16_t shakeWakeThreshold = 150;
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
Expand Down
131 changes: 122 additions & 9 deletions src/displayapp/screens/WatchFaceStarTrek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ constexpr lv_color_t COLOR_HEARTBEAT_OFF = COLOR_BLUE;
constexpr lv_color_t COLOR_STEPS = COLOR_BEIGE;
constexpr lv_color_t COLOR_BG = COLOR_BLACK;

// watch out for sizes !
constexpr char WANT_SYSTEM_FONT[12] = "System font";
constexpr char WANT_ST_FONT[15] = "Star Trek font";
constexpr char WANT_ST_FONT_BUT_NO[14] = "Not installed";

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

WatchFaceStarTrek::WatchFaceStarTrek(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Expand All @@ -53,9 +65,16 @@ WatchFaceStarTrek::WatchFaceStarTrek(Controllers::DateTime& dateTimeController,
lfs_file f = {};
if (filesystem.FileOpen(&f, "/fonts/edge_of_the_galaxy.bin", LFS_O_RDONLY) >= 0) {
filesystem.FileClose(&f);
font_time = lv_font_load("F:/fonts/edge_of_the_galaxy.bin");
} else {
starTrekFontAvailable = true;
}
if (settingsController.getStarTrekUseSystemFont()) {
font_time = &jetbrains_mono_extrabold_compressed;
} else {
if (starTrekFontAvailable) {
font_time = lv_font_load("F:/fonts/edge_of_the_galaxy.bin");
} else {
font_time = &jetbrains_mono_extrabold_compressed;
}
}

// definitions of gaps and sizes
Expand Down Expand Up @@ -266,14 +285,37 @@ WatchFaceStarTrek::WatchFaceStarTrek(Controllers::DateTime& dateTimeController,
lv_label_set_text_static(stepValue, "0");
lv_obj_align(stepValue, stepIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);

// menu buttons
btnClose = lv_btn_create(lv_scr_act(), nullptr);
btnClose->user_data = this;
lv_obj_set_size(btnClose, 200, 60);
lv_obj_align(btnClose, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -15);
lv_obj_set_style_local_bg_opa(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_70);
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);

btnSetUseSystemFont = lv_btn_create(lv_scr_act(), nullptr);
btnSetUseSystemFont->user_data = this;
lv_obj_set_size(btnSetUseSystemFont, 200, 60);
lv_obj_align(btnSetUseSystemFont, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 15);
lv_obj_set_style_local_bg_opa(btnSetUseSystemFont, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_70);
const char* label_sysfont =
settingsController.getStarTrekUseSystemFont() ? WANT_SYSTEM_FONT : (starTrekFontAvailable ? WANT_ST_FONT : WANT_ST_FONT_BUT_NO);
lblSetUseSystemFont = lv_label_create(btnSetUseSystemFont, nullptr);
lv_label_set_text_static(lblSetUseSystemFont, label_sysfont);
lv_obj_set_event_cb(btnSetUseSystemFont, event_handler);
lv_obj_set_hidden(btnSetUseSystemFont, true);

taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
Refresh();
}

WatchFaceStarTrek::~WatchFaceStarTrek() {
lv_task_del(taskRefresh);

if (font_time != nullptr) {
if (!settingsController.getStarTrekUseSystemFont() && font_time != nullptr) {
lv_font_free(font_time);
}

Expand Down Expand Up @@ -380,6 +422,14 @@ void WatchFaceStarTrek::Refresh() {
lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get());
lv_obj_realign(stepValue);
}

if (!lv_obj_get_hidden(btnClose)) {
if ((settingsAutoCloseTick > 0) && (lv_tick_get() - settingsAutoCloseTick > 5000)) {
lv_obj_set_hidden(btnClose, true);
lv_obj_set_hidden(btnSetUseSystemFont, true);
settingsAutoCloseTick = 0;
}
}
}

lv_obj_t* WatchFaceStarTrek::rect(uint8_t w, uint8_t h, uint8_t x, uint8_t y, lv_color_t color) {
Expand All @@ -402,13 +452,76 @@ lv_obj_t* WatchFaceStarTrek::_base(uint8_t w, uint8_t h, uint8_t x, uint8_t y, l
return base;
}

bool WatchFaceStarTrek::IsAvailable(Pinetime::Controllers::FS& filesystem) {
lfs_file file = {};
void WatchFaceStarTrek::updateFontTime() {
lv_obj_set_style_local_text_font(label_time_hour_1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_time);
lv_obj_align(label_time_hour_1, hourAnchor, LV_ALIGN_OUT_RIGHT_MID, 2, 0);
lv_obj_set_style_local_text_font(label_time_hour_10, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_time);
lv_obj_align(label_time_hour_10, hourAnchor, LV_ALIGN_OUT_LEFT_MID, -2, 0);
lv_obj_set_style_local_text_font(label_time_min_1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_time);
lv_obj_align(label_time_min_1, minuteAnchor, LV_ALIGN_OUT_RIGHT_MID, 2, 0);
lv_obj_set_style_local_text_font(label_time_min_10, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_time);
lv_obj_align(label_time_min_10, minuteAnchor, LV_ALIGN_OUT_LEFT_MID, -2, 0);
}

bool WatchFaceStarTrek::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
if ((event == Pinetime::Applications::TouchEvents::LongTap) && lv_obj_get_hidden(btnClose)) {
lv_obj_set_hidden(btnClose, false);
lv_obj_set_hidden(btnSetUseSystemFont, false);
settingsAutoCloseTick = lv_tick_get();
return true;
}
if ((event == Pinetime::Applications::TouchEvents::DoubleTap) && (lv_obj_get_hidden(btnClose) == false)) {
return true;
}
return false;
}

if (filesystem.FileOpen(&file, "/fonts/edge_of_the_galaxy.bin", LFS_O_RDONLY) < 0) {
return false;
bool WatchFaceStarTrek::OnButtonPushed() {
if (!lv_obj_get_hidden(btnClose)) {
lv_obj_set_hidden(btnClose, true);
lv_obj_set_hidden(btnSetUseSystemFont, true);
return true;
}
filesystem.FileClose(&file);
return false;
}

void WatchFaceStarTrek::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_CLICKED) {

return true;
settingsAutoCloseTick = lv_tick_get();

if (object == btnClose) {
lv_obj_set_hidden(btnClose, true);
lv_obj_set_hidden(btnSetUseSystemFont, true);
}

if (object == btnSetUseSystemFont) {
bool usedSystem = settingsController.getStarTrekUseSystemFont();
// ST font was not used and shall be used now
if (starTrekFontAvailable && usedSystem) {
lv_label_set_text_static(lblSetUseSystemFont, WANT_ST_FONT);
font_time = lv_font_load("F:/fonts/edge_of_the_galaxy.bin");
// give font time to be loaded, this can possibly be lowered
vTaskDelay(100);
updateFontTime();
usedSystem = false;
}
// ST font was used and gets deactivated
else if (starTrekFontAvailable && !usedSystem) {
lv_label_set_text_static(lblSetUseSystemFont, WANT_SYSTEM_FONT);
if (font_time != nullptr) {
lv_font_free(font_time);
}
font_time = &jetbrains_mono_extrabold_compressed;
updateFontTime();
usedSystem = true;
}
// ST font was not used, shall be used now, but is not available
// ST font should be used by default but is not installed
else {
lv_label_set_text_static(lblSetUseSystemFont, WANT_ST_FONT_BUT_NO);
}
settingsController.setStarTrekUseSystemFont(usedSystem);
}
}
}
13 changes: 11 additions & 2 deletions src/displayapp/screens/WatchFaceStarTrek.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ namespace Pinetime {
Controllers::FS& filesystem);
~WatchFaceStarTrek() override;

void Refresh() override;
bool OnTouchEvent(TouchEvents event) override;
bool OnButtonPushed() override;
void UpdateSelected(lv_obj_t* object, lv_event_t event);

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

private:
uint8_t displayedHour = -1;
Expand All @@ -47,6 +49,7 @@ namespace Pinetime {
Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
uint8_t currentDay = 0;
uint32_t settingsAutoCloseTick = 0;

Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
Utility::DirtyValue<bool> powerPresent {};
Expand Down Expand Up @@ -89,6 +92,10 @@ namespace Pinetime {
lv_obj_t* bracket1[13];
lv_obj_t* bracket2[13];

lv_obj_t* btnClose;
lv_obj_t* btnSetUseSystemFont;
lv_obj_t* lblSetUseSystemFont;

BatteryIcon batteryIcon;

Controllers::DateTime& dateTimeController;
Expand All @@ -104,8 +111,10 @@ namespace Pinetime {
lv_obj_t* rect(uint8_t w, uint8_t h, uint8_t x, uint8_t y, lv_color_t color);
lv_obj_t* circ(uint8_t d, uint8_t x, uint8_t y, lv_color_t color);
lv_obj_t* _base(uint8_t w, uint8_t h, uint8_t x, uint8_t y, lv_color_t color);
void updateFontTime();

lv_font_t* font_time = nullptr;
bool starTrekFontAvailable = false;
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/settings/SettingWatchFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Pinetime {
{"Terminal", true},
{"Infineat face", Applications::Screens::WatchFaceInfineat::IsAvailable(filesystem)},
{"Casio G7710", Applications::Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem)},
{"Star Trek", Applications::Screens::WatchFaceStarTrek::IsAvailable(filesystem)},
{"Star Trek", true},
{"", false}}};
ScreenList<nScreens> screens;
};
Expand Down

0 comments on commit 6fdef99

Please sign in to comment.