Application selection at build time
A list of "user applications" is built at compile time. It contains all the info needed to create the application at runtime (ptr to a create() function) and to display the app in the application menu. All applications declare a TypeTrait with these information. When a new app must be loaded, DisplayApp first check if this app is a System app (in which case it creates it like it did before). If it's not a System app, it looks for the app in the list of User applications and creates it if it found it. Those changes allow to more easily add new app and to select which app must be built into the firmware. Switch to C++20 (and fix a few issues in SpiMaster.cpp and Watchdog.cpp.
This commit is contained in:

committed by
JF

parent
f6d7f602f5
commit
63e0c4f4ef
@@ -50,6 +50,7 @@
|
||||
#include "displayapp/screens/settings/SettingBluetooth.h"
|
||||
|
||||
#include "libs/lv_conf.h"
|
||||
#include "UserApps.h"
|
||||
|
||||
using namespace Pinetime::Applications;
|
||||
using namespace Pinetime::Applications::Display;
|
||||
@@ -96,7 +97,12 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
||||
touchHandler {touchHandler},
|
||||
filesystem {filesystem},
|
||||
lvgl {lcd, filesystem},
|
||||
timer(this, TimerCallback) {
|
||||
timer(this, TimerCallback),
|
||||
controllers{
|
||||
batteryController, bleController, dateTimeController, notificationManager, heartRateController,
|
||||
settingsController, motorController, motionController, alarmController, brightnessController,
|
||||
nullptr, filesystem, timer, nullptr, this, lvgl, nullptr, nullptr}
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayApp::Start(System::BootErrors error) {
|
||||
@@ -402,14 +408,21 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
|
||||
SetFullRefresh(direction);
|
||||
|
||||
switch (app) {
|
||||
case Apps::Launcher:
|
||||
currentScreen =
|
||||
std::make_unique<Screens::ApplicationList>(this, settingsController, batteryController, bleController, dateTimeController, filesystem);
|
||||
break;
|
||||
case Apps::Motion:
|
||||
// currentScreen = std::make_unique<Screens::Motion>(motionController);
|
||||
// break;
|
||||
case Apps::None:
|
||||
case Apps::Launcher: {
|
||||
std::array<Screens::Tile::Applications, UserAppTypes::Count> apps;
|
||||
int i = 0;
|
||||
for (const auto& userApp : userApps) {
|
||||
apps[i++] = Screens::Tile::Applications {userApp.icon, userApp.app, true};
|
||||
}
|
||||
currentScreen = std::make_unique<Screens::ApplicationList>(this,
|
||||
settingsController,
|
||||
batteryController,
|
||||
bleController,
|
||||
dateTimeController,
|
||||
filesystem,
|
||||
std::move(apps));
|
||||
}
|
||||
break;
|
||||
case Apps::Clock:
|
||||
currentScreen = std::make_unique<Screens::Clock>(dateTimeController,
|
||||
batteryController,
|
||||
@@ -421,7 +434,6 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
|
||||
systemTask->nimble().weather(),
|
||||
filesystem);
|
||||
break;
|
||||
|
||||
case Apps::Error:
|
||||
currentScreen = std::make_unique<Screens::Error>(bootError);
|
||||
break;
|
||||
@@ -453,14 +465,6 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
|
||||
*systemTask,
|
||||
Screens::Notifications::Modes::Preview);
|
||||
break;
|
||||
case Apps::Timer:
|
||||
currentScreen = std::make_unique<Screens::Timer>(timer);
|
||||
break;
|
||||
case Apps::Alarm:
|
||||
currentScreen = std::make_unique<Screens::Alarm>(alarmController, settingsController.GetClockType(), *systemTask, motorController);
|
||||
break;
|
||||
|
||||
// Settings
|
||||
case Apps::QuickSettings:
|
||||
currentScreen = std::make_unique<Screens::QuickSettings>(this,
|
||||
batteryController,
|
||||
@@ -516,38 +520,25 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
|
||||
case Apps::FlashLight:
|
||||
currentScreen = std::make_unique<Screens::FlashLight>(*systemTask, brightnessController);
|
||||
break;
|
||||
case Apps::StopWatch:
|
||||
currentScreen = std::make_unique<Screens::StopWatch>(*systemTask);
|
||||
break;
|
||||
case Apps::Twos:
|
||||
currentScreen = std::make_unique<Screens::Twos>();
|
||||
break;
|
||||
case Apps::Paint:
|
||||
currentScreen = std::make_unique<Screens::InfiniPaint>(lvgl, motorController);
|
||||
break;
|
||||
case Apps::Paddle:
|
||||
currentScreen = std::make_unique<Screens::Paddle>(lvgl);
|
||||
break;
|
||||
case Apps::Music:
|
||||
currentScreen = std::make_unique<Screens::Music>(systemTask->nimble().music());
|
||||
break;
|
||||
case Apps::Navigation:
|
||||
currentScreen = std::make_unique<Screens::Navigation>(systemTask->nimble().navigation());
|
||||
break;
|
||||
case Apps::HeartRate:
|
||||
currentScreen = std::make_unique<Screens::HeartRate>(heartRateController, *systemTask);
|
||||
break;
|
||||
case Apps::Metronome:
|
||||
currentScreen = std::make_unique<Screens::Metronome>(motorController, *systemTask);
|
||||
break;
|
||||
/* Weather debug app
|
||||
case Apps::Weather:
|
||||
currentScreen = std::make_unique<Screens::Weather>(this, systemTask->nimble().weather());
|
||||
break;
|
||||
*/
|
||||
case Apps::Steps:
|
||||
currentScreen = std::make_unique<Screens::Steps>(motionController, settingsController);
|
||||
default: {
|
||||
const auto* d = std::find_if(userApps.begin(), userApps.end(), [app](const AppDescription& appDescription) {
|
||||
return appDescription.app == app;
|
||||
});
|
||||
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);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
currentApp = app;
|
||||
}
|
||||
@@ -605,6 +596,19 @@ void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) {
|
||||
|
||||
void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) {
|
||||
this->systemTask = systemTask;
|
||||
this->controllers.systemTask = systemTask;
|
||||
}
|
||||
|
||||
void DisplayApp::Register(Pinetime::Controllers::WeatherService* weatherService) {
|
||||
this->controllers.weatherController = weatherService;
|
||||
}
|
||||
|
||||
void DisplayApp::Register(Pinetime::Controllers::MusicService* musicService) {
|
||||
this->controllers.musicService = musicService;
|
||||
}
|
||||
|
||||
void DisplayApp::Register(Pinetime::Controllers::NavigationService* NavigationService) {
|
||||
this->controllers.navigationService = NavigationService;
|
||||
}
|
||||
|
||||
void DisplayApp::ApplyBrightness() {
|
||||
|
Reference in New Issue
Block a user