use better state names
This commit is contained in:
parent
b846547f2f
commit
9501d36060
|
@ -7,12 +7,12 @@ using namespace Pinetime::Applications;
|
||||||
|
|
||||||
TickType_t CurrentTaskDelay(HeartRateTask::States state, TickType_t ppgDeltaTms) {
|
TickType_t CurrentTaskDelay(HeartRateTask::States state, TickType_t ppgDeltaTms) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case HeartRateTask::States::Measuring:
|
case HeartRateTask::States::ScreenOnAndMeasuring:
|
||||||
case HeartRateTask::States::BackgroundMeasuring:
|
case HeartRateTask::States::ScreenOffAndMeasuring:
|
||||||
return ppgDeltaTms;
|
return ppgDeltaTms;
|
||||||
case HeartRateTask::States::Running:
|
case HeartRateTask::States::ScreenOnAndStopped:
|
||||||
return pdMS_TO_TICKS(100);
|
return pdMS_TO_TICKS(100);
|
||||||
case HeartRateTask::States::BackgroundWaiting:
|
case HeartRateTask::States::ScreenOffAndWaiting:
|
||||||
return pdMS_TO_TICKS(10000);
|
return pdMS_TO_TICKS(10000);
|
||||||
default:
|
default:
|
||||||
return portMAX_DELAY;
|
return portMAX_DELAY;
|
||||||
|
@ -65,15 +65,15 @@ void HeartRateTask::Work() {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case States::BackgroundWaiting:
|
case States::ScreenOffAndWaiting:
|
||||||
HandleBackgroundWaiting();
|
HandleBackgroundWaiting();
|
||||||
break;
|
break;
|
||||||
case States::BackgroundMeasuring:
|
case States::ScreenOffAndMeasuring:
|
||||||
case States::Measuring:
|
case States::ScreenOnAndMeasuring:
|
||||||
HandleSensorData(&lastBpm);
|
HandleSensorData(&lastBpm);
|
||||||
break;
|
break;
|
||||||
case States::Idle:
|
case States::ScreenOffAndStopped:
|
||||||
case States::Running:
|
case States::ScreenOnAndStopped:
|
||||||
// nothing to do -> ignore
|
// nothing to do -> ignore
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -106,15 +106,15 @@ void HeartRateTask::StartWaiting() {
|
||||||
|
|
||||||
void HeartRateTask::HandleGoToSleep() {
|
void HeartRateTask::HandleGoToSleep() {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case States::Running:
|
case States::ScreenOnAndStopped:
|
||||||
state = States::Idle;
|
state = States::ScreenOffAndStopped;
|
||||||
break;
|
break;
|
||||||
case States::Measuring:
|
case States::ScreenOnAndMeasuring:
|
||||||
state = States::BackgroundMeasuring;
|
state = States::ScreenOffAndMeasuring;
|
||||||
break;
|
break;
|
||||||
case States::Idle:
|
case States::ScreenOffAndStopped:
|
||||||
case States::BackgroundWaiting:
|
case States::ScreenOffAndWaiting:
|
||||||
case States::BackgroundMeasuring:
|
case States::ScreenOffAndMeasuring:
|
||||||
// shouldn't happen -> ignore
|
// shouldn't happen -> ignore
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -122,18 +122,18 @@ void HeartRateTask::HandleGoToSleep() {
|
||||||
|
|
||||||
void HeartRateTask::HandleWakeUp() {
|
void HeartRateTask::HandleWakeUp() {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case States::Idle:
|
case States::ScreenOffAndStopped:
|
||||||
state = States::Running;
|
state = States::ScreenOnAndStopped;
|
||||||
break;
|
break;
|
||||||
case States::BackgroundMeasuring:
|
case States::ScreenOffAndMeasuring:
|
||||||
state = States::Measuring;
|
state = States::ScreenOnAndMeasuring;
|
||||||
break;
|
break;
|
||||||
case States::BackgroundWaiting:
|
case States::ScreenOffAndWaiting:
|
||||||
state = States::Measuring;
|
state = States::ScreenOnAndMeasuring;
|
||||||
StartMeasurement();
|
StartMeasurement();
|
||||||
break;
|
break;
|
||||||
case States::Running:
|
case States::ScreenOnAndStopped:
|
||||||
case States::Measuring:
|
case States::ScreenOnAndMeasuring:
|
||||||
// shouldn't happen -> ignore
|
// shouldn't happen -> ignore
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -141,15 +141,15 @@ void HeartRateTask::HandleWakeUp() {
|
||||||
|
|
||||||
void HeartRateTask::HandleStartMeasurement(int* lastBpm) {
|
void HeartRateTask::HandleStartMeasurement(int* lastBpm) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case States::Idle:
|
case States::ScreenOffAndStopped:
|
||||||
case States::Running:
|
case States::ScreenOnAndStopped:
|
||||||
state = States::Measuring;
|
state = States::ScreenOnAndMeasuring;
|
||||||
*lastBpm = 0;
|
*lastBpm = 0;
|
||||||
StartMeasurement();
|
StartMeasurement();
|
||||||
break;
|
break;
|
||||||
case States::Measuring:
|
case States::ScreenOnAndMeasuring:
|
||||||
case States::BackgroundMeasuring:
|
case States::ScreenOffAndMeasuring:
|
||||||
case States::BackgroundWaiting:
|
case States::ScreenOffAndWaiting:
|
||||||
// shouldn't happen -> ignore
|
// shouldn't happen -> ignore
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -157,17 +157,17 @@ void HeartRateTask::HandleStartMeasurement(int* lastBpm) {
|
||||||
|
|
||||||
void HeartRateTask::HandleStopMeasurement() {
|
void HeartRateTask::HandleStopMeasurement() {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case States::Measuring:
|
case States::ScreenOnAndMeasuring:
|
||||||
state = States::Running;
|
state = States::ScreenOnAndStopped;
|
||||||
StopMeasurement();
|
StopMeasurement();
|
||||||
break;
|
break;
|
||||||
case States::BackgroundMeasuring:
|
case States::ScreenOffAndMeasuring:
|
||||||
case States::BackgroundWaiting:
|
case States::ScreenOffAndWaiting:
|
||||||
state = States::Idle;
|
state = States::ScreenOffAndStopped;
|
||||||
StopMeasurement();
|
StopMeasurement();
|
||||||
break;
|
break;
|
||||||
case States::Running:
|
case States::ScreenOnAndStopped:
|
||||||
case States::Idle:
|
case States::ScreenOffAndStopped:
|
||||||
// shouldn't happen -> ignore
|
// shouldn't happen -> ignore
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ void HeartRateTask::HandleBackgroundWaiting() {
|
||||||
|
|
||||||
TickType_t ticksSinceWaitingStart = xTaskGetTickCount() - backgroundWaitingStart;
|
TickType_t ticksSinceWaitingStart = xTaskGetTickCount() - backgroundWaitingStart;
|
||||||
if (ticksSinceWaitingStart >= GetHeartRateBackgroundMeasurementIntervalInTicks()) {
|
if (ticksSinceWaitingStart >= GetHeartRateBackgroundMeasurementIntervalInTicks()) {
|
||||||
state = States::BackgroundMeasuring;
|
state = States::ScreenOffAndMeasuring;
|
||||||
StartMeasurement();
|
StartMeasurement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,18 +207,18 @@ void HeartRateTask::HandleSensorData(int* lastBpm) {
|
||||||
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::Measuring || IsContinuosModeActivated()) {
|
if (state == States::ScreenOnAndMeasuring || IsContinuosModeActivated()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state == States::BackgroundMeasuring) {
|
if (state == States::ScreenOffAndMeasuring) {
|
||||||
state = States::BackgroundWaiting;
|
state = States::ScreenOffAndWaiting;
|
||||||
StartWaiting();
|
StartWaiting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TickType_t ticksSinceMeasurementStart = xTaskGetTickCount() - measurementStart;
|
TickType_t ticksSinceMeasurementStart = xTaskGetTickCount() - measurementStart;
|
||||||
if (bpm == 0 && state == States::BackgroundMeasuring && !IsContinuosModeActivated() &&
|
if (bpm == 0 && state == States::ScreenOffAndMeasuring && !IsContinuosModeActivated() &&
|
||||||
ticksSinceMeasurementStart >= DURATION_UNTIL_BACKGROUND_MEASUREMENT_IS_STOPPED) {
|
ticksSinceMeasurementStart >= DURATION_UNTIL_BACKGROUND_MEASUREMENT_IS_STOPPED) {
|
||||||
state = States::BackgroundWaiting;
|
state = States::ScreenOffAndWaiting;
|
||||||
StartWaiting();
|
StartWaiting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,27 +20,18 @@ namespace Pinetime {
|
||||||
class HeartRateTask {
|
class HeartRateTask {
|
||||||
public:
|
public:
|
||||||
enum class Messages : uint8_t {
|
enum class Messages : uint8_t {
|
||||||
// Screen gets turned off
|
|
||||||
GoToSleep,
|
GoToSleep,
|
||||||
// Screen gets turned on
|
|
||||||
WakeUp,
|
WakeUp,
|
||||||
// Start button pressed
|
|
||||||
StartMeasurement,
|
StartMeasurement,
|
||||||
// Stop button pressed
|
|
||||||
StopMeasurement
|
StopMeasurement
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class States {
|
enum class States {
|
||||||
// Screen turned off, heartrate not measured
|
ScreenOnAndStopped,
|
||||||
Idle,
|
ScreenOnAndMeasuring,
|
||||||
// Screen turned on, heartrate app open, heartrate not measured
|
ScreenOffAndStopped,
|
||||||
Running,
|
ScreenOffAndWaiting,
|
||||||
// Screen turned on, heartrate app open, heartrate actively measured
|
ScreenOffAndMeasuring
|
||||||
Measuring,
|
|
||||||
// Screen turned off, heartrate task is waiting until the next measurement should be started
|
|
||||||
BackgroundWaiting,
|
|
||||||
// Screen turned off, heartrate actively measured
|
|
||||||
BackgroundMeasuring
|
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit HeartRateTask(Drivers::Hrs3300& heartRateSensor,
|
explicit HeartRateTask(Drivers::Hrs3300& heartRateSensor,
|
||||||
|
@ -70,7 +61,7 @@ namespace Pinetime {
|
||||||
|
|
||||||
TaskHandle_t taskHandle;
|
TaskHandle_t taskHandle;
|
||||||
QueueHandle_t messageQueue;
|
QueueHandle_t messageQueue;
|
||||||
States state = States::Running;
|
States state = States::ScreenOnAndStopped;
|
||||||
Drivers::Hrs3300& heartRateSensor;
|
Drivers::Hrs3300& heartRateSensor;
|
||||||
Controllers::HeartRateController& controller;
|
Controllers::HeartRateController& controller;
|
||||||
Controllers::Settings& settings;
|
Controllers::Settings& settings;
|
||||||
|
|
Loading…
Reference in a new issue