2020-02-23 13:44:39 +01:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-02 21:16:48 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2020-02-23 13:44:39 +01:00
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <task.h>
|
2020-11-15 15:05:51 +01:00
|
|
|
#include <timers.h>
|
2021-01-10 17:57:26 +01:00
|
|
|
#include <heartratetask/HeartRateTask.h>
|
|
|
|
#include <components/heartrate/HeartRateController.h>
|
2021-03-20 11:41:49 +01:00
|
|
|
#include <components/settings/Settings.h>
|
2020-11-15 15:05:51 +01:00
|
|
|
|
2020-07-02 21:38:52 +02:00
|
|
|
#include "SystemMonitor.h"
|
2020-11-15 15:05:51 +01:00
|
|
|
#include "components/battery/BatteryController.h"
|
2020-10-02 21:16:48 +02:00
|
|
|
#include "components/ble/NimbleController.h"
|
2020-11-15 15:05:51 +01:00
|
|
|
#include "components/ble/NotificationManager.h"
|
2021-01-25 16:47:52 +01:00
|
|
|
#include "components/motor/MotorController.h"
|
2021-01-26 20:31:45 +01:00
|
|
|
#ifdef PINETIME_IS_RECOVERY
|
|
|
|
#include "displayapp/DisplayAppRecovery.h"
|
|
|
|
#include "displayapp/DummyLittleVgl.h"
|
|
|
|
#else
|
2021-02-24 20:40:24 +01:00
|
|
|
#include "components/settings/Settings.h"
|
2020-11-15 15:05:51 +01:00
|
|
|
#include "displayapp/DisplayApp.h"
|
2021-01-26 20:31:45 +01:00
|
|
|
#include "displayapp/LittleVgl.h"
|
|
|
|
#endif
|
|
|
|
|
2020-11-15 15:05:51 +01:00
|
|
|
#include "drivers/Watchdog.h"
|
2020-02-23 13:44:39 +01:00
|
|
|
|
|
|
|
namespace Pinetime {
|
2020-11-15 15:05:51 +01:00
|
|
|
namespace Drivers {
|
|
|
|
class Cst816S;
|
|
|
|
class SpiMaster;
|
|
|
|
class SpiNorFlash;
|
|
|
|
class St7789;
|
|
|
|
class TwiMaster;
|
2021-01-10 17:57:26 +01:00
|
|
|
class Hrs3300;
|
2020-11-15 15:05:51 +01:00
|
|
|
}
|
2020-02-23 13:44:39 +01:00
|
|
|
namespace System {
|
|
|
|
class SystemTask {
|
|
|
|
public:
|
2020-10-27 19:51:06 +01:00
|
|
|
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, OnNewCall, BleConnected,
|
2021-01-17 10:39:46 +01:00
|
|
|
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping
|
2020-03-25 21:23:40 +01:00
|
|
|
};
|
2020-02-23 13:44:39 +01:00
|
|
|
|
2020-05-07 19:53:51 +02:00
|
|
|
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
2020-07-19 20:30:44 +02:00
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
|
|
|
Drivers::TwiMaster& twiMaster, Drivers::Cst816S &touchPanel,
|
2020-03-28 19:05:28 +01:00
|
|
|
Components::LittleVgl &lvgl,
|
|
|
|
Controllers::Battery &batteryController, Controllers::Ble &bleController,
|
|
|
|
Controllers::DateTime &dateTimeController,
|
2021-01-25 16:47:52 +01:00
|
|
|
Pinetime::Controllers::MotorController& motorController,
|
2021-02-24 20:40:24 +01:00
|
|
|
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
|
|
|
Controllers::Settings &settingsController);
|
2020-02-23 13:44:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
void PushMessage(Messages msg);
|
|
|
|
|
|
|
|
void OnButtonPushed();
|
|
|
|
void OnTouchEvent();
|
2020-06-01 20:40:11 +02:00
|
|
|
|
|
|
|
void OnIdle();
|
|
|
|
|
2020-07-11 22:37:28 +02:00
|
|
|
Pinetime::Controllers::NimbleController& nimble() {return nimbleController;};
|
|
|
|
|
2020-02-23 13:44:39 +01:00
|
|
|
private:
|
|
|
|
TaskHandle_t taskHandle;
|
|
|
|
|
|
|
|
Pinetime::Drivers::SpiMaster& spi;
|
|
|
|
Pinetime::Drivers::St7789& lcd;
|
2020-05-07 19:53:51 +02:00
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
2020-07-19 20:30:44 +02:00
|
|
|
Pinetime::Drivers::TwiMaster& twiMaster;
|
2020-02-23 13:44:39 +01:00
|
|
|
Pinetime::Drivers::Cst816S& touchPanel;
|
|
|
|
Pinetime::Components::LittleVgl& lvgl;
|
|
|
|
Pinetime::Controllers::Battery& batteryController;
|
|
|
|
std::unique_ptr<Pinetime::Applications::DisplayApp> displayApp;
|
2021-01-10 17:57:26 +01:00
|
|
|
Pinetime::Controllers::HeartRateController heartRateController;
|
|
|
|
std::unique_ptr<Pinetime::Applications::HeartRateTask> heartRateApp;
|
|
|
|
|
2020-02-23 13:44:39 +01:00
|
|
|
Pinetime::Controllers::Ble& bleController;
|
|
|
|
Pinetime::Controllers::DateTime& dateTimeController;
|
2020-10-04 14:13:01 +02:00
|
|
|
QueueHandle_t systemTasksMsgQueue;
|
2020-09-13 21:26:44 +02:00
|
|
|
std::atomic<bool> isSleeping{false};
|
|
|
|
std::atomic<bool> isGoingToSleep{false};
|
|
|
|
std::atomic<bool> isWakingUp{false};
|
2020-02-23 21:09:11 +01:00
|
|
|
Pinetime::Drivers::Watchdog watchdog;
|
2020-03-22 12:03:17 +01:00
|
|
|
Pinetime::Drivers::WatchdogView watchdogView;
|
2021-01-24 17:22:39 +01:00
|
|
|
Pinetime::Controllers::NotificationManager notificationManager;
|
2021-01-25 16:47:52 +01:00
|
|
|
Pinetime::Controllers::MotorController& motorController;
|
2021-01-10 17:57:26 +01:00
|
|
|
Pinetime::Drivers::Hrs3300& heartRateSensor;
|
2021-02-24 20:40:24 +01:00
|
|
|
Pinetime::Controllers::Settings& settingsController;
|
2021-01-17 16:34:14 +01:00
|
|
|
Pinetime::Controllers::NimbleController nimbleController;
|
2021-01-26 20:31:45 +01:00
|
|
|
Controllers::BrightnessController brightnessController;
|
2020-02-23 13:44:39 +01:00
|
|
|
|
|
|
|
static constexpr uint8_t pinSpiSck = 2;
|
|
|
|
static constexpr uint8_t pinSpiMosi = 3;
|
|
|
|
static constexpr uint8_t pinSpiMiso = 4;
|
|
|
|
static constexpr uint8_t pinSpiCsn = 25;
|
|
|
|
static constexpr uint8_t pinLcdDataCommand = 18;
|
|
|
|
static constexpr uint8_t pinButton = 13;
|
|
|
|
static constexpr uint8_t pinTouchIrq = 28;
|
|
|
|
|
|
|
|
static void Process(void* instance);
|
|
|
|
void Work();
|
2020-07-04 18:10:30 +02:00
|
|
|
void ReloadIdleTimer() const;
|
2020-05-01 21:58:31 +02:00
|
|
|
bool isBleDiscoveryTimerRunning = false;
|
|
|
|
uint8_t bleDiscoveryTimer = 0;
|
2020-06-07 20:05:04 +02:00
|
|
|
static constexpr uint32_t idleTime = 15000;
|
2020-06-01 20:40:11 +02:00
|
|
|
TimerHandle_t idleTimer;
|
|
|
|
bool doNotGoToSleep = false;
|
2020-02-23 13:44:39 +01:00
|
|
|
|
2020-06-01 20:40:11 +02:00
|
|
|
void GoToRunning();
|
2020-07-02 21:38:52 +02:00
|
|
|
|
|
|
|
#if configUSE_TRACE_FACILITY == 1
|
|
|
|
SystemMonitor<FreeRtosMonitor> monitor;
|
|
|
|
#else
|
|
|
|
SystemMonitor<DummyMonitor> monitor;
|
|
|
|
#endif
|
2020-02-23 13:44:39 +01:00
|
|
|
};
|
|
|
|
}
|
2020-07-11 22:37:28 +02:00
|
|
|
}
|