summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2022-10-11 21:36:31 +0200
committerJean-François Milants <jf@codingfield.com>2022-10-11 21:36:31 +0200
commiteb0af22ecf66957b9341521990c49a6d1d5d70e3 (patch)
tree269d1925185cd8d10cd39eb86f23c1170e40548e
parent8c7be1fbb1d172ffc5cf99ec2b013f11f35dc421 (diff)
Watch face settings : disable watch faces that are not available (external resources are not installed).
-rw-r--r--src/displayapp/DisplayApp.cpp2
-rw-r--r--src/displayapp/screens/CheckboxList.cpp14
-rw-r--r--src/displayapp/screens/CheckboxList.h9
-rw-r--r--src/displayapp/screens/WatchFaceCasioStyleG7710.cpp17
-rw-r--r--src/displayapp/screens/WatchFaceCasioStyleG7710.h2
-rw-r--r--src/displayapp/screens/WatchFaceInfineat.cpp18
-rw-r--r--src/displayapp/screens/WatchFaceInfineat.h2
-rw-r--r--src/displayapp/screens/settings/SettingWatchFace.cpp16
-rw-r--r--src/displayapp/screens/settings/SettingWatchFace.h3
9 files changed, 72 insertions, 11 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 4afcd8dc..108e380d 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -390,7 +390,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingWatchFace:
- currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController);
+ currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController, filesystem);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingTimeFormat:
diff --git a/src/displayapp/screens/CheckboxList.cpp b/src/displayapp/screens/CheckboxList.cpp
index d97726dd..5889c69a 100644
--- a/src/displayapp/screens/CheckboxList.cpp
+++ b/src/displayapp/screens/CheckboxList.cpp
@@ -18,7 +18,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
const char* optionsSymbol,
uint32_t originalValue,
std::function<void(uint32_t)> OnValueChanged,
- std::array<const char*, MaxItems> options)
+ std::array<Item, MaxItems> options)
: Screen(app), screenID {screenID}, OnValueChanged {std::move(OnValueChanged)}, options {options}, value {originalValue} {
// Set the background to Black
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
@@ -72,9 +72,12 @@ CheckboxList::CheckboxList(const uint8_t screenID,
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
for (unsigned int i = 0; i < options.size(); i++) {
- if (strcmp(options[i], "")) {
+ if (strcmp(options[i].name, "")) {
cbOption[i] = lv_checkbox_create(container1, nullptr);
- lv_checkbox_set_text(cbOption[i], options[i]);
+ lv_checkbox_set_text(cbOption[i], options[i].name);
+ if (!options[i].enabled) {
+ lv_checkbox_set_disabled(cbOption[i]);
+ }
cbOption[i]->user_data = this;
lv_obj_set_event_cb(cbOption[i], event_handler);
SetRadioButtonStyle(cbOption[i]);
@@ -94,13 +97,16 @@ CheckboxList::~CheckboxList() {
void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
for (unsigned int i = 0; i < options.size(); i++) {
- if (strcmp(options[i], "")) {
+ if (strcmp(options[i].name, "")) {
if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true);
value = MaxItems * screenID + i;
} else {
lv_checkbox_set_checked(cbOption[i], false);
}
+ if (!options[i].enabled) {
+ lv_checkbox_set_disabled(cbOption[i]);
+ }
}
}
}
diff --git a/src/displayapp/screens/CheckboxList.h b/src/displayapp/screens/CheckboxList.h
index f9c3bae0..e9104bfb 100644
--- a/src/displayapp/screens/CheckboxList.h
+++ b/src/displayapp/screens/CheckboxList.h
@@ -14,6 +14,11 @@ namespace Pinetime {
class CheckboxList : public Screen {
public:
static constexpr size_t MaxItems = 4;
+ struct Item {
+ const char* name;
+ bool enabled;
+ };
+
CheckboxList(const uint8_t screenID,
const uint8_t numScreens,
DisplayApp* app,
@@ -21,14 +26,14 @@ namespace Pinetime {
const char* optionsSymbol,
uint32_t originalValue,
std::function<void(uint32_t)> OnValueChanged,
- std::array<const char*, MaxItems> options);
+ std::array<Item, MaxItems> options);
~CheckboxList() override;
void UpdateSelected(lv_obj_t* object, lv_event_t event);
private:
const uint8_t screenID;
std::function<void(uint32_t)> OnValueChanged;
- std::array<const char*, MaxItems> options;
+ std::array<Item, MaxItems> options;
std::array<lv_obj_t*, MaxItems> cbOption;
std::array<lv_point_t, 2> pageIndicatorBasePoints;
std::array<lv_point_t, 2> pageIndicatorPoints;
diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp
index f9a01abd..525c2eeb 100644
--- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp
+++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp
@@ -333,3 +333,20 @@ void WatchFaceCasioStyleG7710::Refresh() {
lv_obj_realign(stepIcon);
}
}
+bool WatchFaceCasioStyleG7710::IsAvailable(Pinetime::Controllers::FS& filesystem) {
+ lfs_file file = {};
+
+ if (filesystem.FileOpen(&file, "/fonts/lv_font_dots_40.bin", LFS_O_RDONLY) < 0) {
+ return false;
+ }
+
+ if (filesystem.FileOpen(&file, "/fonts/7segments_40.bin", LFS_O_RDONLY) < 0) {
+ return false;
+ }
+
+ if (filesystem.FileOpen(&file, "/fonts/7segments_115.bin", LFS_O_RDONLY) < 0) {
+ return false;
+ }
+
+ return true;
+}
diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h
index c3821205..eb7bb9e8 100644
--- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h
+++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h
@@ -37,6 +37,8 @@ namespace Pinetime {
void Refresh() override;
+ static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
+
private:
uint8_t displayedHour = -1;
uint8_t displayedMinute = -1;
diff --git a/src/displayapp/screens/WatchFaceInfineat.cpp b/src/displayapp/screens/WatchFaceInfineat.cpp
index 5822a1e8..01b425da 100644
--- a/src/displayapp/screens/WatchFaceInfineat.cpp
+++ b/src/displayapp/screens/WatchFaceInfineat.cpp
@@ -609,3 +609,21 @@ void WatchFaceInfineat::ToggleBatteryIndicatorColor(bool showSideCover) {
lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex() * nLines + 7]));
}
}
+
+bool WatchFaceInfineat::IsAvailable(Pinetime::Controllers::FS& filesystem) {
+ lfs_file file = {};
+
+ if (filesystem.FileOpen(&file, "/fonts/teko.bin", LFS_O_RDONLY) < 0) {
+ return false;
+ }
+
+ if (filesystem.FileOpen(&file, "/fonts/bebas.bin", LFS_O_RDONLY) < 0) {
+ return false;
+ }
+
+ if (filesystem.FileOpen(&file, "/images/pine_small.bin", LFS_O_RDONLY) < 0) {
+ return false;
+ }
+
+ return true;
+}
diff --git a/src/displayapp/screens/WatchFaceInfineat.h b/src/displayapp/screens/WatchFaceInfineat.h
index 285908e8..6c3c30ba 100644
--- a/src/displayapp/screens/WatchFaceInfineat.h
+++ b/src/displayapp/screens/WatchFaceInfineat.h
@@ -39,6 +39,8 @@ namespace Pinetime {
void Refresh() override;
+ static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
+
private:
char displayedChar[5] {};
diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp
index 6d47f3a5..217f97b8 100644
--- a/src/displayapp/screens/settings/SettingWatchFace.cpp
+++ b/src/displayapp/screens/settings/SettingWatchFace.cpp
@@ -4,15 +4,20 @@
#include "displayapp/screens/CheckboxList.h"
#include "displayapp/screens/Screen.h"
#include "components/settings/Settings.h"
+#include "displayapp/screens/WatchFaceInfineat.h"
+#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
using namespace Pinetime::Applications::Screens;
constexpr const char* SettingWatchFace::title;
constexpr const char* SettingWatchFace::symbol;
-SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
+SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app,
+ Pinetime::Controllers::Settings& settingsController,
+ Pinetime::Controllers::FS& filesystem)
: Screen(app),
settingsController {settingsController},
+ filesystem {filesystem},
screens {app,
0,
{[this]() -> std::unique_ptr<Screen> {
@@ -33,7 +38,8 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
}
std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
- std::array<const char*, 4> watchfaces {"Digital face", "Analog face", "PineTimeStyle", "Terminal"};
+ std::array<Screens::CheckboxList::Item, 4> watchfaces {
+ {{"Digital face", true}, {"Analog face", true}, {"PineTimeStyle", true}, {"Terminal", true}}};
return std::make_unique<Screens::CheckboxList>(
0,
2,
@@ -49,7 +55,11 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
}
std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
- std::array<const char*, 4> watchfaces {"Infineat face", "Casio G7710", "", ""};
+ std::array<Screens::CheckboxList::Item, 4> watchfaces {
+ {{"Infineat face", Applications::Screens::WatchFaceInfineat::IsAvailable(filesystem)},
+ {"Casio G7710", Applications::Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem)},
+ {"", false},
+ {"", false}}};
return std::make_unique<Screens::CheckboxList>(
1,
2,
diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h
index 7d14554e..158397f8 100644
--- a/src/displayapp/screens/settings/SettingWatchFace.h
+++ b/src/displayapp/screens/settings/SettingWatchFace.h
@@ -16,13 +16,14 @@ namespace Pinetime {
class SettingWatchFace : public Screen {
public:
- SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
+ SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::FS& filesystem);
~SettingWatchFace() override;
bool OnTouchEvent(TouchEvents event) override;
private:
Controllers::Settings& settingsController;
+ Pinetime::Controllers::FS& filesystem;
ScreenList<2> screens;
static constexpr const char* title = "Watch face";