1
0
Fork 0

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

@ -5,7 +5,7 @@ set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose Debug or Release")
project(pinetime VERSION 1.13.0 LANGUAGES C CXX ASM) project(pinetime VERSION 1.13.0 LANGUAGES C CXX ASM)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 20)
# set(CMAKE_GENERATOR "Unix Makefiles") # set(CMAKE_GENERATOR "Unix Makefiles")
set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_EXTENSIONS OFF)

View file

@ -394,7 +394,6 @@ list(APPEND SOURCE_FILES
displayapp/screens/Notifications.cpp displayapp/screens/Notifications.cpp
displayapp/screens/Twos.cpp displayapp/screens/Twos.cpp
displayapp/screens/HeartRate.cpp displayapp/screens/HeartRate.cpp
displayapp/screens/Motion.cpp
displayapp/screens/FlashLight.cpp displayapp/screens/FlashLight.cpp
displayapp/screens/List.cpp displayapp/screens/List.cpp
displayapp/screens/CheckboxList.cpp displayapp/screens/CheckboxList.cpp

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
#include <cstddef>
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {
enum class Apps { enum class Apps {
@ -37,7 +37,32 @@ namespace Pinetime {
SettingChimes, SettingChimes,
SettingShakeThreshold, SettingShakeThreshold,
SettingBluetooth, SettingBluetooth,
Error Error,
Weather
}; };
template <Apps>
struct AppTraits {};
template<Apps ...As>
struct TypeList {
static constexpr size_t Count = sizeof...(As);
};
using UserAppTypes = TypeList<Apps::Alarm,
Apps::HeartRate,
Apps::Paint,
Apps::Metronome,
Apps::Music,
Apps::Navigation,
Apps::Paddle,
Apps::Steps,
Apps::StopWatch,
Apps::Timer,
Apps::Twos
/*
Apps::Weather,
Apps::Motion
*/
>;
} }
} }

View file

@ -0,0 +1,51 @@
#pragma once
namespace Pinetime {
namespace Applications {
class DisplayApp;
}
namespace Components {
class LittleVgl;
}
namespace Controllers {
class Battery;
class Ble;
class DateTime;
class NotificationManager;
class HeartRateController;
class Settings;
class MotorController;
class MotionController;
class AlarmController;
class BrightnessController;
class WeatherService;
class FS;
class Timer;
class MusicService;
class NavigationService;
}
namespace System {
class SystemTask;
}
namespace Applications {
struct AppControllers {
const Pinetime::Controllers::Battery& batteryController;
const Pinetime::Controllers::Ble& bleController;
Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::NotificationManager& notificationManager;
Pinetime::Controllers::HeartRateController& heartRateController;
Pinetime::Controllers::Settings& settingsController;
Pinetime::Controllers::MotorController& motorController;
Pinetime::Controllers::MotionController& motionController;
Pinetime::Controllers::AlarmController& alarmController;
Pinetime::Controllers::BrightnessController& brightnessController;
Pinetime::Controllers::WeatherService* weatherController;
Pinetime::Controllers::FS& filesystem;
Pinetime::Controllers::Timer& timer;
Pinetime::System::SystemTask* systemTask;
Pinetime::Applications::DisplayApp* displayApp;
Pinetime::Components::LittleVgl& lvgl;
Pinetime::Controllers::MusicService* musicService;
Pinetime::Controllers::NavigationService* navigationService;
};
}
}

View file

@ -50,6 +50,7 @@
#include "displayapp/screens/settings/SettingBluetooth.h" #include "displayapp/screens/settings/SettingBluetooth.h"
#include "libs/lv_conf.h" #include "libs/lv_conf.h"
#include "UserApps.h"
using namespace Pinetime::Applications; using namespace Pinetime::Applications;
using namespace Pinetime::Applications::Display; using namespace Pinetime::Applications::Display;
@ -96,7 +97,12 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
touchHandler {touchHandler}, touchHandler {touchHandler},
filesystem {filesystem}, filesystem {filesystem},
lvgl {lcd, 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) { void DisplayApp::Start(System::BootErrors error) {
@ -402,14 +408,21 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
SetFullRefresh(direction); SetFullRefresh(direction);
switch (app) { switch (app) {
case Apps::Launcher: case Apps::Launcher: {
currentScreen = std::array<Screens::Tile::Applications, UserAppTypes::Count> apps;
std::make_unique<Screens::ApplicationList>(this, settingsController, batteryController, bleController, dateTimeController, filesystem); int i = 0;
break; for (const auto& userApp : userApps) {
case Apps::Motion: apps[i++] = Screens::Tile::Applications {userApp.icon, userApp.app, true};
// currentScreen = std::make_unique<Screens::Motion>(motionController); }
// break; currentScreen = std::make_unique<Screens::ApplicationList>(this,
case Apps::None: settingsController,
batteryController,
bleController,
dateTimeController,
filesystem,
std::move(apps));
}
break;
case Apps::Clock: case Apps::Clock:
currentScreen = std::make_unique<Screens::Clock>(dateTimeController, currentScreen = std::make_unique<Screens::Clock>(dateTimeController,
batteryController, batteryController,
@ -421,7 +434,6 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
systemTask->nimble().weather(), systemTask->nimble().weather(),
filesystem); filesystem);
break; break;
case Apps::Error: case Apps::Error:
currentScreen = std::make_unique<Screens::Error>(bootError); currentScreen = std::make_unique<Screens::Error>(bootError);
break; break;
@ -453,14 +465,6 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
*systemTask, *systemTask,
Screens::Notifications::Modes::Preview); Screens::Notifications::Modes::Preview);
break; 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: case Apps::QuickSettings:
currentScreen = std::make_unique<Screens::QuickSettings>(this, currentScreen = std::make_unique<Screens::QuickSettings>(this,
batteryController, batteryController,
@ -516,38 +520,25 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::FlashLight: case Apps::FlashLight:
currentScreen = std::make_unique<Screens::FlashLight>(*systemTask, brightnessController); currentScreen = std::make_unique<Screens::FlashLight>(*systemTask, brightnessController);
break; break;
case Apps::StopWatch: default: {
currentScreen = std::make_unique<Screens::StopWatch>(*systemTask); const auto* d = std::find_if(userApps.begin(), userApps.end(), [app](const AppDescription& appDescription) {
break; return appDescription.app == app;
case Apps::Twos: });
currentScreen = std::make_unique<Screens::Twos>(); if (d != userApps.end())
break; currentScreen.reset(d->create(controllers));
case Apps::Paint: else {
currentScreen = std::make_unique<Screens::InfiniPaint>(lvgl, motorController); currentScreen = std::make_unique<Screens::Clock>(dateTimeController,
break; batteryController,
case Apps::Paddle: bleController,
currentScreen = std::make_unique<Screens::Paddle>(lvgl); notificationManager,
break; settingsController,
case Apps::Music: heartRateController,
currentScreen = std::make_unique<Screens::Music>(systemTask->nimble().music()); motionController,
break; systemTask->nimble().weather(),
case Apps::Navigation: filesystem);
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);
break; break;
}
} }
currentApp = app; currentApp = app;
} }
@ -605,6 +596,19 @@ void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) {
void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) { void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) {
this->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() { void DisplayApp::ApplyBrightness() {

View file

@ -20,6 +20,7 @@
#include "BootErrors.h" #include "BootErrors.h"
#include "utility/StaticStack.h" #include "utility/StaticStack.h"
#include "displayapp/Controllers.h"
namespace Pinetime { namespace Pinetime {
@ -73,6 +74,9 @@ namespace Pinetime {
void SetFullRefresh(FullRefreshDirections direction); void SetFullRefresh(FullRefreshDirections direction);
void Register(Pinetime::System::SystemTask* systemTask); void Register(Pinetime::System::SystemTask* systemTask);
void Register(Pinetime::Controllers::WeatherService* weatherService);
void Register(Pinetime::Controllers::MusicService* musicService);
void Register(Pinetime::Controllers::NavigationService* NavigationService);
private: private:
Pinetime::Drivers::St7789& lcd; Pinetime::Drivers::St7789& lcd;
@ -96,6 +100,7 @@ namespace Pinetime {
Pinetime::Components::LittleVgl lvgl; Pinetime::Components::LittleVgl lvgl;
Pinetime::Controllers::Timer timer; Pinetime::Controllers::Timer timer;
AppControllers controllers;
TaskHandle_t taskHandle; TaskHandle_t taskHandle;
States state = States::Running; States state = States::Running;

36
src/displayapp/UserApps.h Normal file
View file

@ -0,0 +1,36 @@
#pragma once
#include "Apps.h"
#include "Controllers.h"
#include "displayapp/screens/Alarm.h"
#include "displayapp/screens/Timer.h"
#include "displayapp/screens/Twos.h"
#include "displayapp/screens/Tile.h"
#include "displayapp/screens/ApplicationList.h"
#include "displayapp/screens/Clock.h"
namespace Pinetime {
namespace Applications {
namespace Screens {
class Screen;
}
struct AppDescription {
Apps app;
const char* icon;
Screens::Screen* (*create)(AppControllers& controllers);
};
template <Apps t>
consteval AppDescription CreateAppDescription() {
return {AppTraits<t>::app, AppTraits<t>::icon, &AppTraits<t>::Create};
}
template <template<Apps...> typename T, Apps ...ts>
consteval std::array<AppDescription, sizeof...(ts)> CreateAppDescriptions(T<ts...>) {
return {CreateAppDescription<ts>()...};
}
constexpr auto userApps = CreateAppDescriptions(UserAppTypes {});
}
}

View file

@ -19,6 +19,10 @@
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h" #include "displayapp/screens/Symbols.h"
#include "displayapp/InfiniTimeTheme.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 namespace Pinetime::Applications::Screens;
using Pinetime::Controllers::AlarmController; using Pinetime::Controllers::AlarmController;

View file

@ -17,21 +17,22 @@
*/ */
#pragma once #pragma once
#include "displayapp/Apps.h"
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.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/widgets/Counter.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {
namespace Screens { namespace Screens {
class Alarm : public Screen { class Alarm : public Screen {
public: public:
Alarm(Controllers::AlarmController& alarmController, explicit Alarm(Controllers::AlarmController& alarmController,
Controllers::Settings::ClockType clockType, Controllers::Settings::ClockType clockType,
System::SystemTask& systemTask, System::SystemTask& systemTask,
Controllers::MotorController& motorController); Controllers::MotorController& motorController);
~Alarm() override; ~Alarm() override;
void SetAlerting(); void SetAlerting();
void OnButtonEvent(lv_obj_t* obj, lv_event_t event); 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 hourCounter = Widgets::Counter(0, 23, jetbrains_mono_76);
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, 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/ApplicationList.h"
#include "displayapp/screens/Tile.h"
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include <functional> #include <functional>
#include "displayapp/Apps.h" #include <algorithm>
#include "displayapp/DisplayApp.h" #include "components/settings/Settings.h"
using namespace Pinetime::Applications::Screens; using namespace Pinetime::Applications::Screens;
@ -16,18 +17,20 @@ auto ApplicationList::CreateScreenList() const {
return screens; return screens;
} }
ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app, ApplicationList::ApplicationList(DisplayApp* app,
Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::Settings& settingsController,
const Pinetime::Controllers::Battery& batteryController, const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController, const Pinetime::Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController, Controllers::DateTime& dateTimeController,
Pinetime::Controllers::FS& filesystem) Pinetime::Controllers::FS& filesystem,
std::array<Tile::Applications, UserAppTypes::Count>&& apps)
: app {app}, : app {app},
settingsController {settingsController}, settingsController {settingsController},
batteryController {batteryController}, batteryController {batteryController},
bleController {bleController}, bleController {bleController},
dateTimeController {dateTimeController}, dateTimeController {dateTimeController},
filesystem{filesystem}, filesystem{filesystem},
apps{std::move(apps)},
screens {app, settingsController.GetAppMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} { 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::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) const {
std::array<Tile::Applications, appsPerScreen> apps; std::array<Tile::Applications, appsPerScreen> pageApps;
for (int i = 0; i < appsPerScreen; i++) {
apps[i] = applications[screenNum * appsPerScreen + i]; 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, return std::make_unique<Screens::Tile>(screenNum,
@ -52,5 +60,5 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) co
batteryController, batteryController,
bleController, bleController,
dateTimeController, dateTimeController,
apps); pageApps);
} }

View file

@ -2,15 +2,12 @@
#include <array> #include <array>
#include <memory> #include <memory>
#include "displayapp/Apps.h"
#include "displayapp/screens/Screen.h" #include "Screen.h"
#include "displayapp/screens/ScreenList.h" #include "ScreenList.h"
#include "components/datetime/DateTimeController.h" #include "displayapp/Controllers.h"
#include "components/settings/Settings.h" #include "Symbols.h"
#include "components/battery/BatteryController.h" #include "Tile.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/screens/Tile.h"
#include "displayapp/screens/Navigation.h"
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {
@ -22,7 +19,8 @@ namespace Pinetime {
const Pinetime::Controllers::Battery& batteryController, const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController, const Pinetime::Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController, Controllers::DateTime& dateTimeController,
Pinetime::Controllers::FS& filesystem); Pinetime::Controllers::FS& filesystem,
std::array<Tile::Applications, UserAppTypes::Count>&& apps);
~ApplicationList() override; ~ApplicationList() override;
bool OnTouchEvent(TouchEvents event) override; bool OnTouchEvent(TouchEvents event) override;
@ -36,29 +34,13 @@ namespace Pinetime {
const Pinetime::Controllers::Ble& bleController; const Pinetime::Controllers::Ble& bleController;
Controllers::DateTime& dateTimeController; Controllers::DateTime& dateTimeController;
Pinetime::Controllers::FS& filesystem; Pinetime::Controllers::FS& filesystem;
std::array<Tile::Applications, UserAppTypes::Count> apps;
static constexpr int appsPerScreen = 6; static constexpr int appsPerScreen = 6;
// Increment this when more space is needed // 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; ScreenList<nScreens> screens;
}; };
} }

View file

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

View file

@ -4,6 +4,7 @@
#include <chrono> #include <chrono>
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "systemtask/SystemTask.h" #include "systemtask/SystemTask.h"
#include "Symbols.h"
#include <lvgl/src/lv_core/lv_style.h> #include <lvgl/src/lv_core/lv_style.h>
#include <lvgl/src/lv_core/lv_obj.h> #include <lvgl/src/lv_core/lv_obj.h>
@ -37,5 +38,13 @@ namespace Pinetime {
lv_task_t* taskRefresh; 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 <algorithm> // std::fill
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "components/motor/MotorController.h" #include "components/motor/MotorController.h"
#include "Symbols.h"
#include <displayapp/Apps.h>
#include <displayapp/Controllers.h>
namespace Pinetime { namespace Pinetime {
namespace Components { namespace Components {
@ -35,5 +38,13 @@ namespace Pinetime {
uint8_t color = 2; 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 "systemtask/SystemTask.h"
#include "components/motor/MotorController.h" #include "components/motor/MotorController.h"
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "Symbols.h"
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {
@ -36,5 +37,13 @@ namespace Pinetime {
lv_task_t* taskRefresh; 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_style.h>
#include <lvgl/src/lv_core/lv_obj.h> #include <lvgl/src/lv_core/lv_obj.h>
#include <components/motion/MotionController.h> #include <components/motion/MotionController.h>
#include "displayapp/Controllers.h"
#include "displayapp/Apps.h"
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {
@ -30,5 +32,13 @@ namespace Pinetime {
lv_task_t* taskRefresh; 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 <lvgl/src/lv_core/lv_obj.h>
#include <string> #include <string>
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime { namespace Pinetime {
namespace Controllers { namespace Controllers {
@ -82,5 +85,13 @@ namespace Pinetime {
/** Watchapp */ /** 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 <string>
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include <array> #include <array>
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime { namespace Pinetime {
namespace Controllers { namespace Controllers {
@ -55,5 +58,13 @@ namespace Pinetime {
lv_task_t* taskRefresh; 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 <lvgl/lvgl.h>
#include <cstdint> #include <cstdint>
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime { namespace Pinetime {
namespace Components { namespace Components {
@ -45,5 +48,13 @@ namespace Pinetime {
lv_task_t* taskRefresh; 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 <lvgl/lvgl.h>
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include <components/motion/MotionController.h> #include <components/motion/MotionController.h>
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime { namespace Pinetime {
@ -39,5 +42,13 @@ namespace Pinetime {
lv_task_t* taskRefresh; 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 "portmacro_cmsis.h"
#include "systemtask/SystemTask.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 { struct TimeSeparated_t {
int hours; int hours;
int mins; int mins;
int secs; int secs;
int hundredths; int hundredths;
}; };
class StopWatch : public Screen { class StopWatch : public Screen {
public: public:
explicit StopWatch(System::SystemTask& systemTask); explicit StopWatch(System::SystemTask& systemTask);
~StopWatch() override; ~StopWatch() override;
void Refresh() override; void Refresh() override;
void playPauseBtnEventHandler(); void playPauseBtnEventHandler();
void stopLapBtnEventHandler(); void stopLapBtnEventHandler();
bool OnButtonPushed() override; bool OnButtonPushed() override;
private: private:
void SetInterfacePaused(); void SetInterfacePaused();
void SetInterfaceRunning(); void SetInterfaceRunning();
void SetInterfaceStopped(); void SetInterfaceStopped();
void Reset(); void Reset();
void Start(); void Start();
void Pause(); void Pause();
Pinetime::System::SystemTask& systemTask; Pinetime::System::SystemTask& systemTask;
States currentState = States::Init; States currentState = States::Init;
TickType_t startTime; TickType_t startTime;
TickType_t oldTimeElapsed = 0; TickType_t oldTimeElapsed = 0;
TickType_t blinkTime = 0; TickType_t blinkTime = 0;
static constexpr int maxLapCount = 20; static constexpr int maxLapCount = 20;
TickType_t laps[maxLapCount + 1]; TickType_t laps[maxLapCount + 1];
static constexpr int displayedLaps = 2; static constexpr int displayedLaps = 2;
int lapsDone = 0; int lapsDone = 0;
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap; lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
lv_obj_t* lapText; lv_obj_t* lapText;
bool isHoursLabelUpdated = false; 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/screens/Tile.h"
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/BatteryIcon.h" #include "displayapp/screens/BatteryIcon.h"
#include "components/ble/BleController.h" #include "components/ble/BleController.h"
#include "displayapp/InfiniTimeTheme.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); txtPlayPause = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0, 0); lv_obj_align(txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0, 0);
if (timerController.IsRunning()) { if (timer.IsRunning()) {
SetTimerRunning(); SetTimerRunning();
} else { } else {
SetTimerStopped(); SetTimerStopped();

View file

@ -8,38 +8,48 @@
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include "components/timer/Timer.h" #include "components/timer/Timer.h"
#include "Symbols.h"
namespace Pinetime::Applications::Screens { namespace Pinetime::Applications{
class Timer : public Screen { namespace Screens {
public: class Timer : public Screen {
Timer(Controllers::Timer& timerController); public:
~Timer() override; Timer(Controllers::Timer& timerController);
void Refresh() override; ~Timer() override;
void Reset(); void Refresh() override;
void ToggleRunning(); void Reset();
void ButtonPressed(); void ToggleRunning();
void MaskReset(); void ButtonPressed();
void MaskReset();
private: private:
void SetTimerRunning(); void SetTimerRunning();
void SetTimerStopped(); void SetTimerStopped();
void UpdateMask(); void UpdateMask();
Controllers::Timer& timer; Pinetime::Controllers::Timer& timer;
lv_obj_t* btnPlayPause; lv_obj_t* btnPlayPause;
lv_obj_t* txtPlayPause; lv_obj_t* txtPlayPause;
lv_obj_t* btnObjectMask; lv_obj_t* btnObjectMask;
lv_obj_t* highlightObjectMask; lv_obj_t* highlightObjectMask;
lv_objmask_mask_t* btnMask; lv_objmask_mask_t* btnMask;
lv_objmask_mask_t* highlightMask; lv_objmask_mask_t* highlightMask;
lv_task_t* taskRefresh; lv_task_t* taskRefresh;
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76); Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76); Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
bool buttonPressing = false; bool buttonPressing = false;
lv_coord_t maskPosition = 0; lv_coord_t maskPosition = 0;
TickType_t pressTime = 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 #pragma once
#include <lvgl/src/lv_core/lv_obj.h> #include "displayapp/Apps.h"
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "displayapp/Controllers.h"
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {
@ -35,5 +36,11 @@ namespace Pinetime {
bool placeNewTile(); 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 #pragma once
#include <memory> #include <memory>
#include <components/ble/weather/WeatherService.h> #include "components/ble/weather/WeatherService.h"
#include "Screen.h" #include "Screen.h"
#include "ScreenList.h" #include "ScreenList.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {
@ -41,5 +44,13 @@ namespace Pinetime {
std::unique_ptr<Screen> CreateScreenHumidity(); 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);
};
};
} }
} }

View file

@ -131,8 +131,8 @@ void SpiMaster::OnEndEvent() {
if (s > 0) { if (s > 0) {
auto currentSize = std::min((size_t) 255, s); auto currentSize = std::min((size_t) 255, s);
PrepareTx(currentBufferAddr, currentSize); PrepareTx(currentBufferAddr, currentSize);
currentBufferAddr += currentSize; currentBufferAddr = currentBufferAddr + currentSize;
currentBufferSize -= currentSize; currentBufferSize = currentBufferSize - currentSize;
spiBaseAddress->TASKS_START = 1; spiBaseAddress->TASKS_START = 1;
} else { } else {
@ -153,7 +153,7 @@ void SpiMaster::OnEndEvent() {
void SpiMaster::OnStartedEvent() { void SpiMaster::OnStartedEvent() {
} }
void SpiMaster::PrepareTx(const volatile uint32_t bufferAddress, const volatile size_t size) { void SpiMaster::PrepareTx(const uint32_t bufferAddress, const size_t size) {
spiBaseAddress->TXD.PTR = bufferAddress; spiBaseAddress->TXD.PTR = bufferAddress;
spiBaseAddress->TXD.MAXCNT = size; spiBaseAddress->TXD.MAXCNT = size;
spiBaseAddress->TXD.LIST = 0; spiBaseAddress->TXD.LIST = 0;
@ -163,7 +163,7 @@ void SpiMaster::PrepareTx(const volatile uint32_t bufferAddress, const volatile
spiBaseAddress->EVENTS_END = 0; spiBaseAddress->EVENTS_END = 0;
} }
void SpiMaster::PrepareRx(const volatile uint32_t bufferAddress, const volatile size_t size) { void SpiMaster::PrepareRx(const uint32_t bufferAddress, const size_t size) {
spiBaseAddress->TXD.PTR = 0; spiBaseAddress->TXD.PTR = 0;
spiBaseAddress->TXD.MAXCNT = 0; spiBaseAddress->TXD.MAXCNT = 0;
spiBaseAddress->TXD.LIST = 0; spiBaseAddress->TXD.LIST = 0;
@ -195,8 +195,8 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) {
auto currentSize = std::min((size_t) 255, (size_t) currentBufferSize); auto currentSize = std::min((size_t) 255, (size_t) currentBufferSize);
PrepareTx(currentBufferAddr, currentSize); PrepareTx(currentBufferAddr, currentSize);
currentBufferSize -= currentSize; currentBufferSize = currentBufferSize - currentSize;
currentBufferAddr += currentSize; currentBufferAddr = currentBufferAddr + currentSize;
spiBaseAddress->TASKS_START = 1; spiBaseAddress->TASKS_START = 1;
if (size == 1) { if (size == 1) {

View file

@ -41,7 +41,7 @@ namespace {
// RRED (Reload Register Enable) is a bitfield of 8 bits. Each bit represent // RRED (Reload Register Enable) is a bitfield of 8 bits. Each bit represent
// one of the eight reload registers available. // one of the eight reload registers available.
// In this case, we enable only the first one. // In this case, we enable only the first one.
NRF_WDT->RREN |= 1; NRF_WDT->RREN = NRF_WDT->RREN | 1;
} }
/// Returns the reset reason provided by the POWER subsystem /// Returns the reset reason provided by the POWER subsystem

View file

@ -136,6 +136,9 @@ void SystemTask::Work() {
settingsController.Init(); settingsController.Init();
displayApp.Register(this); displayApp.Register(this);
displayApp.Register(&nimbleController.weather());
displayApp.Register(&nimbleController.music());
displayApp.Register(&nimbleController.navigation());
displayApp.Start(bootError); displayApp.Start(bootError);
heartRateSensor.Init(); heartRateSensor.Init();