InfiniTime/src/systemtask/SystemTask.h

154 lines
5.4 KiB
C
Raw Normal View History

#pragma once
#include <memory>
#include <FreeRTOS.h>
#include <queue.h>
#include <task.h>
2020-11-15 14:05:51 +00:00
#include <timers.h>
#include <heartratetask/HeartRateTask.h>
#include <components/settings/Settings.h>
#include <drivers/Bma421.h>
2021-08-02 19:37:48 +00:00
#include <drivers/PinMap.h>
#include <components/motion/MotionController.h>
2020-11-15 14:05:51 +00:00
#include "systemtask/SystemMonitor.h"
#include "components/ble/NimbleController.h"
2020-11-15 14:05:51 +00:00
#include "components/ble/NotificationManager.h"
#include "components/motor/MotorController.h"
#include "components/timer/TimerController.h"
2021-09-10 22:40:13 +00:00
#include "components/alarm/AlarmController.h"
#include "components/fs/FS.h"
2021-07-15 22:49:20 +00:00
#include "touchhandler/TouchHandler.h"
2021-10-25 09:53:14 +00:00
#include "buttonhandler/ButtonHandler.h"
#include "buttonhandler/ButtonActions.h"
#ifdef PINETIME_IS_RECOVERY
#include "displayapp/DisplayAppRecovery.h"
#include "displayapp/DummyLittleVgl.h"
#else
#include "components/settings/Settings.h"
#include "displayapp/DisplayApp.h"
2021-07-15 22:49:20 +00:00
#include "displayapp/LittleVgl.h"
#endif
2020-11-15 14:05:51 +00:00
#include "drivers/Watchdog.h"
#include "systemtask/Messages.h"
2021-08-19 00:51:12 +00:00
extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime;
namespace Pinetime {
2020-11-15 14:05:51 +00:00
namespace Drivers {
class Cst816S;
class SpiMaster;
class SpiNorFlash;
class St7789;
class TwiMaster;
class Hrs3300;
2020-11-15 14:05:51 +00:00
}
2021-07-15 22:49:20 +00:00
namespace Controllers {
class Battery;
2021-07-15 22:49:20 +00:00
class TouchHandler;
2021-10-25 09:53:14 +00:00
class ButtonHandler;
2021-07-15 22:49:20 +00:00
}
namespace System {
class SystemTask {
2021-04-24 09:00:45 +00:00
public:
enum class SystemTaskState { Sleeping, Running, GoingToSleep, WakingUp };
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,
Controllers::DateTime& dateTimeController,
Controllers::TimerController& timerController,
2021-09-10 22:40:13 +00:00
Controllers::AlarmController& alarmController,
Drivers::Watchdog& watchdog,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Drivers::Hrs3300& heartRateSensor,
Pinetime::Controllers::MotionController& motionController,
Pinetime::Drivers::Bma421& motionSensor,
Controllers::Settings& settingsController,
Pinetime::Controllers::HeartRateController& heartRateController,
Pinetime::Applications::DisplayApp& displayApp,
Pinetime::Applications::HeartRateTask& heartRateApp,
2021-07-15 22:49:20 +00:00
Pinetime::Controllers::FS& fs,
2021-10-25 09:53:14 +00:00
Pinetime::Controllers::TouchHandler& touchHandler,
Pinetime::Controllers::ButtonHandler& buttonHandler);
void Start();
void PushMessage(Messages msg);
void OnTouchEvent();
void OnIdle();
void OnDim();
Pinetime::Controllers::NimbleController& nimble() {
return nimbleController;
};
bool IsSleeping() const {
return state == SystemTaskState::Sleeping || state == SystemTaskState::WakingUp;
}
2021-04-24 09:00:45 +00:00
private:
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;
Pinetime::Controllers::Ble& bleController;
Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::TimerController& timerController;
2021-09-10 22:40:13 +00:00
Pinetime::Controllers::AlarmController& alarmController;
QueueHandle_t systemTasksMsgQueue;
Pinetime::Drivers::Watchdog& watchdog;
Pinetime::Controllers::NotificationManager& notificationManager;
Pinetime::Controllers::MotorController& motorController;
Pinetime::Drivers::Hrs3300& heartRateSensor;
Pinetime::Drivers::Bma421& motionSensor;
Pinetime::Controllers::Settings& settingsController;
Pinetime::Controllers::HeartRateController& heartRateController;
Pinetime::Controllers::MotionController& motionController;
Pinetime::Applications::DisplayApp& displayApp;
Pinetime::Applications::HeartRateTask& heartRateApp;
Pinetime::Controllers::FS& fs;
2021-07-15 22:49:20 +00:00
Pinetime::Controllers::TouchHandler& touchHandler;
2021-10-25 09:53:14 +00:00
Pinetime::Controllers::ButtonHandler& buttonHandler;
Pinetime::Controllers::NimbleController nimbleController;
static void Process(void* instance);
void Work();
void ReloadIdleTimer();
bool isBleDiscoveryTimerRunning = false;
uint8_t bleDiscoveryTimer = 0;
TimerHandle_t dimTimer;
TimerHandle_t idleTimer;
TimerHandle_t measureBatteryTimer;
bool doNotGoToSleep = false;
2021-07-30 18:43:44 +00:00
bool isDimmed = false;
SystemTaskState state = SystemTaskState::Running;
void HandleButtonAction(Controllers::ButtonActions action);
bool fastWakeUpDone = false;
void GoToRunning();
void UpdateMotion();
bool stepCounterMustBeReset = false;
static constexpr TickType_t batteryMeasurementPeriod = pdMS_TO_TICKS(10 * 60 * 1000);
SystemMonitor monitor;
};
}
2020-07-11 20:37:28 +00:00
}