Skip to content

Commit 4609da5

Browse files
committed
Merge branch 'heartrate-measurements-in-background' of github.com:patricgruber/InfiniTime into heartrate-measurements-in-background
2 parents 5737b95 + a06b882 commit 4609da5

File tree

3 files changed

+77
-25
lines changed

3 files changed

+77
-25
lines changed

src/displayapp/screens/settings/SettingHeartRate.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@ namespace {
1515
}
1616
}
1717

18-
constexpr std::array<Option, 8> SettingHeartRate::options;
19-
2018
SettingHeartRate::SettingHeartRate(Pinetime::Controllers::Settings& settingsController) : settingsController {settingsController} {
2119

22-
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
20+
lv_obj_t* container = lv_cont_create(lv_scr_act(), nullptr);
2321

24-
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
25-
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
26-
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
27-
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
22+
lv_obj_set_style_local_bg_opa(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
23+
lv_obj_set_style_local_pad_all(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
24+
lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
25+
lv_obj_set_style_local_border_width(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
2826

29-
lv_obj_set_pos(container1, 10, 60);
30-
lv_obj_set_width(container1, LV_HOR_RES - 20);
31-
lv_obj_set_height(container1, LV_VER_RES - 50);
32-
lv_cont_set_layout(container1, LV_LAYOUT_PRETTY_TOP);
27+
lv_obj_set_pos(container, 10, 60);
28+
lv_obj_set_width(container, LV_HOR_RES - 20);
29+
lv_obj_set_height(container, LV_VER_RES - 50);
30+
lv_cont_set_layout(container, LV_LAYOUT_PRETTY_TOP);
3331

3432
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
3533
lv_label_set_text_static(title, "Backg. Interval");
@@ -47,7 +45,7 @@ SettingHeartRate::SettingHeartRate(Pinetime::Controllers::Settings& settingsCont
4745
unsigned int currentInterval = settingsController.GetHeartRateBackgroundMeasurementInterval();
4846

4947
for (unsigned int i = 0; i < options.size(); i++) {
50-
cbOption[i] = lv_checkbox_create(container1, nullptr);
48+
cbOption[i] = lv_checkbox_create(container, nullptr);
5149
lv_checkbox_set_text(cbOption[i], options[i].name);
5250
cbOption[i]->user_data = this;
5351
lv_obj_set_event_cb(cbOption[i], event_handler);

src/heartratetask/HeartRateTask.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,22 @@ void HeartRateTask::HandleSensorData(int* lastBpm) {
156156
}
157157

158158
if (ShouldStartBackgroundMeasuring()) {
159-
// This doesn't change the state but resets the measurment timer, which basically starts the next measurment without resetting the
160-
// sensor. This is basically a fall back to continuous mode, when measurments take too long.
159+
// This doesn't change the state but resets the measurement timer, which basically starts the next measurement without resetting the
160+
// sensor. This is basically a fall back to continuous mode, when measurements take too long.
161161
measurementStart = xTaskGetTickCount();
162162
return;
163163
}
164164

165-
bool noDataWithinTimeLimit = bpm == 0 && ShoudStopTryingToGetData();
166-
bool dataWithinTimeLimit = bpm != 0;
167-
if (dataWithinTimeLimit || noDataWithinTimeLimit) {
168-
isBackgroundMeasuring = false;
169-
StopSensor();
165+
bool dataTimeout = bpm == 0 && ShouldStopTryingToGetData();
166+
bool foundHeartrate = bpm != 0;
167+
if (foundHeartrate || dataTimeout) {
168+
state = States::ScreenOffAndWaiting;
169+
StopMeasurement();
170170
}
171171
}
172172

173173
TickType_t HeartRateTask::GetBackgroundIntervalInTicks() {
174-
int ms = settings.GetHeartRateBackgroundMeasurementInterval() * 1000;
175-
return pdMS_TO_TICKS(ms);
174+
return settings.GetHeartRateBackgroundMeasurementInterval() * configTICK_RATE_HZ;
176175
}
177176

178177
bool HeartRateTask::IsContinuousModeActivated() {
@@ -187,10 +186,10 @@ TickType_t HeartRateTask::GetTicksSinceLastMeasurementStarted() {
187186
return xTaskGetTickCount() - measurementStart;
188187
}
189188

190-
bool HeartRateTask::ShoudStopTryingToGetData() {
191-
return GetTicksSinceLastMeasurementStarted() >= DURATION_UNTIL_BACKGROUND_MEASUREMENT_IS_STOPPED;
189+
bool HeartRateTask::ShouldStopTryingToGetData() {
190+
return GetTicksSinceLastMeasurementStarted() >= durationUntilBackgroundMeasurementIsStopped;
192191
}
193192

194193
bool HeartRateTask::ShouldStartBackgroundMeasuring() {
195194
return GetTicksSinceLastMeasurementStarted() >= GetBackgroundIntervalInTicks();
196-
}
195+
}

src/heartratetask/HeartRateTask.h

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,61 @@
55
#include <components/heartrate/Ppg.h>
66
#include "components/settings/Settings.h"
77

8+
<<<<<<< HEAD
89
#define DURATION_UNTIL_BACKGROUND_MEASUREMENT_IS_STOPPED pdMS_TO_TICKS(30 * 1000)
10+
=======
11+
/*
12+
*** Background Measurement deactivated ***
13+
14+
15+
16+
┌─────────────────────────┐ ┌─────────────────────────┐
17+
│ ├───StartMeasurement───►│ │
18+
│ ScreenOnAndStopped │ │ ScreenOnAndMeasuring │
19+
│ │◄──StopMeasurement │ │
20+
└──▲────────────────┬─────┘ └──▲──────────────────┬───┘
21+
│ │ │ │
22+
WakeUp GoToSleep WakeUp GoToSleep
23+
│ │ │ │
24+
┌──┴────────────────▼─────┐ ┌──┴──────────────────▼───┐
25+
│ │ │ │
26+
│ ScreenOffAndStopped │ │ ScreenOffAndWaiting │
27+
│ │ │ │
28+
└─────────────────────────┘ └─────────────────────────┘
29+
30+
31+
32+
33+
34+
*** Background Measurement activated ***
35+
36+
37+
38+
┌─────────────────────────┐ ┌─────────────────────────┐
39+
│ ├───StartMeasurement───►│ │
40+
│ ScreenOnAndStopped │ │ ScreenOnAndMeasuring │
41+
│ │◄──StopMeasurement │ │
42+
└──▲────────────────┬─────┘ └──▲──────────────────┬───┘
43+
│ │ ┌───────┘ │
44+
WakeUp GoToSleep │ WakeUp GoToSleep
45+
│ │ │ │ │
46+
┌──┴────────────────▼─────┐ │ ┌──┴──────────────────▼───┐
47+
│ │ │ │ │
48+
│ ScreenOffAndStopped │ │ │ ScreenOffAndWating │
49+
│ │ │ │ │
50+
└─────────────────────────┘ │ └───┬──────────────────▲──┘
51+
│ │ │
52+
│ Waited Got sensor
53+
│ interval data
54+
│ time │
55+
│ │ │
56+
WakeUp ┌───▼──────────────────┴──┐
57+
│ │ │
58+
└────┤ ScreenOffAndMeasuring │
59+
│ │
60+
└─────────────────────────┘
61+
*/
62+
>>>>>>> a06b88260051c89f0017d42c64c9b831be522be7
963

1064
namespace Pinetime {
1165
namespace Drivers {
@@ -27,6 +81,7 @@ namespace Pinetime {
2781
void Start();
2882
void Work();
2983
void PushMessage(Messages msg);
84+
static constexpr int durationUntilBackgroundMeasurementIsStopped = pdMS_TO_TICKS(30 * 1000);
3085

3186
private:
3287
static void Process(void* instance);
@@ -46,7 +101,7 @@ namespace Pinetime {
46101
bool IsBackgroundMeasurementActivated();
47102

48103
TickType_t GetTicksSinceLastMeasurementStarted();
49-
bool ShoudStopTryingToGetData();
104+
bool ShouldStopTryingToGetData();
50105
bool ShouldStartBackgroundMeasuring();
51106

52107
TaskHandle_t taskHandle;

0 commit comments

Comments
 (0)