1
0
Fork 0

Watch face selection at build time

Watch faces can now be selected at buid time. It's implemented in a similar way than the selection of user apps, using a list of watch face description that is generated at build time (consteval, constexpr)
This commit is contained in:
Jean-François Milants 2023-12-10 18:35:19 +01:00 committed by JF
parent a544da9ed1
commit 39bc166e54
16 changed files with 216 additions and 259 deletions

View file

@ -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
@ -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
@ -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

View file

@ -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 {

View file

@ -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,
@ -42,14 +43,31 @@ namespace Pinetime {
Weather
};
enum class WatchFace : uint8_t {
Digital = 0,
Analog = 1,
PineTimeStyle = 2,
Terminal = 3,
Infineat = 4,
CasioStyleG7710 = 5,
};
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,
@ -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);
}
}

View file

@ -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"
@ -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;
@ -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;
@ -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;
}

View file

@ -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 {
@ -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 {});
}
}

View file

@ -1,14 +0,0 @@
#pragma once
namespace Pinetime {
namespace Applications {
enum class WatchFace : uint8_t {
Digital = 0,
Analog = 1,
PineTimeStyle = 2,
Terminal = 3,
Infineat = 4,
CasioStyleG7710 = 5,
};
}
}

View file

@ -1,133 +0,0 @@
#include "displayapp/screens/Clock.h"
#include <lvgl/lvgl.h>
#include "components/battery/BatteryController.h"
#include "components/motion/MotionController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "components/settings/Settings.h"
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/WatchFaceDigital.h"
#include "displayapp/screens/WatchFaceTerminal.h"
#include "displayapp/screens/WatchFaceInfineat.h"
#include "displayapp/screens/WatchFaceAnalog.h"
#include "displayapp/screens/WatchFacePineTimeStyle.h"
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
using namespace Pinetime::Applications::Screens;
using namespace Pinetime::Applications;
Clock::Clock(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController,
Controllers::WeatherService& weatherService,
Controllers::FS& filesystem)
: dateTimeController {dateTimeController},
batteryController {batteryController},
bleController {bleController},
notificationManager {notificationManager},
settingsController {settingsController},
heartRateController {heartRateController},
motionController {motionController},
weatherService {weatherService},
filesystem {filesystem},
screen {[this, &settingsController]() {
switch (settingsController.GetWatchFace()) {
case WatchFace::Digital:
return WatchFaceDigitalScreen();
break;
case WatchFace::Analog:
return WatchFaceAnalogScreen();
break;
case WatchFace::PineTimeStyle:
return WatchFacePineTimeStyleScreen();
break;
case WatchFace::Terminal:
return WatchFaceTerminalScreen();
break;
case WatchFace::Infineat:
return WatchFaceInfineatScreen();
break;
case WatchFace::CasioStyleG7710:
return WatchFaceCasioStyleG7710();
break;
}
return WatchFaceDigitalScreen();
}()} {
settingsController.SetAppMenu(0);
}
Clock::~Clock() {
lv_obj_clean(lv_scr_act());
}
bool Clock::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return screen->OnTouchEvent(event);
}
bool Clock::OnButtonPushed() {
return screen->OnButtonPushed();
}
std::unique_ptr<Screen> Clock::WatchFaceDigitalScreen() {
return std::make_unique<Screens::WatchFaceDigital>(dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController,
heartRateController,
motionController);
}
std::unique_ptr<Screen> Clock::WatchFaceAnalogScreen() {
return std::make_unique<Screens::WatchFaceAnalog>(dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController);
}
std::unique_ptr<Screen> Clock::WatchFacePineTimeStyleScreen() {
return std::make_unique<Screens::WatchFacePineTimeStyle>(dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController,
motionController,
weatherService);
}
std::unique_ptr<Screen> Clock::WatchFaceTerminalScreen() {
return std::make_unique<Screens::WatchFaceTerminal>(dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController,
heartRateController,
motionController);
}
std::unique_ptr<Screen> Clock::WatchFaceInfineatScreen() {
return std::make_unique<Screens::WatchFaceInfineat>(dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController,
motionController,
filesystem);
}
std::unique_ptr<Screen> Clock::WatchFaceCasioStyleG7710() {
return std::make_unique<Screens::WatchFaceCasioStyleG7710>(dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController,
heartRateController,
motionController,
filesystem);
}

View file

@ -1,63 +0,0 @@
#pragma once
#include <chrono>
#include <cstdint>
#include <memory>
#include "displayapp/Controllers.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/Apps.h"
#include "Symbols.h"
namespace Pinetime {
namespace Controllers {
class Settings;
class Battery;
class Ble;
class NotificationManager;
class MotionController;
class DateTime;
class HeartRateController;
class WeatherService;
class FS;
}
namespace Applications {
namespace Screens {
class Clock : public Screen {
public:
Clock(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController,
Controllers::WeatherService& weatherService,
Controllers::FS& filesystem);
~Clock() override;
bool OnTouchEvent(TouchEvents event) override;
bool OnButtonPushed() override;
private:
Controllers::DateTime& dateTimeController;
const Controllers::Battery& batteryController;
const Controllers::Ble& bleController;
Controllers::NotificationManager& notificationManager;
Controllers::Settings& settingsController;
Controllers::HeartRateController& heartRateController;
Controllers::MotionController& motionController;
Controllers::WeatherService& weatherService;
Controllers::FS& filesystem;
std::unique_ptr<Screen> screen;
std::unique_ptr<Screen> WatchFaceDigitalScreen();
std::unique_ptr<Screen> WatchFaceAnalogScreen();
std::unique_ptr<Screen> WatchFacePineTimeStyleScreen();
std::unique_ptr<Screen> WatchFaceTerminalScreen();
std::unique_ptr<Screen> WatchFaceInfineatScreen();
std::unique_ptr<Screen> WatchFaceCasioStyleG7710();
};
}
}
}

View file

@ -88,5 +88,23 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct WatchFaceTraits<WatchFace::Analog> {
static constexpr WatchFace watchFace = WatchFace::Analog;
static constexpr const char* name = "Analog face";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::WatchFaceAnalog(controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.notificationManager,
controllers.settingsController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
}
};
}
}

View file

@ -5,10 +5,12 @@
#include <chrono>
#include <cstdint>
#include <memory>
#include <displayapp/Controllers.h>
#include "displayapp/screens/Screen.h"
#include "components/datetime/DateTimeController.h"
#include "components/ble/BleController.h"
#include "utility/DirtyValue.h"
#include "displayapp/Apps.h"
namespace Pinetime {
namespace Controllers {
@ -100,5 +102,26 @@ namespace Pinetime {
lv_font_t* font_segment115 = nullptr;
};
}
template <>
struct WatchFaceTraits<WatchFace::CasioStyleG7710> {
static constexpr WatchFace watchFace = WatchFace::CasioStyleG7710;
static constexpr const char* name = "Casio G7710";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::WatchFaceCasioStyleG7710(controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.notificationManager,
controllers.settingsController,
controllers.heartRateController,
controllers.motionController,
controllers.filesystem);
};
static bool IsAvailable(Pinetime::Controllers::FS& filesystem) {
return Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem);
}
};
}
}

View file

@ -9,6 +9,7 @@
#include "components/ble/BleController.h"
#include "displayapp/widgets/StatusIcons.h"
#include "utility/DirtyValue.h"
#include "displayapp/Apps.h"
namespace Pinetime {
namespace Controllers {
@ -71,5 +72,25 @@ namespace Pinetime {
Widgets::StatusIcons statusIcons;
};
}
template <>
struct WatchFaceTraits<WatchFace::Digital> {
static constexpr WatchFace watchFace = WatchFace::Digital;
static constexpr const char* name = "Digital face";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::WatchFaceDigital(controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.notificationManager,
controllers.settingsController,
controllers.heartRateController,
controllers.motionController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
}
};
}
}

View file

@ -4,9 +4,11 @@
#include <chrono>
#include <cstdint>
#include <memory>
#include <displayapp/Controllers.h>
#include "displayapp/screens/Screen.h"
#include "components/datetime/DateTimeController.h"
#include "utility/DirtyValue.h"
#include "displayapp/Apps.h"
namespace Pinetime {
namespace Controllers {
@ -98,5 +100,25 @@ namespace Pinetime {
lv_font_t* font_bebas = nullptr;
};
}
template <>
struct WatchFaceTraits<WatchFace::Infineat> {
static constexpr WatchFace watchFace = WatchFace::Infineat;
static constexpr const char* name = "Infineat face";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::WatchFaceInfineat(controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.notificationManager,
controllers.settingsController,
controllers.motionController,
controllers.filesystem);
};
static bool IsAvailable(Pinetime::Controllers::FS& filesystem) {
return Screens::WatchFaceInfineat::IsAvailable(filesystem);
}
};
}
}

View file

@ -4,6 +4,7 @@
#include <chrono>
#include <cstdint>
#include <memory>
#include <displayapp/Controllers.h>
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/BatteryIcon.h"
#include "displayapp/Colors.h"
@ -121,5 +122,25 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct WatchFaceTraits<WatchFace::PineTimeStyle> {
static constexpr WatchFace watchFace = WatchFace::PineTimeStyle;
static constexpr const char* name = "PineTimeStyle";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::WatchFacePineTimeStyle(controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.notificationManager,
controllers.settingsController,
controllers.motionController,
*controllers.weatherController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
}
};
}
}

View file

@ -4,6 +4,7 @@
#include <chrono>
#include <cstdint>
#include <memory>
#include <displayapp/Controllers.h>
#include "displayapp/screens/Screen.h"
#include "components/datetime/DateTimeController.h"
#include "utility/DirtyValue.h"
@ -68,5 +69,25 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct WatchFaceTraits<WatchFace::Terminal> {
static constexpr WatchFace watchFace = WatchFace::Terminal;
static constexpr const char* name = "Terminal";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::WatchFaceTerminal(controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.notificationManager,
controllers.settingsController,
controllers.heartRateController,
controllers.motionController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
}
};
}
}

View file

@ -3,7 +3,6 @@
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Screen.h"
#include "components/settings/Settings.h"
#include "displayapp/WatchFaces.h"
using namespace Pinetime::Applications::Screens;
@ -21,9 +20,11 @@ auto SettingWatchFace::CreateScreenList() const {
}
SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app,
std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count>&& watchfaceItems,
Pinetime::Controllers::Settings& settingsController,
Pinetime::Controllers::FS& filesystem)
: app {app},
watchfaceItems {std::move(watchfaceItems)},
settingsController {settingsController},
filesystem {filesystem},
screens {app, 0, CreateScreenList(), Screens::ScreenListModes::UpDown} {
@ -40,7 +41,11 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
std::unique_ptr<Screen> SettingWatchFace::CreateScreen(unsigned int screenNum) const {
std::array<Screens::CheckboxList::Item, settingsPerScreen> watchfacesOnThisScreen;
for (int i = 0; i < settingsPerScreen; i++) {
watchfacesOnThisScreen[i] = watchfaces[screenNum * settingsPerScreen + i];
if (i + (screenNum * settingsPerScreen) >= watchfaceItems.size()) {
watchfacesOnThisScreen[i] = {"", false};
} else {
watchfacesOnThisScreen[i] = watchfaceItems[i + (screenNum * settingsPerScreen)];
}
}
return std::make_unique<Screens::CheckboxList>(

View file

@ -19,7 +19,10 @@ namespace Pinetime {
class SettingWatchFace : public Screen {
public:
SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::FS& filesystem);
SettingWatchFace(DisplayApp* app,
std::array<Screens::CheckboxList::Item, UserWatchFaceTypes::Count>&& watchfaceItems,
Pinetime::Controllers::Settings& settingsController,
Pinetime::Controllers::FS& filesystem);
~SettingWatchFace() override;
bool OnTouchEvent(TouchEvents event) override;
@ -29,26 +32,16 @@ namespace Pinetime {
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;
static constexpr int nScreens = UserWatchFaceTypes::Count > 0 ? (UserWatchFaceTypes ::Count - 1) / settingsPerScreen + 1 : 1;
Controllers::Settings& settingsController;
Pinetime::Controllers::FS& filesystem;
static constexpr const char* title = "Watch face";
static constexpr const char* symbol = Symbols::home;
static constexpr int settingsPerScreen = 4;
// Increment this when more space is needed
static constexpr int nScreens = 2;
std::array<Screens::CheckboxList::Item, settingsPerScreen * nScreens> watchfaces {
{{"Digital face", true},
{"Analog face", true},
{"PineTimeStyle", true},
{"Terminal", true},
{"Infineat face", Applications::Screens::WatchFaceInfineat::IsAvailable(filesystem)},
{"Casio G7710", Applications::Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem)},
{"", false},
{"", false}}};
ScreenList<nScreens> screens;
};
}