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>
|
2021-03-20 11:41:49 +01:00
|
|
|
#include <components/settings/Settings.h>
|
2021-03-31 19:47:27 +02:00
|
|
|
#include <drivers/Bma421.h>
|
2021-08-02 21:37:48 +02:00
|
|
|
#include <drivers/PinMap.h>
|
2021-03-31 19:47:27 +02:00
|
|
|
#include <components/motion/MotionController.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-05-20 20:43:54 +02:00
|
|
|
#include "components/timer/TimerController.h"
|
2021-09-11 00:40:13 +02:00
|
|
|
#include "components/alarm/AlarmController.h"
|
2021-07-11 15:06:06 +02:00
|
|
|
#include "components/fs/FS.h"
|
2021-07-16 00:49:20 +02:00
|
|
|
#include "touchhandler/TouchHandler.h"
|
2021-07-11 15:06:06 +02:00
|
|
|
|
2021-01-26 20:31:45 +01:00
|
|
|
#ifdef PINETIME_IS_RECOVERY
|
2021-04-18 19:28:14 +02:00
|
|
|
#include "displayapp/DisplayAppRecovery.h"
|
|
|
|
#include "displayapp/DummyLittleVgl.h"
|
2021-01-26 20:31:45 +01:00
|
|
|
#else
|
2021-04-18 19:28:14 +02:00
|
|
|
#include "components/settings/Settings.h"
|
|
|
|
#include "displayapp/DisplayApp.h"
|
2021-07-16 00:49:20 +02:00
|
|
|
#include "displayapp/LittleVgl.h"
|
2021-01-26 20:31:45 +01:00
|
|
|
#endif
|
|
|
|
|
2020-11-15 15:05:51 +01:00
|
|
|
#include "drivers/Watchdog.h"
|
2021-06-06 15:56:03 +02:00
|
|
|
#include "Messages.h"
|
2020-02-23 13:44:39 +01:00
|
|
|
|
2021-08-19 02:51:12 +02:00
|
|
|
extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime;
|
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
|
|
|
}
|
2021-07-16 00:49:20 +02:00
|
|
|
namespace Controllers {
|
|
|
|
class TouchHandler;
|
|
|
|
}
|
2020-02-23 13:44:39 +01:00
|
|
|
namespace System {
|
|
|
|
class SystemTask {
|
2021-04-24 11:00:45 +02:00
|
|
|
public:
|
2021-04-18 19:28:14 +02:00
|
|
|
SystemTask(Drivers::SpiMaster& spi,
|
|
|
|
Drivers::St7789& lcd,
|
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
|
|
|
Drivers::TwiMaster& twiMaster,
|
|
|
|
Drivers::Cst816S& touchPanel,
|
|
|
|
Components::LittleVgl& lvgl,
|
|
|
|
Controllers::Battery& batteryController,
|
|
|
|
Controllers::Ble& bleController,
|
2021-06-06 15:56:03 +02:00
|
|
|
Controllers::DateTime& dateTimeController,
|
|
|
|
Controllers::TimerController& timerController,
|
2021-09-11 00:40:13 +02:00
|
|
|
Controllers::AlarmController& alarmController,
|
2021-06-06 15:56:03 +02:00
|
|
|
Drivers::Watchdog& watchdog,
|
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager,
|
2021-04-18 19:28:14 +02:00
|
|
|
Pinetime::Controllers::MotorController& motorController,
|
|
|
|
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
2021-06-06 15:56:03 +02:00
|
|
|
Pinetime::Controllers::MotionController& motionController,
|
2021-04-18 19:28:14 +02:00
|
|
|
Pinetime::Drivers::Bma421& motionSensor,
|
2021-06-06 15:56:03 +02:00
|
|
|
Controllers::Settings& settingsController,
|
|
|
|
Pinetime::Controllers::HeartRateController& heartRateController,
|
|
|
|
Pinetime::Applications::DisplayApp& displayApp,
|
2021-07-11 15:06:06 +02:00
|
|
|
Pinetime::Applications::HeartRateTask& heartRateApp,
|
2021-07-16 00:49:20 +02:00
|
|
|
Pinetime::Controllers::FS& fs,
|
|
|
|
Pinetime::Controllers::TouchHandler& touchHandler);
|
2021-04-18 19:28:14 +02:00
|
|
|
|
|
|
|
void Start();
|
|
|
|
void PushMessage(Messages msg);
|
|
|
|
|
|
|
|
void OnButtonPushed();
|
|
|
|
void OnTouchEvent();
|
|
|
|
|
|
|
|
void OnIdle();
|
2021-07-24 20:29:10 +02:00
|
|
|
void OnDim();
|
2021-04-18 19:28:14 +02:00
|
|
|
|
|
|
|
Pinetime::Controllers::NimbleController& nimble() {
|
|
|
|
return nimbleController;
|
|
|
|
};
|
|
|
|
|
2021-06-26 20:53:32 +02:00
|
|
|
bool IsSleeping() const {
|
|
|
|
return isSleeping;
|
|
|
|
}
|
|
|
|
|
2021-04-24 11:00:45 +02:00
|
|
|
private:
|
2021-04-18 19:28:14 +02:00
|
|
|
TaskHandle_t taskHandle;
|
|
|
|
|
|
|
|
Pinetime::Drivers::SpiMaster& spi;
|
|
|
|
Pinetime::Drivers::St7789& lcd;
|
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
|
|
|
Pinetime::Drivers::TwiMaster& twiMaster;
|
|
|
|
Pinetime::Drivers::Cst816S& touchPanel;
|
|
|
|
Pinetime::Components::LittleVgl& lvgl;
|
|
|
|
Pinetime::Controllers::Battery& batteryController;
|
2021-06-06 15:56:03 +02:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
Pinetime::Controllers::Ble& bleController;
|
2021-06-06 15:56:03 +02:00
|
|
|
Pinetime::Controllers::DateTime& dateTimeController;
|
|
|
|
Pinetime::Controllers::TimerController& timerController;
|
2021-09-11 00:40:13 +02:00
|
|
|
Pinetime::Controllers::AlarmController& alarmController;
|
2021-04-18 19:28:14 +02:00
|
|
|
QueueHandle_t systemTasksMsgQueue;
|
|
|
|
std::atomic<bool> isSleeping {false};
|
|
|
|
std::atomic<bool> isGoingToSleep {false};
|
|
|
|
std::atomic<bool> isWakingUp {false};
|
2021-07-24 20:29:10 +02:00
|
|
|
std::atomic<bool> isDimmed {false};
|
2021-06-06 15:56:03 +02:00
|
|
|
Pinetime::Drivers::Watchdog& watchdog;
|
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager;
|
2021-04-18 19:28:14 +02:00
|
|
|
Pinetime::Controllers::MotorController& motorController;
|
|
|
|
Pinetime::Drivers::Hrs3300& heartRateSensor;
|
|
|
|
Pinetime::Drivers::Bma421& motionSensor;
|
|
|
|
Pinetime::Controllers::Settings& settingsController;
|
2021-06-06 15:56:03 +02:00
|
|
|
Pinetime::Controllers::HeartRateController& heartRateController;
|
|
|
|
Pinetime::Controllers::MotionController& motionController;
|
|
|
|
|
|
|
|
Pinetime::Applications::DisplayApp& displayApp;
|
|
|
|
Pinetime::Applications::HeartRateTask& heartRateApp;
|
2021-07-11 15:06:06 +02:00
|
|
|
Pinetime::Controllers::FS& fs;
|
2021-07-16 00:49:20 +02:00
|
|
|
Pinetime::Controllers::TouchHandler& touchHandler;
|
2021-07-11 15:06:06 +02:00
|
|
|
Pinetime::Controllers::NimbleController nimbleController;
|
2021-04-18 19:28:14 +02:00
|
|
|
|
|
|
|
static void Process(void* instance);
|
|
|
|
void Work();
|
2021-07-24 20:29:10 +02:00
|
|
|
void ReloadIdleTimer();
|
2021-04-18 19:28:14 +02:00
|
|
|
bool isBleDiscoveryTimerRunning = false;
|
|
|
|
uint8_t bleDiscoveryTimer = 0;
|
2021-07-24 20:29:10 +02:00
|
|
|
TimerHandle_t dimTimer;
|
2021-04-18 19:28:14 +02:00
|
|
|
TimerHandle_t idleTimer;
|
2021-08-14 20:18:11 +02:00
|
|
|
TimerHandle_t measureBatteryTimer;
|
|
|
|
bool sendBatteryNotification = false;
|
2021-04-18 19:28:14 +02:00
|
|
|
bool doNotGoToSleep = false;
|
|
|
|
|
|
|
|
void GoToRunning();
|
|
|
|
void UpdateMotion();
|
|
|
|
bool stepCounterMustBeReset = false;
|
2021-08-14 20:18:11 +02:00
|
|
|
static constexpr TickType_t batteryMeasurementPeriod = pdMS_TO_TICKS(10 * 60 * 1000);
|
|
|
|
TickType_t lastBatteryNotificationTime = 0;
|
2020-07-02 21:38:52 +02:00
|
|
|
|
|
|
|
#if configUSE_TRACE_FACILITY == 1
|
2021-04-18 19:28:14 +02:00
|
|
|
SystemMonitor<FreeRtosMonitor> monitor;
|
2020-07-02 21:38:52 +02:00
|
|
|
#else
|
2021-04-18 19:28:14 +02:00
|
|
|
SystemMonitor<DummyMonitor> monitor;
|
2020-07-02 21:38:52 +02:00
|
|
|
#endif
|
2020-02-23 13:44:39 +01:00
|
|
|
};
|
|
|
|
}
|
2020-07-11 22:37:28 +02:00
|
|
|
}
|