use interval as interval, instead of wait time
This commit is contained in:
parent
7df39994ab
commit
462ea11bd4
|
@ -53,7 +53,7 @@ namespace Pinetime {
|
||||||
enum class HeartRateBackgroundMeasurementInterval : uint8_t {
|
enum class HeartRateBackgroundMeasurementInterval : uint8_t {
|
||||||
Off,
|
Off,
|
||||||
Continuous,
|
Continuous,
|
||||||
TenSeconds,
|
FifteenSeconds,
|
||||||
ThirtySeconds,
|
ThirtySeconds,
|
||||||
OneMinute,
|
OneMinute,
|
||||||
FiveMinutes,
|
FiveMinutes,
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace Pinetime {
|
||||||
static constexpr std::array<Option, 8> options = {{
|
static constexpr std::array<Option, 8> options = {{
|
||||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Off, " Off"},
|
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Off, " Off"},
|
||||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Continuous, "Cont"},
|
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Continuous, "Cont"},
|
||||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::TenSeconds, " 10s"},
|
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::FifteenSeconds, " 15s"},
|
||||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtySeconds, " 30s"},
|
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtySeconds, " 30s"},
|
||||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::OneMinute, " 1m"},
|
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::OneMinute, " 1m"},
|
||||||
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::FiveMinutes, " 5m"},
|
{Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::FiveMinutes, " 5m"},
|
||||||
|
|
|
@ -97,11 +97,6 @@ void HeartRateTask::StopMeasurement() {
|
||||||
vTaskDelay(100);
|
vTaskDelay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartRateTask::StartWaiting() {
|
|
||||||
StopMeasurement();
|
|
||||||
backgroundWaitingStart = xTaskGetTickCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HeartRateTask::HandleGoToSleep() {
|
void HeartRateTask::HandleGoToSleep() {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case States::ScreenOnAndStopped:
|
case States::ScreenOnAndStopped:
|
||||||
|
@ -176,8 +171,7 @@ void HeartRateTask::HandleBackgroundWaiting() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TickType_t ticksSinceWaitingStart = xTaskGetTickCount() - backgroundWaitingStart;
|
if (ShouldStartBackgroundMeasuring()) {
|
||||||
if (ticksSinceWaitingStart >= GetHeartRateBackgroundMeasurementIntervalInTicks()) {
|
|
||||||
state = States::ScreenOffAndMeasuring;
|
state = States::ScreenOffAndMeasuring;
|
||||||
StartMeasurement();
|
StartMeasurement();
|
||||||
}
|
}
|
||||||
|
@ -198,34 +192,45 @@ void HeartRateTask::HandleSensorData(int* lastBpm) {
|
||||||
bpm = 0;
|
bpm = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*lastBpm == 0 && bpm == 0) {
|
bool notEnoughData = *lastBpm == 0 && bpm == 0;
|
||||||
|
if (notEnoughData) {
|
||||||
controller.Update(Controllers::HeartRateController::States::NotEnoughData, bpm);
|
controller.Update(Controllers::HeartRateController::States::NotEnoughData, bpm);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bpm != 0) {
|
if (bpm != 0) {
|
||||||
*lastBpm = bpm;
|
*lastBpm = bpm;
|
||||||
controller.Update(Controllers::HeartRateController::States::Running, bpm);
|
controller.Update(Controllers::HeartRateController::States::Running, bpm);
|
||||||
if (state == States::ScreenOnAndMeasuring || IsContinuousModeActivated()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (state == States::ScreenOffAndMeasuring) {
|
|
||||||
state = States::ScreenOffAndWaiting;
|
|
||||||
StartWaiting();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
TickType_t ticksSinceMeasurementStart = xTaskGetTickCount() - measurementStart;
|
|
||||||
if (bpm == 0 && state == States::ScreenOffAndMeasuring && !IsContinuousModeActivated() &&
|
if (state == States::ScreenOnAndMeasuring || IsContinuousModeActivated()) {
|
||||||
ticksSinceMeasurementStart >= DURATION_UNTIL_BACKGROUND_MEASUREMENT_IS_STOPPED) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// state == States::ScreenOffAndMeasuring
|
||||||
|
// (because state != ScreenOnAndMeasuring and the only state that enables measuring is ScreenOffAndMeasuring)
|
||||||
|
// !IsContinuousModeActivated()
|
||||||
|
|
||||||
|
if (ShouldStartBackgroundMeasuring()) {
|
||||||
|
// This doesn't change the state but resets the measurment timer, which basically starts the next measurment without resetting the sensor.
|
||||||
|
// This is basically a fall back to continuous mode, when measurments take too long.
|
||||||
|
measurementStart = xTaskGetTickCount();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool noDataWithinTimeLimit = bpm == 0 && ShoudStopTryingToGetData();
|
||||||
|
bool dataWithinTimeLimit = bpm != 0;
|
||||||
|
if (dataWithinTimeLimit || noDataWithinTimeLimit) {
|
||||||
state = States::ScreenOffAndWaiting;
|
state = States::ScreenOffAndWaiting;
|
||||||
StartWaiting();
|
StopMeasurement();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TickType_t HeartRateTask::GetHeartRateBackgroundMeasurementIntervalInTicks() {
|
TickType_t HeartRateTask::GetHeartRateBackgroundMeasurementIntervalInTicks() {
|
||||||
int ms;
|
int ms;
|
||||||
switch (settings.GetHeartRateBackgroundMeasurementInterval()) {
|
switch (settings.GetHeartRateBackgroundMeasurementInterval()) {
|
||||||
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::TenSeconds:
|
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::FifteenSeconds:
|
||||||
ms = 10 * 1000;
|
ms = 15 * 1000;
|
||||||
break;
|
break;
|
||||||
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtySeconds:
|
case Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::ThirtySeconds:
|
||||||
ms = 30 * 1000;
|
ms = 30 * 1000;
|
||||||
|
@ -258,3 +263,15 @@ bool HeartRateTask::IsBackgroundMeasurementActivated() {
|
||||||
return settings.GetHeartRateBackgroundMeasurementInterval() !=
|
return settings.GetHeartRateBackgroundMeasurementInterval() !=
|
||||||
Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Off;
|
Pinetime::Controllers::Settings::HeartRateBackgroundMeasurementInterval::Off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TickType_t HeartRateTask::GetTicksSinceLastMeasurementStarted() {
|
||||||
|
return xTaskGetTickCount() - measurementStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HeartRateTask::ShoudStopTryingToGetData() {
|
||||||
|
return GetTicksSinceLastMeasurementStarted() >= DURATION_UNTIL_BACKGROUND_MEASUREMENT_IS_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HeartRateTask::ShouldStartBackgroundMeasuring() {
|
||||||
|
return GetTicksSinceLastMeasurementStarted() >= GetHeartRateBackgroundMeasurementIntervalInTicks();
|
||||||
|
}
|
|
@ -45,7 +45,6 @@ namespace Pinetime {
|
||||||
static void Process(void* instance);
|
static void Process(void* instance);
|
||||||
void StartMeasurement();
|
void StartMeasurement();
|
||||||
void StopMeasurement();
|
void StopMeasurement();
|
||||||
void StartWaiting();
|
|
||||||
|
|
||||||
void HandleGoToSleep();
|
void HandleGoToSleep();
|
||||||
void HandleWakeUp();
|
void HandleWakeUp();
|
||||||
|
@ -59,6 +58,10 @@ namespace Pinetime {
|
||||||
bool IsContinuousModeActivated();
|
bool IsContinuousModeActivated();
|
||||||
bool IsBackgroundMeasurementActivated();
|
bool IsBackgroundMeasurementActivated();
|
||||||
|
|
||||||
|
TickType_t GetTicksSinceLastMeasurementStarted();
|
||||||
|
bool ShoudStopTryingToGetData();
|
||||||
|
bool ShouldStartBackgroundMeasuring();
|
||||||
|
|
||||||
TaskHandle_t taskHandle;
|
TaskHandle_t taskHandle;
|
||||||
QueueHandle_t messageQueue;
|
QueueHandle_t messageQueue;
|
||||||
States state = States::ScreenOnAndStopped;
|
States state = States::ScreenOnAndStopped;
|
||||||
|
@ -66,7 +69,6 @@ namespace Pinetime {
|
||||||
Controllers::HeartRateController& controller;
|
Controllers::HeartRateController& controller;
|
||||||
Controllers::Settings& settings;
|
Controllers::Settings& settings;
|
||||||
Controllers::Ppg ppg;
|
Controllers::Ppg ppg;
|
||||||
TickType_t backgroundWaitingStart = 0;
|
|
||||||
TickType_t measurementStart = 0;
|
TickType_t measurementStart = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue