Skip to content

Commit faec69e

Browse files
committed
rebase on main
1 parent c5d2e42 commit faec69e

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/heartratetask/HeartRateTask.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void HeartRateTask::Process(void* instance) {
2424
}
2525

2626
void HeartRateTask::Work() {
27-
lastBpm = 0;
27+
int lastBpm = 0;
2828

2929
while (true) {
3030
auto delay = CurrentTaskDelay();
@@ -75,7 +75,7 @@ void HeartRateTask::Work() {
7575
if (state == States::BackgroundWaiting) {
7676
HandleBackgroundWaiting();
7777
} else if (state == States::BackgroundMeasuring || state == States::Measuring) {
78-
HandleSensorData();
78+
HandleSensorData(&lastBpm);
7979
}
8080
}
8181
}
@@ -108,32 +108,28 @@ void HeartRateTask::HandleBackgroundWaiting() {
108108
}
109109
}
110110

111-
void HeartRateTask::HandleSensorData() {
111+
void HeartRateTask::HandleSensorData(int* lastBpm) {
112112
int8_t ambient = ppg.Preprocess(heartRateSensor.ReadHrs(), heartRateSensor.ReadAls());
113113
int bpm = ppg.HeartRate();
114114

115115
// If ambient light detected or a reset requested (bpm < 0)
116116
if (ambient > 0) {
117117
// Reset all DAQ buffers
118118
ppg.Reset(true);
119-
// Force state to NotEnoughData (below)
120-
lastBpm = 0;
121-
bpm = 0;
122119
} else if (bpm < 0) {
123120
// Reset all DAQ buffers except HRS buffer
124121
ppg.Reset(false);
125122
// Set HR to zero and update
126123
bpm = 0;
127-
controller.Update(Controllers::HeartRateController::States::Running, bpm);
128124
}
129125

130-
if (lastBpm == 0 && bpm == 0) {
126+
if (*lastBpm == 0 && bpm == 0) {
131127
controller.Update(Controllers::HeartRateController::States::NotEnoughData, bpm);
132128
}
133129

134130
if (bpm != 0) {
135-
lastBpm = bpm;
136-
controller.Update(Controllers::HeartRateController::States::Running, lastBpm);
131+
*lastBpm = bpm;
132+
controller.Update(Controllers::HeartRateController::States::Running, bpm);
137133
if (state == States::BackgroundMeasuring) {
138134
StopMeasurement();
139135
state = States::BackgroundWaiting;

src/heartratetask/HeartRateTask.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace Pinetime {
3232
void StopMeasurement();
3333

3434
void HandleBackgroundWaiting();
35-
void HandleSensorData();
35+
void HandleSensorData(int* lastBpm);
3636
int CurrentTaskDelay();
3737

3838
TaskHandle_t taskHandle;
@@ -41,7 +41,6 @@ namespace Pinetime {
4141
Drivers::Hrs3300& heartRateSensor;
4242
Controllers::HeartRateController& controller;
4343
Controllers::Ppg ppg;
44-
int lastBpm = 0;
4544
TickType_t backgroundMeasurementWaitingStart = 0;
4645
};
4746

0 commit comments

Comments
 (0)