1
0
Fork 0
InfiniTime/src/systemtask/SystemTask.h

143 lines
4.7 KiB
C
Raw Normal View History

#pragma once
#include <memory>
#include <FreeRTOS.h>
#include <task.h>
2020-11-15 15:05:51 +01:00
#include <timers.h>
#include <heartratetask/HeartRateTask.h>
#include <components/settings/Settings.h>
#include <drivers/Bma421.h>
#include <components/motion/MotionController.h>
2020-11-15 15:05:51 +01:00
#include "SystemMonitor.h"
2020-11-15 15:05:51 +01:00
#include "components/battery/BatteryController.h"
#include "components/ble/NimbleController.h"
2020-11-15 15:05:51 +01:00
#include "components/ble/NotificationManager.h"
#include "components/motor/MotorController.h"
#include "components/timer/TimerController.h"
#ifdef PINETIME_IS_RECOVERY
#include "displayapp/DisplayAppRecovery.h"
#include "displayapp/DummyLittleVgl.h"
#else
#include "components/settings/Settings.h"
#include "displayapp/DisplayApp.h"
#include "displayapp/LittleVgl.h"
#endif
2020-11-15 15:05:51 +01:00
#include "drivers/Watchdog.h"
#include "Messages.h"
namespace Pinetime {
2020-11-15 15:05:51 +01:00
namespace Drivers {
class Cst816S;
class SpiMaster;
class SpiNorFlash;
class St7789;
class TwiMaster;
class Hrs3300;
2020-11-15 15:05:51 +01:00
}
namespace System {
class SystemTask {
2021-04-24 11:00:45 +02:00
public:
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,
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);
void Start();
void PushMessage(Messages msg);
void OnButtonPushed();
void OnTouchEvent();
void OnIdle();
Pinetime::Controllers::NimbleController& nimble() {
return nimbleController;
};
bool IsSleeping() const {
return isSleeping;
}
2021-04-24 11:00:45 +02: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;
QueueHandle_t systemTasksMsgQueue;
std::atomic<bool> isSleeping {false};
std::atomic<bool> isGoingToSleep {false};
std::atomic<bool> isWakingUp {false};
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::NimbleController nimbleController;
Controllers::BrightnessController brightnessController;
Pinetime::Controllers::MotionController& motionController;
Pinetime::Applications::DisplayApp& displayApp;
Pinetime::Applications::HeartRateTask& heartRateApp;
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 constexpr uint8_t pinPowerPresentIrq = 19;
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;
#if configUSE_TRACE_FACILITY == 1
SystemMonitor<FreeRtosMonitor> monitor;
#else
SystemMonitor<DummyMonitor> monitor;
#endif
};
}
2020-07-11 22:37:28 +02:00
}