Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch face selection at build time #1926

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ list(APPEND SOURCE_FILES
logging/NrfLogger.cpp
displayapp/DisplayApp.cpp
displayapp/screens/Screen.cpp
displayapp/screens/Clock.cpp
displayapp/screens/Tile.cpp
displayapp/screens/InfiniPaint.cpp
displayapp/screens/Paddle.cpp
Expand Down Expand Up @@ -597,7 +596,6 @@ set(INCLUDE_FILES
displayapp/Messages.h
displayapp/TouchEvents.h
displayapp/screens/Screen.h
displayapp/screens/Clock.h
displayapp/screens/Tile.h
displayapp/screens/InfiniPaint.h
displayapp/screens/StopWatch.h
Expand All @@ -613,7 +611,6 @@ set(INCLUDE_FILES
displayapp/screens/ApplicationList.h
displayapp/screens/CheckboxList.h
displayapp/Apps.h
displayapp/WatchFaces.h
displayapp/screens/Notifications.h
displayapp/screens/HeartRate.h
displayapp/screens/Metronome.h
Expand Down
2 changes: 1 addition & 1 deletion src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <bitset>
#include "components/brightness/BrightnessController.h"
#include "components/fs/FS.h"
#include "displayapp/WatchFaces.h"
#include "displayapp/Apps.h"

namespace Pinetime {
namespace Controllers {
Expand Down
29 changes: 28 additions & 1 deletion src/displayapp/Apps.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once
#include <cstddef>
#include <cstdint>

namespace Pinetime {
namespace Applications {
enum class Apps {
enum class Apps : uint8_t {
None,
Launcher,
Clock,
Expand Down Expand Up @@ -42,14 +43,31 @@ namespace Pinetime {
Weather
};

enum class WatchFace : uint8_t {
Digital = 0,
Analog = 1,
PineTimeStyle = 2,
Terminal = 3,
Infineat = 4,
CasioStyleG7710 = 5,
FintasticMan marked this conversation as resolved.
Show resolved Hide resolved
};

template <Apps>
struct AppTraits {};

template <WatchFace>
struct WatchFaceTraits {};

template <Apps... As>
struct TypeList {
static constexpr size_t Count = sizeof...(As);
};

template <WatchFace... Ws>
struct WatchFaceTypeList {
static constexpr size_t Count = sizeof...(Ws);
};

using UserAppTypes = TypeList<Apps::StopWatch,
Apps::Alarm,
Apps::Timer,
Expand All @@ -66,5 +84,14 @@ namespace Pinetime {
Apps::Motion
*/
>;

using UserWatchFaceTypes = WatchFaceTypeList<WatchFace::Digital,
WatchFace::Analog,
WatchFace::PineTimeStyle,
WatchFace::Terminal,
WatchFace::Infineat,
WatchFace::CasioStyleG7710>;

static_assert(UserWatchFaceTypes::Count >= 1);
}
}
48 changes: 22 additions & 26 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "components/motion/MotionController.h"
#include "components/motor/MotorController.h"
#include "displayapp/screens/ApplicationList.h"
#include "displayapp/screens/Clock.h"
#include "displayapp/screens/FirmwareUpdate.h"
#include "displayapp/screens/FirmwareValidation.h"
#include "displayapp/screens/InfiniPaint.h"
Expand Down Expand Up @@ -435,17 +434,17 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
filesystem,
std::move(apps));
} break;
case Apps::Clock:
currentScreen = std::make_unique<Screens::Clock>(dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController,
heartRateController,
motionController,
systemTask->nimble().weather(),
filesystem);
break;
case Apps::Clock: {
const auto* watchFace =
std::find_if(userWatchFaces.begin(), userWatchFaces.end(), [this](const WatchFaceDescription& watchfaceDescription) {
return watchfaceDescription.watchFace == settingsController.GetWatchFace();
});
if (watchFace != userWatchFaces.end())
currentScreen.reset(watchFace->create(controllers));
else {
currentScreen.reset(userWatchFaces[0].create(controllers));
}
} break;
case Apps::Error:
currentScreen = std::make_unique<Screens::Error>(bootError);
break;
Expand Down Expand Up @@ -489,9 +488,14 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::Settings:
currentScreen = std::make_unique<Screens::Settings>(this, settingsController);
break;
case Apps::SettingWatchFace:
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController, filesystem);
break;
case Apps::SettingWatchFace: {
std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count> items;
int i = 0;
for (const auto& userWatchFace : userWatchFaces) {
items[i++] = Screens::CheckboxList::Item {userWatchFace.name, userWatchFace.isAvailable(controllers.filesystem)};
}
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem);
} break;
case Apps::SettingTimeFormat:
currentScreen = std::make_unique<Screens::SettingTimeFormat>(settingsController);
break;
Expand Down Expand Up @@ -536,18 +540,10 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
const auto* d = std::find_if(userApps.begin(), userApps.end(), [app](const AppDescription& appDescription) {
return appDescription.app == app;
});
if (d != userApps.end())
if (d != userApps.end()) {
currentScreen.reset(d->create(controllers));
else {
currentScreen = std::make_unique<Screens::Clock>(dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController,
heartRateController,
motionController,
systemTask->nimble().weather(),
filesystem);
} else {
currentScreen.reset(userWatchFaces[0].create(controllers));
}
break;
}
Expand Down
25 changes: 24 additions & 1 deletion src/displayapp/UserApps.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
#include "displayapp/screens/Twos.h"
#include "displayapp/screens/Tile.h"
#include "displayapp/screens/ApplicationList.h"
#include "displayapp/screens/Clock.h"
#include "displayapp/screens/WatchFaceDigital.h"
#include "displayapp/screens/WatchFaceAnalog.h"
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
#include "displayapp/screens/WatchFaceInfineat.h"
#include "displayapp/screens/WatchFacePineTimeStyle.h"
#include "displayapp/screens/WatchFaceTerminal.h"

namespace Pinetime {
namespace Applications {
Expand All @@ -21,16 +26,34 @@ namespace Pinetime {
Screens::Screen* (*create)(AppControllers& controllers);
};

struct WatchFaceDescription {
WatchFace watchFace;
const char* name;
Screens::Screen* (*create)(AppControllers& controllers);
bool (*isAvailable)(Controllers::FS& fileSystem);
};

template <Apps t>
consteval AppDescription CreateAppDescription() {
return {AppTraits<t>::app, AppTraits<t>::icon, &AppTraits<t>::Create};
}

template <WatchFace t>
consteval WatchFaceDescription CreateWatchFaceDescription() {
return {WatchFaceTraits<t>::watchFace, WatchFaceTraits<t>::name, &WatchFaceTraits<t>::Create, &WatchFaceTraits<t>::IsAvailable};
}

template <template <Apps...> typename T, Apps... ts>
consteval std::array<AppDescription, sizeof...(ts)> CreateAppDescriptions(T<ts...>) {
return {CreateAppDescription<ts>()...};
}

template <template <WatchFace...> typename T, WatchFace... ts>
consteval std::array<WatchFaceDescription, sizeof...(ts)> CreateWatchFaceDescriptions(T<ts...>) {
return {CreateWatchFaceDescription<ts>()...};
}

constexpr auto userApps = CreateAppDescriptions(UserAppTypes {});
constexpr auto userWatchFaces = CreateWatchFaceDescriptions(UserWatchFaceTypes {});
}
}
14 changes: 0 additions & 14 deletions src/displayapp/WatchFaces.h

This file was deleted.

133 changes: 0 additions & 133 deletions src/displayapp/screens/Clock.cpp

This file was deleted.

Loading