Author: Jean-François Milants <jf@codingfield.com>
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.
src/displayapp/DisplayApp.cpp | 5 + src/displayapp/apps/Apps.h.in | 7 -- src/displayapp/apps/CMakeLists.txt | 6 ++ src/displayapp/screens/settings/SettingWatchFace.cpp | 42 ++++++++++++- src/displayapp/screens/settings/SettingWatchFace.h | 10 ++
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 2792009f05cb59ed40b23efdc309f60012463c50..938d1179a8dd225ff87e4a93e6f0ab4c29bbc384 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -489,10 +489,11 @@ case Apps::Settings: currentScreen = std::make_unique<Screens::Settings>(this, settingsController); break; case Apps::SettingWatchFace: { - std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count> items; + std::array<Screens::SettingWatchFace::Item, UserWatchFaceTypes::Count> items; int i = 0; for (const auto& userWatchFace : userWatchFaces) { - items[i++] = Screens::CheckboxList::Item {userWatchFace.name, userWatchFace.isAvailable(controllers.filesystem)}; + items[i++] = + Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.watchFace, userWatchFace.isAvailable(controllers.filesystem)}; } currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem); } break; diff --git a/src/displayapp/apps/Apps.h.in b/src/displayapp/apps/Apps.h.in index 11fe17b57535aede586258d07489c33acef18fb7..e6e8d7dcd98d5964598b8d9aa07135362dc428e9 100644 --- a/src/displayapp/apps/Apps.h.in +++ b/src/displayapp/apps/Apps.h.in @@ -71,12 +71,7 @@ struct WatchFaceTypeList { static constexpr size_t Count = sizeof...(Ws); }; - using UserWatchFaceTypes = WatchFaceTypeList<WatchFace::Digital, - WatchFace::Analog, - WatchFace::PineTimeStyle, - WatchFace::Terminal, - WatchFace::Infineat, - WatchFace::CasioStyleG7710>; + using UserWatchFaceTypes = WatchFaceTypeList<@WATCHFACE_TYPES@>; static_assert(UserWatchFaceTypes::Count >= 1); } diff --git a/src/displayapp/apps/CMakeLists.txt b/src/displayapp/apps/CMakeLists.txt index 3544443a9fb2ad6379f64f104ed7e31d29669c06..4f0e4c4953994c4af3c3ab620e08d5f24f13a7fb 100644 --- a/src/displayapp/apps/CMakeLists.txt +++ b/src/displayapp/apps/CMakeLists.txt @@ -17,6 +17,12 @@ #set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion") set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware") endif () +if(DEFINED ENABLE_WATCHFACES) + set(WATCHFACE_TYPES ${ENABLE_WATCHFACES} CACHE STRING "List of watch faces to build into the firmware") +else() + 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") +endif() + add_library(infinitime_apps INTERFACE) target_sources(infinitime_apps INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/Apps.h") target_include_directories(infinitime_apps INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/") diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index f052573c366b935395fe841105bdf86cefb1506b..e01e9f847d673e7be8676fa704ee55f9491f227c 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -9,6 +9,37 @@ constexpr const char* SettingWatchFace::title; constexpr const char* SettingWatchFace::symbol; +namespace { + uint32_t IndexOf(const std::array<Pinetime::Applications::Screens::SettingWatchFace::Item, + Pinetime::Applications::UserWatchFaceTypes::Count>& watchfaces, + Pinetime::Applications::WatchFace watchface) { + size_t index = 0; + auto found = std::find_if(watchfaces.begin(), + watchfaces.end(), + [&index, &watchface](const Pinetime::Applications::Screens::SettingWatchFace::Item& item) { + const bool result = item.watchface == watchface; + if (!result) { + index++; + } + return result; + }); + if (found == watchfaces.end()) { + index = 0; + } + + return index; + } + + Pinetime::Applications::WatchFace IndexToWatchFace(const std::array<Pinetime::Applications::Screens::SettingWatchFace::Item, + Pinetime::Applications::UserWatchFaceTypes::Count>& watchfaces, + size_t index) { + if (index >= watchfaces.size()) { + return watchfaces[0].watchface; + } + return watchfaces[index].watchface; + } +} + auto SettingWatchFace::CreateScreenList() const { std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens; for (size_t i = 0; i < screens.size(); i++) { @@ -20,7 +51,7 @@ return screens; } SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, - std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count>&& watchfaceItems, + std::array<Screens::SettingWatchFace::Item, UserWatchFaceTypes::Count>&& watchfaceItems, Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::FS& filesystem) : app {app}, @@ -44,7 +75,8 @@ for (int i = 0; i < settingsPerScreen; i++) { if (i + (screenNum * settingsPerScreen) >= watchfaceItems.size()) { watchfacesOnThisScreen[i] = {"", false}; } else { - watchfacesOnThisScreen[i] = watchfaceItems[i + (screenNum * settingsPerScreen)]; + auto& item = watchfaceItems[i + (screenNum * settingsPerScreen)]; + watchfacesOnThisScreen[i] = Screens::CheckboxList::Item {item.name, item.enabled}; } } @@ -53,9 +85,9 @@ screenNum, nScreens, title, symbol, - static_cast<uint32_t>(settingsController.GetWatchFace()), - [&settings = settingsController](uint32_t index) { - settings.SetWatchFace(static_cast<WatchFace>(index)); + static_cast<uint32_t>(IndexOf(watchfaceItems, settingsController.GetWatchFace())), + [this, &settings = settingsController](uint32_t index) { + settings.SetWatchFace(IndexToWatchFace(watchfaceItems, index)); settings.SaveSettings(); }, watchfacesOnThisScreen); diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index 66559c73cbbde25b40c0c2e0fcd3fe8140fcbb39..4c75b0ab21b58c760e71d8f6133a2743a5cc41ae 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -19,8 +19,14 @@ namespace Screens { class SettingWatchFace : public Screen { public: + struct Item { + const char* name; + WatchFace watchface; + bool enabled; + }; + SettingWatchFace(DisplayApp* app, - std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count>&& watchfaceItems, + std::array<Item, UserWatchFaceTypes::Count>&& watchfaceItems, Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::FS& filesystem); ~SettingWatchFace() override; @@ -33,7 +39,7 @@ auto CreateScreenList() const; std::unique_ptr<Screen> CreateScreen(unsigned int screenNum) const; static constexpr int settingsPerScreen = 4; - std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count> watchfaceItems; + std::array<Item, UserWatchFaceTypes::Count> watchfaceItems; static constexpr int nScreens = UserWatchFaceTypes::Count > 0 ? (UserWatchFaceTypes ::Count - 1) / settingsPerScreen + 1 : 1; Controllers::Settings& settingsController;