2021-01-10 17:57:26 +01:00
|
|
|
#include <libs/lvgl/lvgl.h>
|
|
|
|
#include "HeartRate.h"
|
|
|
|
#include <components/heartrate/HeartRateController.h>
|
|
|
|
|
|
|
|
#include "../DisplayApp.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-01-17 10:39:46 +01:00
|
|
|
namespace {
|
|
|
|
const char *ToString(Pinetime::Controllers::HeartRateController::States s) {
|
|
|
|
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 "";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void btnStartStopEventHandler(lv_obj_t *obj, lv_event_t event) {
|
|
|
|
HeartRate *screen = static_cast<HeartRate *>(obj->user_data);
|
|
|
|
screen->OnStartStopEvent(event);
|
2021-01-10 17:57:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
HeartRate::HeartRate(Pinetime::Applications::DisplayApp *app, Controllers::HeartRateController& heartRateController, System::SystemTask &systemTask) :
|
|
|
|
Screen(app), heartRateController{heartRateController}, systemTask{systemTask} {
|
2021-01-28 18:13:28 +01:00
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
label_hr = lv_label_create(lv_scr_act(), nullptr);
|
2021-01-10 17:57:26 +01:00
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_obj_set_style_local_text_font(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
|
|
|
|
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
2021-01-10 17:57:26 +01:00
|
|
|
lv_label_set_text(label_hr, "000");
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_obj_align(label_hr, nullptr, LV_ALIGN_CENTER, 0, -40);
|
2021-01-10 17:57:26 +01:00
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
label_bpm = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_text(label_bpm, "Heart rate BPM");
|
2021-01-10 17:57:26 +01:00
|
|
|
lv_obj_align(label_bpm, label_hr, LV_ALIGN_OUT_TOP_MID, 0, -20);
|
|
|
|
|
|
|
|
|
2021-04-04 04:08:51 +02: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));
|
2021-01-10 17:57:26 +01:00
|
|
|
lv_label_set_text(label_status, ToString(Pinetime::Controllers::HeartRateController::States::NotEnoughData));
|
2021-01-28 18:13:28 +01:00
|
|
|
|
2021-01-17 10:39:46 +01:00
|
|
|
lv_obj_align(label_status, label_hr, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
2021-01-10 17:57:26 +01:00
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
btn_startStop = lv_btn_create(lv_scr_act(), nullptr);
|
2021-01-17 10:39:46 +01: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);
|
|
|
|
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
|
2021-01-10 17:57:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HeartRate::~HeartRate() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
2021-04-04 04:08:51 +02:00
|
|
|
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::EnableSleeping);
|
2021-01-10 17:57:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HeartRate::Refresh() {
|
|
|
|
|
|
|
|
auto state = heartRateController.State();
|
|
|
|
switch(state) {
|
|
|
|
case Controllers::HeartRateController::States::NoTouch:
|
|
|
|
case Controllers::HeartRateController::States::NotEnoughData:
|
2021-04-04 04:08:51 +02:00
|
|
|
//case Controllers::HeartRateController::States::Stopped:
|
2021-01-10 17:57:26 +01:00
|
|
|
lv_label_set_text(label_hr, "000");
|
|
|
|
break;
|
|
|
|
default:
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_label_set_text_fmt(label_hr, "%03d", heartRateController.HeartRate());
|
2021-01-10 17:57:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lv_label_set_text(label_status, ToString(state));
|
2021-01-17 10:39:46 +01:00
|
|
|
lv_obj_align(label_status, label_hr, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
2021-01-10 17:57:26 +01:00
|
|
|
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
2021-01-17 10:39:46 +01:00
|
|
|
void HeartRate::OnStartStopEvent(lv_event_t event) {
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
if(heartRateController.State() == Controllers::HeartRateController::States::Stopped) {
|
|
|
|
heartRateController.Start();
|
|
|
|
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
|
2021-04-04 04:08:51 +02:00
|
|
|
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::DisableSleeping);
|
|
|
|
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
2021-01-17 10:39:46 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
heartRateController.Stop();
|
|
|
|
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
|
2021-04-04 04:08:51 +02:00
|
|
|
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::EnableSleeping);
|
|
|
|
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
2021-01-17 10:39:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HeartRate::UpdateStartStopButton(bool isRunning) {
|
|
|
|
if(isRunning)
|
|
|
|
lv_label_set_text(label_startStop, "Stop");
|
|
|
|
else
|
|
|
|
lv_label_set_text(label_startStop, "Start");
|
|
|
|
}
|