HR Sensor : do not go to sleep when the HR app is running.

This commit is contained in:
Jean-François Milants 2021-01-10 22:02:21 +01:00
parent 1a582815ba
commit c82c22650c
4 changed files with 28 additions and 3 deletions

View file

@ -1,23 +1,34 @@
#include "HeartRateController.h" #include "HeartRateController.h"
#include <heartratetask/HeartRateTask.h> #include <heartratetask/HeartRateTask.h>
#include <systemtask/SystemTask.h>
using namespace Pinetime::Controllers; using namespace Pinetime::Controllers;
HeartRateController::HeartRateController(Pinetime::System::SystemTask &systemTask) : systemTask{systemTask} {
}
void HeartRateController::Update(HeartRateController::States newState, uint8_t heartRate) { void HeartRateController::Update(HeartRateController::States newState, uint8_t heartRate) {
this->state = newState; this->state = newState;
this->heartRate = heartRate; this->heartRate = heartRate;
} }
void HeartRateController::Start() { void HeartRateController::Start() {
if(task != nullptr) if(task != nullptr) {
task->PushMessage(Pinetime::Applications::HeartRateTask::Messages::StartMeasurement); task->PushMessage(Pinetime::Applications::HeartRateTask::Messages::StartMeasurement);
systemTask.PushMessage(System::SystemTask::Messages::HeartRateRunning);
}
} }
void HeartRateController::Stop() { void HeartRateController::Stop() {
if(task != nullptr) if(task != nullptr) {
task->PushMessage(Pinetime::Applications::HeartRateTask::Messages::StopMeasurement); task->PushMessage(Pinetime::Applications::HeartRateTask::Messages::StopMeasurement);
systemTask.PushMessage(System::SystemTask::Messages::HeartRateStopped);
}
} }
void HeartRateController::SetHeartRateTask(Pinetime::Applications::HeartRateTask *task) { void HeartRateController::SetHeartRateTask(Pinetime::Applications::HeartRateTask *task) {
this->task = task; this->task = task;
} }

View file

@ -6,11 +6,16 @@ namespace Pinetime {
namespace Applications { namespace Applications {
class HeartRateTask; class HeartRateTask;
} }
namespace System {
class SystemTask;
}
namespace Controllers { namespace Controllers {
class HeartRateController { class HeartRateController {
public: public:
enum class States { NotEnoughData, NoTouch, Running}; enum class States { NotEnoughData, NoTouch, Running};
explicit HeartRateController(System::SystemTask& systemTask);
void Start(); void Start();
void Stop(); void Stop();
void Update(States newState, uint8_t heartRate); void Update(States newState, uint8_t heartRate);
@ -20,6 +25,7 @@ namespace Pinetime {
uint8_t HeartRate() const { return heartRate; } uint8_t HeartRate() const { return heartRate; }
private: private:
System::SystemTask& systemTask;
Applications::HeartRateTask* task = nullptr; Applications::HeartRateTask* task = nullptr;
States state = States::NotEnoughData; States state = States::NotEnoughData;
uint8_t heartRate = 0; uint8_t heartRate = 0;

View file

@ -44,6 +44,7 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
Pinetime::Drivers::Hrs3300& heartRateSensor) : Pinetime::Drivers::Hrs3300& heartRateSensor) :
spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash}, spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash},
twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController},
heartRateController{*this},
bleController{bleController}, dateTimeController{dateTimeController}, bleController{bleController}, dateTimeController{dateTimeController},
watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager},
nimbleController(*this, bleController,dateTimeController, notificationManager, batteryController, spiNorFlash), nimbleController(*this, bleController,dateTimeController, notificationManager, batteryController, spiNorFlash),
@ -194,6 +195,12 @@ void SystemTask::Work() {
isSleeping = true; isSleeping = true;
isGoingToSleep = false; isGoingToSleep = false;
break; break;
case Messages::HeartRateRunning:
doNotGoToSleep = true;
break;
case Messages::HeartRateStopped:
doNotGoToSleep = false;
break;
default: break; default: break;
} }
} }

View file

@ -28,7 +28,8 @@ namespace Pinetime {
class SystemTask { class SystemTask {
public: public:
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected, enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected,
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping,
HeartRateRunning, HeartRateStopped
}; };
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,