Skip to content

Commit

Permalink
rebase on main
Browse files Browse the repository at this point in the history
  • Loading branch information
patricgruber committed May 11, 2023
1 parent c5d2e42 commit faec69e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
16 changes: 6 additions & 10 deletions src/heartratetask/HeartRateTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void HeartRateTask::Process(void* instance) {
}

void HeartRateTask::Work() {
lastBpm = 0;
int lastBpm = 0;

while (true) {
auto delay = CurrentTaskDelay();
Expand Down Expand Up @@ -75,7 +75,7 @@ void HeartRateTask::Work() {
if (state == States::BackgroundWaiting) {
HandleBackgroundWaiting();
} else if (state == States::BackgroundMeasuring || state == States::Measuring) {
HandleSensorData();
HandleSensorData(&lastBpm);
}
}
}
Expand Down Expand Up @@ -108,32 +108,28 @@ void HeartRateTask::HandleBackgroundWaiting() {
}
}

void HeartRateTask::HandleSensorData() {
void HeartRateTask::HandleSensorData(int* lastBpm) {
int8_t ambient = ppg.Preprocess(heartRateSensor.ReadHrs(), heartRateSensor.ReadAls());
int bpm = ppg.HeartRate();

// If ambient light detected or a reset requested (bpm < 0)
if (ambient > 0) {
// Reset all DAQ buffers
ppg.Reset(true);
// Force state to NotEnoughData (below)
lastBpm = 0;
bpm = 0;
} else if (bpm < 0) {
// Reset all DAQ buffers except HRS buffer
ppg.Reset(false);
// Set HR to zero and update
bpm = 0;
controller.Update(Controllers::HeartRateController::States::Running, bpm);
}

if (lastBpm == 0 && bpm == 0) {
if (*lastBpm == 0 && bpm == 0) {
controller.Update(Controllers::HeartRateController::States::NotEnoughData, bpm);
}

if (bpm != 0) {
lastBpm = bpm;
controller.Update(Controllers::HeartRateController::States::Running, lastBpm);
*lastBpm = bpm;
controller.Update(Controllers::HeartRateController::States::Running, bpm);
if (state == States::BackgroundMeasuring) {
StopMeasurement();
state = States::BackgroundWaiting;
Expand Down
3 changes: 1 addition & 2 deletions src/heartratetask/HeartRateTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Pinetime {
void StopMeasurement();

void HandleBackgroundWaiting();
void HandleSensorData();
void HandleSensorData(int* lastBpm);
int CurrentTaskDelay();

TaskHandle_t taskHandle;
Expand All @@ -41,7 +41,6 @@ namespace Pinetime {
Drivers::Hrs3300& heartRateSensor;
Controllers::HeartRateController& controller;
Controllers::Ppg ppg;
int lastBpm = 0;
TickType_t backgroundMeasurementWaitingStart = 0;
};

Expand Down

0 comments on commit faec69e

Please sign in to comment.