2021-10-13 16:08:35 -04:00
|
|
|
#include "displayapp/screens/HeartRate.h"
|
2021-11-05 18:55:34 -04:00
|
|
|
#include <lvgl/lvgl.h>
|
2021-01-10 11:57:26 -05:00
|
|
|
#include <components/heartrate/HeartRateController.h>
|
|
|
|
|
2021-10-13 16:08:35 -04:00
|
|
|
#include "displayapp/DisplayApp.h"
|
2021-01-10 11:57:26 -05:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-01-17 04:39:46 -05:00
|
|
|
namespace {
|
2021-04-18 13:28:14 -04:00
|
|
|
const char* ToString(Pinetime::Controllers::HeartRateController::States s) {
|
2021-01-17 04:39:46 -05:00
|
|
|
switch (s) {
|
|
|
|
case Pinetime::Controllers::HeartRateController::States::NotEnoughData:
|
|
|
|
return "Not enough data,\nplease wait...";
|
|
|
|
case Pinetime::Controllers::HeartRateController::States::NoTouch:
|
|
|
|
return "No touch detected";
|
|
|
|
case Pinetime::Controllers::HeartRateController::States::Running:
|
|
|
|
return "Measuring...";
|
|
|
|
case Pinetime::Controllers::HeartRateController::States::Stopped:
|
|
|
|
return "Stopped";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2022-04-09 06:37:31 -04:00
|
|
|
void btnStartStopEventHandler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
auto* screen = static_cast<HeartRate*>(obj->user_data);
|
2021-01-17 04:39:46 -05:00
|
|
|
screen->OnStartStopEvent(event);
|
2021-01-10 11:57:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
HeartRate::HeartRate(Pinetime::Applications::DisplayApp* app,
|
|
|
|
Controllers::HeartRateController& heartRateController,
|
|
|
|
System::SystemTask& systemTask)
|
|
|
|
: Screen(app), heartRateController {heartRateController}, systemTask {systemTask} {
|
2021-04-18 07:50:38 -04:00
|
|
|
bool isHrRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
|
2021-04-03 22:08:51 -04:00
|
|
|
label_hr = lv_label_create(lv_scr_act(), nullptr);
|
2021-01-10 11:57:26 -05:00
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_style_local_text_font(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
|
2021-04-18 07:50:38 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
if (isHrRunning)
|
2022-04-22 16:26:38 -04:00
|
|
|
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x0, 0xb0, 0x0));
|
2021-04-18 07:50:38 -04:00
|
|
|
else
|
2022-04-22 16:26:38 -04:00
|
|
|
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
|
2021-04-18 07:50:38 -04:00
|
|
|
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(label_hr, "000");
|
2021-04-18 13:28:14 -04:00
|
|
|
lv_obj_align(label_hr, nullptr, LV_ALIGN_CENTER, 0, -40);
|
2021-01-10 11:57:26 -05:00
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
label_bpm = lv_label_create(lv_scr_act(), nullptr);
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(label_bpm, "Heart rate BPM");
|
2021-01-10 11:57:26 -05:00
|
|
|
lv_obj_align(label_bpm, label_hr, LV_ALIGN_OUT_TOP_MID, 0, -20);
|
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
label_status = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(label_status, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222));
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(label_status, ToString(Pinetime::Controllers::HeartRateController::States::NotEnoughData));
|
2021-04-18 13:28:14 -04:00
|
|
|
|
2021-01-17 04:39:46 -05:00
|
|
|
lv_obj_align(label_status, label_hr, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
2021-01-10 11:57:26 -05:00
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
btn_startStop = lv_btn_create(lv_scr_act(), nullptr);
|
2021-01-17 04:39:46 -05:00
|
|
|
btn_startStop->user_data = this;
|
|
|
|
lv_obj_set_height(btn_startStop, 50);
|
|
|
|
lv_obj_set_event_cb(btn_startStop, btnStartStopEventHandler);
|
|
|
|
lv_obj_align(btn_startStop, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
|
|
|
|
|
|
|
label_startStop = lv_label_create(btn_startStop, nullptr);
|
2021-04-18 07:50:38 -04:00
|
|
|
UpdateStartStopButton(isHrRunning);
|
2021-04-18 13:28:14 -04:00
|
|
|
if (isHrRunning)
|
2021-06-06 09:56:03 -04:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
|
2021-07-19 09:26:12 -04:00
|
|
|
|
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
|
2021-01-10 11:57:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
HeartRate::~HeartRate() {
|
2021-07-19 09:26:12 -04:00
|
|
|
lv_task_del(taskRefresh);
|
2021-01-10 11:57:26 -05:00
|
|
|
lv_obj_clean(lv_scr_act());
|
2021-06-06 09:56:03 -04:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
|
2021-01-10 11:57:26 -05:00
|
|
|
}
|
|
|
|
|
2021-07-19 09:26:12 -04:00
|
|
|
void HeartRate::Refresh() {
|
2021-01-10 11:57:26 -05:00
|
|
|
|
|
|
|
auto state = heartRateController.State();
|
2021-04-18 13:28:14 -04:00
|
|
|
switch (state) {
|
2021-01-10 11:57:26 -05:00
|
|
|
case Controllers::HeartRateController::States::NoTouch:
|
|
|
|
case Controllers::HeartRateController::States::NotEnoughData:
|
2021-04-18 13:28:14 -04:00
|
|
|
// case Controllers::HeartRateController::States::Stopped:
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(label_hr, "000");
|
2021-01-10 11:57:26 -05:00
|
|
|
break;
|
|
|
|
default:
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_label_set_text_fmt(label_hr, "%03d", heartRateController.HeartRate());
|
2021-01-10 11:57:26 -05:00
|
|
|
}
|
|
|
|
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(label_status, ToString(state));
|
2021-01-17 04:39:46 -05:00
|
|
|
lv_obj_align(label_status, label_hr, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
2021-01-10 11:57:26 -05:00
|
|
|
}
|
|
|
|
|
2021-01-17 04:39:46 -05:00
|
|
|
void HeartRate::OnStartStopEvent(lv_event_t event) {
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
2021-04-18 13:28:14 -04:00
|
|
|
if (heartRateController.State() == Controllers::HeartRateController::States::Stopped) {
|
2021-01-17 04:39:46 -05:00
|
|
|
heartRateController.Start();
|
|
|
|
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
|
2021-06-06 09:56:03 -04:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
|
2022-04-22 16:26:38 -04:00
|
|
|
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x0, 0xb0, 0x0));
|
2021-04-18 13:28:14 -04:00
|
|
|
} else {
|
2021-01-17 04:39:46 -05:00
|
|
|
heartRateController.Stop();
|
|
|
|
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
|
2021-06-06 09:56:03 -04:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
|
2022-04-22 16:26:38 -04:00
|
|
|
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
|
2021-01-17 04:39:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HeartRate::UpdateStartStopButton(bool isRunning) {
|
2021-04-18 13:28:14 -04:00
|
|
|
if (isRunning)
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(label_startStop, "Stop");
|
2021-01-17 04:39:46 -05:00
|
|
|
else
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(label_startStop, "Start");
|
2021-01-17 04:39:46 -05:00
|
|
|
}
|