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:
Jean-François Milants
2023-10-23 20:12:34 +02:00
committed by JF
parent f6d7f602f5
commit 63e0c4f4ef
29 changed files with 431 additions and 176 deletions

View File

@@ -19,6 +19,10 @@
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/InfiniTimeTheme.h"
#include "components/settings/Settings.h"
#include "components/alarm/AlarmController.h"
#include "components/motor/MotorController.h"
#include "systemtask/SystemTask.h"
using namespace Pinetime::Applications::Screens;
using Pinetime::Controllers::AlarmController;

View File

@@ -17,21 +17,22 @@
*/
#pragma once
#include "displayapp/Apps.h"
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
#include "systemtask/SystemTask.h"
#include "displayapp/LittleVgl.h"
#include "components/alarm/AlarmController.h"
#include "displayapp/widgets/Counter.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime {
namespace Applications {
namespace Screens {
class Alarm : public Screen {
public:
Alarm(Controllers::AlarmController& alarmController,
Controllers::Settings::ClockType clockType,
System::SystemTask& systemTask,
Controllers::MotorController& motorController);
explicit Alarm(Controllers::AlarmController& alarmController,
Controllers::Settings::ClockType clockType,
System::SystemTask& systemTask,
Controllers::MotorController& motorController);
~Alarm() override;
void SetAlerting();
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
@@ -63,6 +64,15 @@ namespace Pinetime {
Widgets::Counter hourCounter = Widgets::Counter(0, 23, jetbrains_mono_76);
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
};
}
template<>
struct AppTraits<Apps::Alarm> {
static constexpr Apps app = Apps::Alarm;
static constexpr const char* icon = Screens::Symbols::clock;
static Screens::Screen *Create(AppControllers& controllers) { return new Screens::Alarm(controllers.alarmController,
controllers.settingsController.GetClockType(),
*controllers.systemTask,
controllers.motorController); };
};
};
}
}

View File

@@ -1,8 +1,9 @@
#include "displayapp/screens/ApplicationList.h"
#include "displayapp/screens/Tile.h"
#include <lvgl/lvgl.h>
#include <functional>
#include "displayapp/Apps.h"
#include "displayapp/DisplayApp.h"
#include <algorithm>
#include "components/settings/Settings.h"
using namespace Pinetime::Applications::Screens;
@@ -16,18 +17,20 @@ auto ApplicationList::CreateScreenList() const {
return screens;
}
ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
ApplicationList::ApplicationList(DisplayApp* app,
Pinetime::Controllers::Settings& settingsController,
const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
Pinetime::Controllers::FS& filesystem)
Pinetime::Controllers::FS& filesystem,
std::array<Tile::Applications, UserAppTypes::Count>&& apps)
: app {app},
settingsController {settingsController},
batteryController {batteryController},
bleController {bleController},
dateTimeController {dateTimeController},
filesystem{filesystem},
apps{std::move(apps)},
screens {app, settingsController.GetAppMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
}
@@ -40,9 +43,14 @@ bool ApplicationList::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
}
std::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) const {
std::array<Tile::Applications, appsPerScreen> apps;
for (int i = 0; i < appsPerScreen; i++) {
apps[i] = applications[screenNum * appsPerScreen + i];
std::array<Tile::Applications, appsPerScreen> pageApps;
for(int i = 0; i < appsPerScreen; i++) {
if(i+(screenNum * appsPerScreen) >= apps.size()) {
pageApps[i] = {"", Pinetime::Applications::Apps::None, false};
} else {
pageApps[i] = apps[i + (screenNum * appsPerScreen)];
}
}
return std::make_unique<Screens::Tile>(screenNum,
@@ -52,5 +60,5 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) co
batteryController,
bleController,
dateTimeController,
apps);
pageApps);
}

View File

@@ -2,15 +2,12 @@
#include <array>
#include <memory>
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/ScreenList.h"
#include "components/datetime/DateTimeController.h"
#include "components/settings/Settings.h"
#include "components/battery/BatteryController.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/screens/Tile.h"
#include "displayapp/screens/Navigation.h"
#include "displayapp/Apps.h"
#include "Screen.h"
#include "ScreenList.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
#include "Tile.h"
namespace Pinetime {
namespace Applications {
@@ -22,7 +19,8 @@ namespace Pinetime {
const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
Pinetime::Controllers::FS& filesystem);
Pinetime::Controllers::FS& filesystem,
std::array<Tile::Applications, UserAppTypes::Count>&& apps);
~ApplicationList() override;
bool OnTouchEvent(TouchEvents event) override;
@@ -36,29 +34,13 @@ namespace Pinetime {
const Pinetime::Controllers::Ble& bleController;
Controllers::DateTime& dateTimeController;
Pinetime::Controllers::FS& filesystem;
std::array<Tile::Applications, UserAppTypes::Count> apps;
static constexpr int appsPerScreen = 6;
// Increment this when more space is needed
static constexpr int nScreens = 2;
static constexpr int nScreens = (UserAppTypes::Count/appsPerScreen)+1;
std::array<Tile::Applications, appsPerScreen * nScreens> applications {{
{Symbols::stopWatch, Apps::StopWatch, true},
{Symbols::clock, Apps::Alarm, true},
{Symbols::hourGlass, Apps::Timer, true},
{Symbols::shoe, Apps::Steps, true},
{Symbols::heartBeat, Apps::HeartRate, true},
{Symbols::music, Apps::Music, true},
{Symbols::paintbrush, Apps::Paint, true},
{Symbols::paddle, Apps::Paddle, true},
{"2", Apps::Twos, true},
{Symbols::drum, Apps::Metronome, true},
{Symbols::map, Apps::Navigation, Applications::Screens::Navigation::IsAvailable(filesystem)},
{Symbols::none, Apps::None, false},
// {"M", Apps::Motion},
}};
ScreenList<nScreens> screens;
};
}

View File

@@ -1,13 +1,12 @@
#pragma once
#include <lvgl/src/lv_core/lv_obj.h>
#include <chrono>
#include <cstdint>
#include <memory>
#include <components/heartrate/HeartRateController.h>
#include "displayapp/Controllers.h"
#include "displayapp/screens/Screen.h"
#include "components/datetime/DateTimeController.h"
#include "components/ble/weather/WeatherService.h"
#include "displayapp/Apps.h"
#include "Symbols.h"
namespace Pinetime {
namespace Controllers {
@@ -16,6 +15,10 @@ namespace Pinetime {
class Ble;
class NotificationManager;
class MotionController;
class DateTime;
class HeartRateController;
class WeatherService;
class FS;
}
namespace Applications {

View File

@@ -4,6 +4,7 @@
#include <chrono>
#include "displayapp/screens/Screen.h"
#include "systemtask/SystemTask.h"
#include "Symbols.h"
#include <lvgl/src/lv_core/lv_style.h>
#include <lvgl/src/lv_core/lv_obj.h>
@@ -37,5 +38,13 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct AppTraits<Apps::HeartRate> {
static constexpr Apps app = Apps::HeartRate;
static constexpr const char* icon = Screens::Symbols::heartBeat;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::HeartRate(controllers.heartRateController, *controllers.systemTask);
};
};
}
}

View File

@@ -5,6 +5,9 @@
#include <algorithm> // std::fill
#include "displayapp/screens/Screen.h"
#include "components/motor/MotorController.h"
#include "Symbols.h"
#include <displayapp/Apps.h>
#include <displayapp/Controllers.h>
namespace Pinetime {
namespace Components {
@@ -35,5 +38,13 @@ namespace Pinetime {
uint8_t color = 2;
};
}
template <>
struct AppTraits<Apps::Paint> {
static constexpr Apps app = Apps::Paint;
static constexpr const char* icon = Screens::Symbols::paintbrush;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::InfiniPaint(controllers.lvgl, controllers.motorController);
};
};
}
}

View File

@@ -3,6 +3,7 @@
#include "systemtask/SystemTask.h"
#include "components/motor/MotorController.h"
#include "displayapp/screens/Screen.h"
#include "Symbols.h"
namespace Pinetime {
namespace Applications {
@@ -36,5 +37,13 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct AppTraits<Apps::Metronome> {
static constexpr Apps app = Apps::Metronome;
static constexpr const char* icon = Screens::Symbols::drum;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Metronome(controllers.motorController, *controllers.systemTask);
};
};
}
}

View File

@@ -6,6 +6,8 @@
#include <lvgl/src/lv_core/lv_style.h>
#include <lvgl/src/lv_core/lv_obj.h>
#include <components/motion/MotionController.h>
#include "displayapp/Controllers.h"
#include "displayapp/Apps.h"
namespace Pinetime {
namespace Applications {
@@ -30,5 +32,13 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct AppTraits<Apps::Motion> {
static constexpr Apps app = Apps::Motion;
static constexpr const char* icon = "M";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Motion(controllers.motionController);
};
};
}
}

View File

@@ -21,6 +21,9 @@
#include <lvgl/src/lv_core/lv_obj.h>
#include <string>
#include "displayapp/screens/Screen.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime {
namespace Controllers {
@@ -82,5 +85,13 @@ namespace Pinetime {
/** Watchapp */
};
}
template <>
struct AppTraits<Apps::Music> {
static constexpr Apps app = Apps::Music;
static constexpr const char* icon = Screens::Symbols::music;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Music(*controllers.musicService);
};
};
}
}

View File

@@ -22,6 +22,9 @@
#include <string>
#include "displayapp/screens/Screen.h"
#include <array>
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime {
namespace Controllers {
@@ -55,5 +58,13 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct AppTraits<Apps::Navigation> {
static constexpr Apps app = Apps::Navigation;
static constexpr const char* icon = Screens::Symbols::map;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Navigation(*controllers.navigationService);
};
};
}
}

View File

@@ -3,6 +3,9 @@
#include <lvgl/lvgl.h>
#include <cstdint>
#include "displayapp/screens/Screen.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime {
namespace Components {
@@ -45,5 +48,13 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct AppTraits<Apps::Paddle> {
static constexpr Apps app = Apps::Paddle;
static constexpr const char* icon = Screens::Symbols::paddle;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Paddle(controllers.lvgl);
};
};
}
}

View File

@@ -4,6 +4,9 @@
#include <lvgl/lvgl.h>
#include "displayapp/screens/Screen.h"
#include <components/motion/MotionController.h>
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime {
@@ -39,5 +42,13 @@ namespace Pinetime {
lv_task_t* taskRefresh;
};
}
template <>
struct AppTraits<Apps::Steps> {
static constexpr Apps app = Apps::Steps;
static constexpr const char* icon = Screens::Symbols::shoe;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Steps(controllers.motionController, controllers.settingsController);
};
};
}
}

View File

@@ -7,50 +7,65 @@
#include "portmacro_cmsis.h"
#include "systemtask/SystemTask.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime::Applications::Screens {
namespace Pinetime {
namespace Applications {
namespace Screens {
enum class States { Init, Running, Halted };
enum class States { Init, Running, Halted };
struct TimeSeparated_t {
int hours;
int mins;
int secs;
int hundredths;
};
struct TimeSeparated_t {
int hours;
int mins;
int secs;
int hundredths;
};
class StopWatch : public Screen {
public:
explicit StopWatch(System::SystemTask& systemTask);
~StopWatch() override;
void Refresh() override;
class StopWatch : public Screen {
public:
explicit StopWatch(System::SystemTask& systemTask);
~StopWatch() override;
void Refresh() override;
void playPauseBtnEventHandler();
void stopLapBtnEventHandler();
bool OnButtonPushed() override;
void playPauseBtnEventHandler();
void stopLapBtnEventHandler();
bool OnButtonPushed() override;
private:
void SetInterfacePaused();
void SetInterfaceRunning();
void SetInterfaceStopped();
private:
void SetInterfacePaused();
void SetInterfaceRunning();
void SetInterfaceStopped();
void Reset();
void Start();
void Pause();
void Reset();
void Start();
void Pause();
Pinetime::System::SystemTask& systemTask;
States currentState = States::Init;
TickType_t startTime;
TickType_t oldTimeElapsed = 0;
TickType_t blinkTime = 0;
static constexpr int maxLapCount = 20;
TickType_t laps[maxLapCount + 1];
static constexpr int displayedLaps = 2;
int lapsDone = 0;
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
lv_obj_t* lapText;
bool isHoursLabelUpdated = false;
Pinetime::System::SystemTask& systemTask;
States currentState = States::Init;
TickType_t startTime;
TickType_t oldTimeElapsed = 0;
TickType_t blinkTime = 0;
static constexpr int maxLapCount = 20;
TickType_t laps[maxLapCount + 1];
static constexpr int displayedLaps = 2;
int lapsDone = 0;
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
lv_obj_t* lapText;
bool isHoursLabelUpdated = false;
lv_task_t* taskRefresh;
};
lv_task_t* taskRefresh;
};
}
template <>
struct AppTraits<Apps::StopWatch> {
static constexpr Apps app = Apps::StopWatch;
static constexpr const char* icon = Screens::Symbols::stopWatch;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::StopWatch(*controllers.systemTask);
};
};
}
}

View File

@@ -1,5 +1,4 @@
#include "displayapp/screens/Tile.h"
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/BatteryIcon.h"
#include "components/ble/BleController.h"
#include "displayapp/InfiniTimeTheme.h"

View File

@@ -62,7 +62,7 @@ Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
txtPlayPause = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0, 0);
if (timerController.IsRunning()) {
if (timer.IsRunning()) {
SetTimerRunning();
} else {
SetTimerStopped();

View File

@@ -8,38 +8,48 @@
#include <lvgl/lvgl.h>
#include "components/timer/Timer.h"
#include "Symbols.h"
namespace Pinetime::Applications::Screens {
class Timer : public Screen {
public:
Timer(Controllers::Timer& timerController);
~Timer() override;
void Refresh() override;
void Reset();
void ToggleRunning();
void ButtonPressed();
void MaskReset();
namespace Pinetime::Applications{
namespace Screens {
class Timer : public Screen {
public:
Timer(Controllers::Timer& timerController);
~Timer() override;
void Refresh() override;
void Reset();
void ToggleRunning();
void ButtonPressed();
void MaskReset();
private:
void SetTimerRunning();
void SetTimerStopped();
void UpdateMask();
Controllers::Timer& timer;
private:
void SetTimerRunning();
void SetTimerStopped();
void UpdateMask();
Pinetime::Controllers::Timer& timer;
lv_obj_t* btnPlayPause;
lv_obj_t* txtPlayPause;
lv_obj_t* btnPlayPause;
lv_obj_t* txtPlayPause;
lv_obj_t* btnObjectMask;
lv_obj_t* highlightObjectMask;
lv_objmask_mask_t* btnMask;
lv_objmask_mask_t* highlightMask;
lv_obj_t* btnObjectMask;
lv_obj_t* highlightObjectMask;
lv_objmask_mask_t* btnMask;
lv_objmask_mask_t* highlightMask;
lv_task_t* taskRefresh;
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
lv_task_t* taskRefresh;
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
bool buttonPressing = false;
lv_coord_t maskPosition = 0;
TickType_t pressTime = 0;
bool buttonPressing = false;
lv_coord_t maskPosition = 0;
TickType_t pressTime = 0;
};
}
template<>
struct AppTraits<Apps::Timer> {
static constexpr Apps app = Apps::Timer;
static constexpr const char* icon = Screens::Symbols::hourGlass;
static Screens::Screen *Create(AppControllers& controllers) { return new Screens::Timer(controllers.timer); };
};
}

View File

@@ -1,7 +1,8 @@
#pragma once
#include <lvgl/src/lv_core/lv_obj.h>
#include "displayapp/Apps.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/Controllers.h"
namespace Pinetime {
namespace Applications {
@@ -35,5 +36,11 @@ namespace Pinetime {
bool placeNewTile();
};
}
template<>
struct AppTraits<Apps::Twos> {
static constexpr Apps app = Apps::Twos;
static constexpr const char* icon = "2";
static Screens::Screen *Create(AppControllers& /*controllers*/) { return new Screens::Twos(); };
};
}
}

View File

@@ -1,9 +1,12 @@
#pragma once
#include <memory>
#include <components/ble/weather/WeatherService.h>
#include "components/ble/weather/WeatherService.h"
#include "Screen.h"
#include "ScreenList.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime {
namespace Applications {
@@ -41,5 +44,13 @@ namespace Pinetime {
std::unique_ptr<Screen> CreateScreenHumidity();
};
}
template <>
struct AppTraits<Apps::Weather> {
static constexpr Apps app = Apps::Weather;
static constexpr const char* icon = Screens::Symbols::sun;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Weather(controllers.displayApp, *controllers.weatherController);
};
};
}
}