@@ -24,7 +24,7 @@ void HeartRateTask::Process(void* instance) {
2424}
2525
2626void 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;
0 commit comments