From 73b22aaaa4f65d54db6ea4a497f20c5e8094137f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 25 Feb 2024 16:03:35 +0100 Subject: [PATCH 1/5] Code cleaning : remove includes to Apps.h that were not needed. --- src/displayapp/screens/ApplicationList.h | 1 - src/displayapp/screens/CheckboxList.h | 1 - src/displayapp/screens/List.h | 1 - src/displayapp/screens/Tile.h | 1 - 4 files changed, 4 deletions(-) diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h index 41a413af1a..1f74cc1e11 100644 --- a/src/displayapp/screens/ApplicationList.h +++ b/src/displayapp/screens/ApplicationList.h @@ -2,7 +2,6 @@ #include #include -#include "displayapp/apps/Apps.h" #include "Screen.h" #include "ScreenList.h" #include "displayapp/Controllers.h" diff --git a/src/displayapp/screens/CheckboxList.h b/src/displayapp/screens/CheckboxList.h index c6119970a1..7530f72435 100644 --- a/src/displayapp/screens/CheckboxList.h +++ b/src/displayapp/screens/CheckboxList.h @@ -1,6 +1,5 @@ #pragma once -#include "displayapp/apps/Apps.h" #include "displayapp/screens/Screen.h" #include #include diff --git a/src/displayapp/screens/List.h b/src/displayapp/screens/List.h index 17a25f8209..cafd5634ac 100644 --- a/src/displayapp/screens/List.h +++ b/src/displayapp/screens/List.h @@ -5,7 +5,6 @@ #include #include "displayapp/screens/Screen.h" #include "displayapp/widgets/PageIndicator.h" -#include "displayapp/apps/Apps.h" #include "components/settings/Settings.h" #define MAXLISTITEMS 4 diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h index f1b86246ce..deac9a1493 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -4,7 +4,6 @@ #include #include #include "displayapp/screens/Screen.h" -#include "displayapp/apps/Apps.h" #include "components/datetime/DateTimeController.h" #include "components/settings/Settings.h" #include "components/battery/BatteryController.h" From 45f0d9880c8bbd8fd58dd8b487b11ad3286a1c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 25 Feb 2024 16:11:30 +0100 Subject: [PATCH 2/5] Code cleaning : Split displayapp/apps/Apps.h.in into 2 files : Apps.h and WatchFaces.h --- src/components/settings/Settings.h | 1 + src/displayapp/apps/Apps.h.in | 21 -------------- src/displayapp/apps/CMakeLists.txt | 1 + src/displayapp/apps/WatchFaces.h.in | 28 +++++++++++++++++++ src/displayapp/screens/WatchFaceAnalog.h | 2 ++ .../screens/WatchFaceCasioStyleG7710.h | 2 +- src/displayapp/screens/WatchFaceDigital.h | 3 +- src/displayapp/screens/WatchFaceInfineat.h | 2 +- src/displayapp/screens/WatchFaceTerminal.h | 1 + 9 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 src/displayapp/apps/WatchFaces.h.in diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 063120774a..f53cdd74f5 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -4,6 +4,7 @@ #include "components/brightness/BrightnessController.h" #include "components/fs/FS.h" #include "displayapp/apps/Apps.h" +#include "displayapp/apps/WatchFaces.h" namespace Pinetime { namespace Controllers { diff --git a/src/displayapp/apps/Apps.h.in b/src/displayapp/apps/Apps.h.in index 2104a267c0..91d498c8a0 100644 --- a/src/displayapp/apps/Apps.h.in +++ b/src/displayapp/apps/Apps.h.in @@ -45,35 +45,14 @@ namespace Pinetime { Error }; - enum class WatchFace : uint8_t { - Digital, - Analog, - PineTimeStyle, - Terminal, - Infineat, - CasioStyleG7710, - }; - template struct AppTraits {}; - template - struct WatchFaceTraits {}; - template struct TypeList { static constexpr size_t Count = sizeof...(As); }; using UserAppTypes = TypeList<@USERAPP_TYPES@>; - - template - struct WatchFaceTypeList { - static constexpr size_t Count = sizeof...(Ws); - }; - - 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 d78587609e..ec5f36962f 100644 --- a/src/displayapp/apps/CMakeLists.txt +++ b/src/displayapp/apps/CMakeLists.txt @@ -36,3 +36,4 @@ target_include_directories(infinitime_apps INTERFACE "${CMAKE_CURRENT_BINARY_DIR # Generate the list of user apps to be compiled into the firmware configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Apps.h.in ${CMAKE_CURRENT_BINARY_DIR}/Apps.h) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/WatchFaces.h.in ${CMAKE_CURRENT_BINARY_DIR}/WatchFaces.h) diff --git a/src/displayapp/apps/WatchFaces.h.in b/src/displayapp/apps/WatchFaces.h.in new file mode 100644 index 0000000000..60cc61c2a3 --- /dev/null +++ b/src/displayapp/apps/WatchFaces.h.in @@ -0,0 +1,28 @@ +#pragma once +#include +#include + +namespace Pinetime { + namespace Applications { + enum class WatchFace : uint8_t { + Digital, + Analog, + PineTimeStyle, + Terminal, + Infineat, + CasioStyleG7710, + }; + + template + struct WatchFaceTraits {}; + + template + struct WatchFaceTypeList { + static constexpr size_t Count = sizeof...(Ws); + }; + + using UserWatchFaceTypes = WatchFaceTypeList<@WATCHFACE_TYPES@>; + + static_assert(UserWatchFaceTypes::Count >= 1); + } +} diff --git a/src/displayapp/screens/WatchFaceAnalog.h b/src/displayapp/screens/WatchFaceAnalog.h index 89ad4e1346..75f45109aa 100644 --- a/src/displayapp/screens/WatchFaceAnalog.h +++ b/src/displayapp/screens/WatchFaceAnalog.h @@ -11,6 +11,8 @@ #include "components/ble/NotificationManager.h" #include "displayapp/screens/BatteryIcon.h" #include "utility/DirtyValue.h" +#include "displayapp/apps/WatchFaces.h" + namespace Pinetime { namespace Controllers { diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index f10e931ce4..ff8e671590 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -10,7 +10,7 @@ #include "components/datetime/DateTimeController.h" #include "components/ble/BleController.h" #include "utility/DirtyValue.h" -#include "displayapp/apps/Apps.h" +#include "displayapp/apps/WatchFaces.h" namespace Pinetime { namespace Controllers { diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 3ff78c8aec..6b80df6e6f 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -10,7 +10,8 @@ #include "components/ble/BleController.h" #include "displayapp/widgets/StatusIcons.h" #include "utility/DirtyValue.h" -#include "displayapp/apps/Apps.h" +#include "displayapp/apps/WatchFaces.h" + namespace Pinetime { namespace Controllers { diff --git a/src/displayapp/screens/WatchFaceInfineat.h b/src/displayapp/screens/WatchFaceInfineat.h index 32c08f1887..096489e7b8 100644 --- a/src/displayapp/screens/WatchFaceInfineat.h +++ b/src/displayapp/screens/WatchFaceInfineat.h @@ -8,7 +8,7 @@ #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" #include "utility/DirtyValue.h" -#include "displayapp/apps/Apps.h" +#include "displayapp/apps/WatchFaces.h" namespace Pinetime { namespace Controllers { diff --git a/src/displayapp/screens/WatchFaceTerminal.h b/src/displayapp/screens/WatchFaceTerminal.h index ce22005fb9..c96861680a 100644 --- a/src/displayapp/screens/WatchFaceTerminal.h +++ b/src/displayapp/screens/WatchFaceTerminal.h @@ -8,6 +8,7 @@ #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" #include "utility/DirtyValue.h" +#include "displayapp/apps/WatchFaces.h" namespace Pinetime { namespace Controllers { From 7c2ead90548f4519c89671f6a9bc5d626b68816f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Tue, 19 Mar 2024 20:28:45 +0100 Subject: [PATCH 3/5] Watchface : remove the WatchFace enum Watch faces are not identified by their type at build type and their name at runtime --- src/components/settings/Settings.h | 17 +++++--- src/displayapp/DisplayApp.cpp | 5 +-- src/displayapp/UserApps.h | 9 ++-- src/displayapp/apps/CMakeLists.txt | 41 ++++++++++++++----- src/displayapp/apps/WatchFaces.h.in | 14 ++----- src/displayapp/screens/WatchFaceAnalog.h | 4 +- .../screens/WatchFaceCasioStyleG7710.h | 3 +- src/displayapp/screens/WatchFaceDigital.h | 4 +- src/displayapp/screens/WatchFaceInfineat.h | 3 +- .../screens/WatchFacePineTimeStyle.h | 4 +- src/displayapp/screens/WatchFaceTerminal.h | 3 +- .../screens/settings/SettingWatchFace.cpp | 14 +++---- .../screens/settings/SettingWatchFace.h | 2 +- 13 files changed, 68 insertions(+), 55 deletions(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index f53cdd74f5..534a691cc7 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -1,6 +1,8 @@ #pragma once #include #include +#include +#include #include "components/brightness/BrightnessController.h" #include "components/fs/FS.h" #include "displayapp/apps/Apps.h" @@ -61,15 +63,18 @@ namespace Pinetime { void Init(); void SaveSettings(); - void SetWatchFace(Pinetime::Applications::WatchFace face) { - if (face != settings.watchFace) { + void SetWatchFace(const char* face) { + const char* currentWatchFace = settings.watchFace.data(); + if (std::strcmp(face, currentWatchFace) != 0) { settingsChanged = true; + auto len = std::min(std::strlen(face), Pinetime::Applications::MaxWatchFaceNameSize); + std::memcpy(settings.watchFace.data(), face, len); + settings.watchFace[len] = 0; } - settings.watchFace = face; }; - Pinetime::Applications::WatchFace GetWatchFace() const { - return settings.watchFace; + const char* GetWatchFace() const { + return settings.watchFace.data(); }; void SetChimeOption(ChimesOption chimeOption) { @@ -298,7 +303,7 @@ namespace Pinetime { WeatherFormat weatherFormat = WeatherFormat::Metric; Notification notificationStatus = Notification::On; - Pinetime::Applications::WatchFace watchFace = Pinetime::Applications::WatchFace::Digital; + std::array watchFace = {0}; ChimesOption chimesOption = ChimesOption::None; PineTimeStyle PTS; diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index f3f0bd934b..62e8646fb6 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -439,7 +439,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio case Apps::Clock: { const auto* watchFace = std::find_if(userWatchFaces.begin(), userWatchFaces.end(), [this](const WatchFaceDescription& watchfaceDescription) { - return watchfaceDescription.watchFace == settingsController.GetWatchFace(); + return std::strcmp(watchfaceDescription.name, settingsController.GetWatchFace()) == 0; }); if (watchFace != userWatchFaces.end()) currentScreen.reset(watchFace->create(controllers)); @@ -494,8 +494,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio std::array items; int i = 0; for (const auto& userWatchFace : userWatchFaces) { - items[i++] = - Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.watchFace, userWatchFace.isAvailable(controllers.filesystem)}; + items[i++] = Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.isAvailable(controllers.filesystem)}; } currentScreen = std::make_unique(this, std::move(items), settingsController, filesystem); } break; diff --git a/src/displayapp/UserApps.h b/src/displayapp/UserApps.h index 67bbfa7d41..619874612b 100644 --- a/src/displayapp/UserApps.h +++ b/src/displayapp/UserApps.h @@ -28,7 +28,6 @@ namespace Pinetime { }; struct WatchFaceDescription { - WatchFace watchFace; const char* name; Screens::Screen* (*create)(AppControllers& controllers); bool (*isAvailable)(Controllers::FS& fileSystem); @@ -39,9 +38,11 @@ namespace Pinetime { return {AppTraits::app, AppTraits::icon, &AppTraits::Create}; } - template + template consteval WatchFaceDescription CreateWatchFaceDescription() { - return {WatchFaceTraits::watchFace, WatchFaceTraits::name, &WatchFaceTraits::Create, &WatchFaceTraits::IsAvailable}; + static_assert(std::char_traits::length(WatchFaceTraits::name) < 16, + "The name of the watch faces is limited to 15 characters max"); + return {WatchFaceTraits::name, &WatchFaceTraits::Create, &WatchFaceTraits::IsAvailable}; } template