Skip to content

Commit 22f6d4a

Browse files
committed
Watch face selection using CMake
The list of watch face to build into the firmware is now set by CMake (-DENABLE_WATCHFACES). Fix SettingWatchFace : convert to index to/from WatchFace when needed.
1 parent 12acef6 commit 22f6d4a

File tree

5 files changed

+55
-15
lines changed

5 files changed

+55
-15
lines changed

src/displayapp/DisplayApp.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,11 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
489489
currentScreen = std::make_unique<Screens::Settings>(this, settingsController);
490490
break;
491491
case Apps::SettingWatchFace: {
492-
std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count> items;
492+
std::array<Screens::SettingWatchFace::Item, UserWatchFaceTypes::Count> items;
493493
int i = 0;
494494
for (const auto& userWatchFace : userWatchFaces) {
495-
items[i++] = Screens::CheckboxList::Item {userWatchFace.name, userWatchFace.isAvailable(controllers.filesystem)};
495+
items[i++] =
496+
Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.watchFace, userWatchFace.isAvailable(controllers.filesystem)};
496497
}
497498
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem);
498499
} break;

src/displayapp/apps/Apps.h.in

+1-6
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ namespace Pinetime {
7171
static constexpr size_t Count = sizeof...(Ws);
7272
};
7373

74-
using UserWatchFaceTypes = WatchFaceTypeList<WatchFace::Digital,
75-
WatchFace::Analog,
76-
WatchFace::PineTimeStyle,
77-
WatchFace::Terminal,
78-
WatchFace::Infineat,
79-
WatchFace::CasioStyleG7710>;
74+
using UserWatchFaceTypes = WatchFaceTypeList<@WATCHFACE_TYPES@>;
8075

8176
static_assert(UserWatchFaceTypes::Count >= 1);
8277
}

src/displayapp/apps/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ else ()
1717
set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware")
1818
endif ()
1919

20+
if(DEFINED ENABLE_WATCHFACES)
21+
set(WATCHFACE_TYPES ${ENABLE_WATCHFACES} CACHE STRING "List of watch faces to build into the firmware")
22+
else()
23+
set(WATCHFACE_TYPES "WatchFace::Digital, WatchFace::Analog, WatchFace::PineTimeStyle, WatchFace::Terminal, WatchFace::Infineat, WatchFace::CasioStyleG7710" CACHE STRING "List of watch faces to build into the firmware")
24+
endif()
25+
2026
add_library(infinitime_apps INTERFACE)
2127
target_sources(infinitime_apps INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/Apps.h")
2228
target_include_directories(infinitime_apps INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/")

src/displayapp/screens/settings/SettingWatchFace.cpp

+37-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ using namespace Pinetime::Applications::Screens;
99
constexpr const char* SettingWatchFace::title;
1010
constexpr const char* SettingWatchFace::symbol;
1111

12+
namespace {
13+
uint32_t IndexOf(const std::array<Pinetime::Applications::Screens::SettingWatchFace::Item,
14+
Pinetime::Applications::UserWatchFaceTypes::Count>& watchfaces,
15+
Pinetime::Applications::WatchFace watchface) {
16+
size_t index = 0;
17+
auto found = std::find_if(watchfaces.begin(),
18+
watchfaces.end(),
19+
[&index, &watchface](const Pinetime::Applications::Screens::SettingWatchFace::Item& item) {
20+
const bool result = item.watchface == watchface;
21+
if (!result) {
22+
index++;
23+
}
24+
return result;
25+
});
26+
if (found == watchfaces.end()) {
27+
index = 0;
28+
}
29+
30+
return index;
31+
}
32+
33+
Pinetime::Applications::WatchFace IndexToWatchFace(const std::array<Pinetime::Applications::Screens::SettingWatchFace::Item,
34+
Pinetime::Applications::UserWatchFaceTypes::Count>& watchfaces,
35+
size_t index) {
36+
if (index >= watchfaces.size()) {
37+
return watchfaces[0].watchface;
38+
}
39+
return watchfaces[index].watchface;
40+
}
41+
}
42+
1243
auto SettingWatchFace::CreateScreenList() const {
1344
std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens;
1445
for (size_t i = 0; i < screens.size(); i++) {
@@ -20,7 +51,7 @@ auto SettingWatchFace::CreateScreenList() const {
2051
}
2152

2253
SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app,
23-
std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count>&& watchfaceItems,
54+
std::array<Screens::SettingWatchFace::Item, UserWatchFaceTypes::Count>&& watchfaceItems,
2455
Pinetime::Controllers::Settings& settingsController,
2556
Pinetime::Controllers::FS& filesystem)
2657
: app {app},
@@ -44,7 +75,8 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen(unsigned int screenNum) c
4475
if (i + (screenNum * settingsPerScreen) >= watchfaceItems.size()) {
4576
watchfacesOnThisScreen[i] = {"", false};
4677
} else {
47-
watchfacesOnThisScreen[i] = watchfaceItems[i + (screenNum * settingsPerScreen)];
78+
auto& item = watchfaceItems[i + (screenNum * settingsPerScreen)];
79+
watchfacesOnThisScreen[i] = Screens::CheckboxList::Item {item.name, item.enabled};
4880
}
4981
}
5082

@@ -53,9 +85,9 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen(unsigned int screenNum) c
5385
nScreens,
5486
title,
5587
symbol,
56-
static_cast<uint32_t>(settingsController.GetWatchFace()),
57-
[&settings = settingsController](uint32_t index) {
58-
settings.SetWatchFace(static_cast<WatchFace>(index));
88+
static_cast<uint32_t>(IndexOf(watchfaceItems, settingsController.GetWatchFace())),
89+
[this, &settings = settingsController](uint32_t index) {
90+
settings.SetWatchFace(IndexToWatchFace(watchfaceItems, index));
5991
settings.SaveSettings();
6092
},
6193
watchfacesOnThisScreen);

src/displayapp/screens/settings/SettingWatchFace.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ namespace Pinetime {
1919

2020
class SettingWatchFace : public Screen {
2121
public:
22+
struct Item {
23+
const char* name;
24+
WatchFace watchface;
25+
bool enabled;
26+
};
27+
2228
SettingWatchFace(DisplayApp* app,
23-
std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count>&& watchfaceItems,
29+
std::array<Item, UserWatchFaceTypes::Count>&& watchfaceItems,
2430
Pinetime::Controllers::Settings& settingsController,
2531
Pinetime::Controllers::FS& filesystem);
2632
~SettingWatchFace() override;
@@ -33,7 +39,7 @@ namespace Pinetime {
3339
std::unique_ptr<Screen> CreateScreen(unsigned int screenNum) const;
3440

3541
static constexpr int settingsPerScreen = 4;
36-
std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count> watchfaceItems;
42+
std::array<Item, UserWatchFaceTypes::Count> watchfaceItems;
3743
static constexpr int nScreens = UserWatchFaceTypes::Count > 0 ? (UserWatchFaceTypes ::Count - 1) / settingsPerScreen + 1 : 1;
3844

3945
Controllers::Settings& settingsController;

0 commit comments

Comments
 (0)