Skip to content

Commit 30c0fdc

Browse files
committed
Add bar for daily exercise target completion
Add screen title text Anticipate resting heart rate tracking (some max heart rate tracking algorithms use this)
1 parent a317bd3 commit 30c0fdc

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

src/components/heartrate/HeartRateController.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using namespace Pinetime::Controllers;
77
HeartRateZoneSettings::HeartRateZoneSettings() {
88
version = 0;
99
adjustMsDelay = 300000;
10+
exerciseMsTarget = 1800000;
1011
age = 25;
1112
maxHeartRate = maxHeartRateEstimate(age);
1213
percentTarget = {50, 60, 70, 80, 90};

src/components/heartrate/HeartRateController.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Pinetime {
1919
template <typename T>
2020
struct HeartRateZones {
2121
// 1440 minutes in a day (11 bits), 86400 seconds (17 bits)
22-
std::array<T,5> zoneTime = {};
22+
std::array<T, 5> zoneTime = {};
2323

2424
T totalTime() const {
2525
return zoneTime[0] + zoneTime[1] + zoneTime[2] + zoneTime[3] + zoneTime[4];
@@ -49,7 +49,8 @@ namespace Pinetime {
4949

5050
struct HeartRateZoneSettings {
5151
uint32_t version = 0;
52-
uint32_t adjustMsDelay = 300000;
52+
uint32_t adjustMsDelay = 300000; // 5 minutes
53+
uint32_t exerciseMsTarget = 1800000; // hour 3600'000
5354
uint8_t age = 25;
5455
uint8_t maxHeartRate = 195;
5556
std::array<uint8_t, 5> percentTarget = {50, 60, 70, 80, 90};
@@ -86,6 +87,10 @@ namespace Pinetime {
8687
return currentActivity;
8788
}
8889

90+
HeartRateZoneSettings hrzSettings() const {
91+
return zSettings;
92+
}
93+
8994
void SetService(Pinetime::Controllers::HeartRateService* service);
9095

9196
void AdvanceDay();
@@ -95,6 +100,7 @@ namespace Pinetime {
95100
Applications::HeartRateTask* task = nullptr;
96101
States state = States::Stopped;
97102
uint8_t heartRate = 0;
103+
uint8_t restingHeartRate = 0;
98104
Pinetime::Controllers::HeartRateService* service = nullptr;
99105
Pinetime::Controllers::FS& fs;
100106

src/displayapp/screens/HeartRateZone.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,35 @@ using namespace Pinetime::Applications::Screens;
1010
HeartRateZone::HeartRateZone(Controllers::HeartRateController& heartRateController, System::SystemTask& systemTask)
1111
: heartRateController {heartRateController}, wakeLock(systemTask) {
1212
auto activity = heartRateController.Activity();
13+
auto settings = heartRateController.hrzSettings();
1314
uint32_t total = 0;
1415

15-
auto hundreths_of_hour = pdMS_TO_TICKS(10*60*60);
16+
auto hundreths_of_hour = pdMS_TO_TICKS(10 * 60 * 60);
17+
auto exercise_target = pdMS_TO_TICKS(settings.exerciseMsTarget);
18+
uint32_t offset = 25 * (zone_bar.size() + 2);
1619

1720
lv_obj_t* screen = lv_scr_act();
21+
22+
title = lv_label_create(screen);
23+
lv_label_set_text_static(title, "BPM Breakdown");
24+
lv_obj_align(title, screen, LV_ALIGN_IN_TOP_MID, 0, 20);
25+
26+
total_bar = lv_bar_create(screen, nullptr);
27+
lv_obj_set_style_local_bg_opa(zone_bar[i], LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_OPA_0);
28+
lv_obj_set_style_local_line_color(zone_bar[i], LV_BAR_PART_BG, LV_STATE_DEFAULT, Colors::bgAlt);
29+
lv_obj_set_style_local_border_width(zone_bar[i], LV_BAR_PART_BG, LV_STATE_DEFAULT, 2);
30+
lv_obj_set_style_local_radius(zone_bar[i], LV_BAR_PART_BG, LV_STATE_DEFAULT, 0);
31+
lv_obj_set_style_local_line_color(zone_bar[0], LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_NAVY);
32+
33+
lv_obj_align(total_bar, screen, LV_ALIGN_IN_TOP_MID, 0, offset - (zone_bar.size() * 25));
34+
35+
total_label = lv_label_create(zone_bar[i], nullptr);
36+
lv_obj_align(total_label, zone_bar[i], LV_ALIGN_CENTER, 0, 0);
37+
lv_obj_set_style_local_text_color(total_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN);
38+
1839
for (uint8_t i = 0; i < zone_bar.size(); i++) {
1940
zone_bar[i] = lv_bar_create(screen, nullptr);
20-
41+
2142
total += activity.zoneTime[i];
2243

2344
lv_obj_set_style_local_bg_opa(zone_bar[i], LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_OPA_0);
@@ -26,9 +47,9 @@ HeartRateZone::HeartRateZone(Controllers::HeartRateController& heartRateControll
2647
lv_obj_set_style_local_radius(zone_bar[i], LV_BAR_PART_BG, LV_STATE_DEFAULT, 0);
2748

2849
lv_obj_set_size(zone_bar[i], 240, 20);
29-
lv_obj_align(zone_bar[i], screen, LV_ALIGN_IN_TOP_MID, 0, 25 * i);
50+
lv_obj_align(zone_bar[i], screen, LV_ALIGN_IN_TOP_MID, 0, offset - i * 25);
3051

31-
label_time[i] = lv_label_create(zone_bar[i],nullptr);
52+
label_time[i] = lv_label_create(zone_bar[i], nullptr);
3253
lv_obj_align(label_time[i], zone_bar[i], LV_ALIGN_CENTER, 0, 0);
3354

3455
lv_obj_set_style_local_text_color(label_time[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN);
@@ -39,6 +60,7 @@ HeartRateZone::HeartRateZone(Controllers::HeartRateController& heartRateControll
3960
lv_label_set_text_static(label_time[2], "Aerobic");
4061
lv_label_set_text_static(label_time[3], "Threshold");
4162
lv_label_set_text_static(label_time[4], "Anaerobic");
63+
lv_label_set_text_static(total_label, "Goal");
4264

4365
lv_obj_set_style_local_line_color(zone_bar[0], LV_BAR_PART_INDIC, LV_STATE_DEFAULT, Colors::blue);
4466
lv_obj_set_style_local_line_color(zone_bar[1], LV_BAR_PART_INDIC, LV_STATE_DEFAULT, Colors::green);
@@ -54,6 +76,9 @@ HeartRateZone::HeartRateZone(Controllers::HeartRateController& heartRateControll
5476
lv_bar_set_value(zone_bar[i], percent, LV_ANIM_OFF);
5577
}
5678

79+
lv_bar_set_range(total_bar, 0, exercise_target);
80+
lv_bar_set_value(total_bar, total > exercise_target ? exercise_target : total, LV_ANIM_OFF);
81+
5782
taskRefresh = lv_task_create(RefreshTaskCallback, 5000, LV_TASK_PRIO_MID, this);
5883
}
5984

@@ -79,4 +104,7 @@ void HeartRateZone::Refresh() {
79104
lv_bar_set_range(zone_bar[i], 0, bar_limit);
80105
lv_bar_set_value(zone_bar[i], percent, LV_ANIM_OFF);
81106
}
107+
108+
lv_bar_set_range(total_bar, 0, exercise_target);
109+
lv_bar_set_value(total_bar, total > exercise_target ? exercise_target : total, LV_ANIM_OFF);
82110
}

src/displayapp/screens/HeartRateZone.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ namespace Pinetime {
2929
Controllers::HeartRateController& heartRateController;
3030
Pinetime::System::WakeLock wakeLock;
3131

32-
std::array<lv_obj_t*,5> zone_bar;
33-
std::array<lv_obj_t*,5> label_time;
32+
std::array<lv_obj_t*, 5> zone_bar = {};
33+
std::array<lv_obj_t*, 5> label_time = {};
34+
lv_obj_t* total_bar = nullptr;
35+
lv_obj_t* total_label = nullptr;
36+
lv_obj_t* title = nullptr;
3437

3538
lv_task_t* taskRefresh;
3639
};

0 commit comments

Comments
 (0)