@@ -24,7 +24,7 @@ void HeartRateTask::Process(void* instance) {
24
24
}
25
25
26
26
void HeartRateTask::Work () {
27
- lastBpm = 0 ;
27
+ int lastBpm = 0 ;
28
28
29
29
while (true ) {
30
30
auto delay = CurrentTaskDelay ();
@@ -75,7 +75,7 @@ void HeartRateTask::Work() {
75
75
if (state == States::BackgroundWaiting) {
76
76
HandleBackgroundWaiting ();
77
77
} else if (state == States::BackgroundMeasuring || state == States::Measuring) {
78
- HandleSensorData ();
78
+ HandleSensorData (&lastBpm );
79
79
}
80
80
}
81
81
}
@@ -108,32 +108,28 @@ void HeartRateTask::HandleBackgroundWaiting() {
108
108
}
109
109
}
110
110
111
- void HeartRateTask::HandleSensorData () {
111
+ void HeartRateTask::HandleSensorData (int * lastBpm ) {
112
112
int8_t ambient = ppg.Preprocess (heartRateSensor.ReadHrs (), heartRateSensor.ReadAls ());
113
113
int bpm = ppg.HeartRate ();
114
114
115
115
// If ambient light detected or a reset requested (bpm < 0)
116
116
if (ambient > 0 ) {
117
117
// Reset all DAQ buffers
118
118
ppg.Reset (true );
119
- // Force state to NotEnoughData (below)
120
- lastBpm = 0 ;
121
- bpm = 0 ;
122
119
} else if (bpm < 0 ) {
123
120
// Reset all DAQ buffers except HRS buffer
124
121
ppg.Reset (false );
125
122
// Set HR to zero and update
126
123
bpm = 0 ;
127
- controller.Update (Controllers::HeartRateController::States::Running, bpm);
128
124
}
129
125
130
- if (lastBpm == 0 && bpm == 0 ) {
126
+ if (* lastBpm == 0 && bpm == 0 ) {
131
127
controller.Update (Controllers::HeartRateController::States::NotEnoughData, bpm);
132
128
}
133
129
134
130
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 );
137
133
if (state == States::BackgroundMeasuring) {
138
134
StopMeasurement ();
139
135
state = States::BackgroundWaiting;
0 commit comments