2020-02-23 07:44:39 -05:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-02 15:16:48 -04:00
|
|
|
#include <memory>
|
|
|
|
|
2020-02-23 07:44:39 -05:00
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <task.h>
|
2020-11-15 09:05:51 -05:00
|
|
|
#include <timers.h>
|
2021-01-10 11:57:26 -05:00
|
|
|
#include <heartratetask/HeartRateTask.h>
|
|
|
|
#include <components/heartrate/HeartRateController.h>
|
2021-03-20 06:41:49 -04:00
|
|
|
#include <components/settings/Settings.h>
|
2021-03-31 13:47:27 -04:00
|
|
|
#include <drivers/Bma421.h>
|
|
|
|
#include <components/motion/MotionController.h>
|
2020-11-15 09:05:51 -05:00
|
|
|
|
2020-07-02 15:38:52 -04:00
|
|
|
#include "SystemMonitor.h"
|
2020-11-15 09:05:51 -05:00
|
|
|
#include "components/battery/BatteryController.h"
|
2020-10-02 15:16:48 -04:00
|
|
|
#include "components/ble/NimbleController.h"
|
2020-11-15 09:05:51 -05:00
|
|
|
#include "components/ble/NotificationManager.h"
|
2021-01-25 10:47:52 -05:00
|
|
|
#include "components/motor/MotorController.h"
|
2021-05-20 14:43:54 -04:00
|
|
|
#include "components/timer/TimerController.h"
|
2021-01-26 14:31:45 -05:00
|
|
|
#ifdef PINETIME_IS_RECOVERY
|
2021-04-18 13:28:14 -04:00
|
|
|
#include "displayapp/DisplayAppRecovery.h"
|
|
|
|
#include "displayapp/DummyLittleVgl.h"
|
2021-01-26 14:31:45 -05:00
|
|
|
#else
|
2021-04-18 13:28:14 -04:00
|
|
|
#include "components/settings/Settings.h"
|
|
|
|
#include "displayapp/DisplayApp.h"
|
|
|
|
#include "displayapp/LittleVgl.h"
|
2021-01-26 14:31:45 -05:00
|
|
|
#endif
|
|
|
|
|
2020-11-15 09:05:51 -05:00
|
|
|
#include "drivers/Watchdog.h"
|
2020-02-23 07:44:39 -05:00
|
|
|
|
|
|
|
namespace Pinetime {
|
2020-11-15 09:05:51 -05:00
|
|
|
namespace Drivers {
|
|
|
|
class Cst816S;
|
|
|
|
class SpiMaster;
|
|
|
|
class SpiNorFlash;
|
|
|
|
class St7789;
|
|
|
|
class TwiMaster;
|
2021-01-10 11:57:26 -05:00
|
|
|
class Hrs3300;
|
2020-11-15 09:05:51 -05:00
|
|
|
}
|
2020-02-23 07:44:39 -05:00
|
|
|
namespace System {
|
|
|
|
class SystemTask {
|
2021-04-24 05:00:45 -04:00
|
|
|
public:
|
2021-04-18 13:28:14 -04:00
|
|
|
enum class Messages {
|
|
|
|
GoToSleep,
|
|
|
|
GoToRunning,
|
|
|
|
TouchWakeUp,
|
|
|
|
OnNewTime,
|
|
|
|
OnNewNotification,
|
2021-05-20 14:43:54 -04:00
|
|
|
OnTimerDone,
|
2021-04-18 13:28:14 -04:00
|
|
|
OnNewCall,
|
|
|
|
BleConnected,
|
|
|
|
UpdateTimeOut,
|
|
|
|
BleFirmwareUpdateStarted,
|
|
|
|
BleFirmwareUpdateFinished,
|
|
|
|
OnTouchEvent,
|
|
|
|
OnButtonEvent,
|
|
|
|
OnDisplayTaskSleeping,
|
|
|
|
EnableSleeping,
|
|
|
|
DisableSleeping,
|
2021-05-16 15:13:22 -04:00
|
|
|
OnNewDay,
|
|
|
|
OnChargingEvent
|
2021-04-18 13:28:14 -04: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,
|
|
|
|
Pinetime::Controllers::MotorController& motorController,
|
|
|
|
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
|
|
|
Pinetime::Drivers::Bma421& motionSensor,
|
|
|
|
Controllers::Settings& settingsController);
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
void PushMessage(Messages msg);
|
|
|
|
|
|
|
|
void OnButtonPushed();
|
|
|
|
void OnTouchEvent();
|
|
|
|
|
|
|
|
void OnIdle();
|
|
|
|
|
|
|
|
Pinetime::Controllers::NimbleController& nimble() {
|
|
|
|
return nimbleController;
|
|
|
|
};
|
|
|
|
|
2021-04-24 05:00:45 -04:00
|
|
|
private:
|
2021-04-18 13:28:14 -04: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;
|
|
|
|
std::unique_ptr<Pinetime::Applications::DisplayApp> displayApp;
|
|
|
|
Pinetime::Controllers::HeartRateController heartRateController;
|
|
|
|
std::unique_ptr<Pinetime::Applications::HeartRateTask> heartRateApp;
|
|
|
|
|
|
|
|
Pinetime::Controllers::Ble& bleController;
|
|
|
|
Pinetime::Controllers::DateTime dateTimeController;
|
2021-05-20 14:43:54 -04:00
|
|
|
Pinetime::Controllers::TimerController timerController;
|
2021-04-18 13:28:14 -04:00
|
|
|
QueueHandle_t systemTasksMsgQueue;
|
|
|
|
std::atomic<bool> isSleeping {false};
|
|
|
|
std::atomic<bool> isGoingToSleep {false};
|
|
|
|
std::atomic<bool> isWakingUp {false};
|
|
|
|
Pinetime::Drivers::Watchdog watchdog;
|
|
|
|
Pinetime::Drivers::WatchdogView watchdogView;
|
|
|
|
Pinetime::Controllers::NotificationManager notificationManager;
|
|
|
|
Pinetime::Controllers::MotorController& motorController;
|
|
|
|
Pinetime::Drivers::Hrs3300& heartRateSensor;
|
|
|
|
Pinetime::Drivers::Bma421& motionSensor;
|
|
|
|
Pinetime::Controllers::Settings& settingsController;
|
|
|
|
Pinetime::Controllers::NimbleController nimbleController;
|
|
|
|
Controllers::BrightnessController brightnessController;
|
|
|
|
Pinetime::Controllers::MotionController motionController;
|
|
|
|
|
|
|
|
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;
|
2021-05-16 15:13:22 -04:00
|
|
|
static constexpr uint8_t pinPowerPresentIrq = 19;
|
2021-04-18 13:28:14 -04:00
|
|
|
|
|
|
|
static void Process(void* instance);
|
|
|
|
void Work();
|
|
|
|
void ReloadIdleTimer() const;
|
|
|
|
bool isBleDiscoveryTimerRunning = false;
|
|
|
|
uint8_t bleDiscoveryTimer = 0;
|
|
|
|
TimerHandle_t idleTimer;
|
|
|
|
bool doNotGoToSleep = false;
|
|
|
|
|
|
|
|
void GoToRunning();
|
|
|
|
void UpdateMotion();
|
|
|
|
bool stepCounterMustBeReset = false;
|
2020-07-02 15:38:52 -04:00
|
|
|
|
|
|
|
#if configUSE_TRACE_FACILITY == 1
|
2021-04-18 13:28:14 -04:00
|
|
|
SystemMonitor<FreeRtosMonitor> monitor;
|
2020-07-02 15:38:52 -04:00
|
|
|
#else
|
2021-04-18 13:28:14 -04:00
|
|
|
SystemMonitor<DummyMonitor> monitor;
|
2020-07-02 15:38:52 -04:00
|
|
|
#endif
|
2020-02-23 07:44:39 -05:00
|
|
|
};
|
|
|
|
}
|
2020-07-11 16:37:28 -04:00
|
|
|
}
|