2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/screens/Steps.h"
|
2021-04-19 14:28:38 +00:00
|
|
|
#include <lvgl/lvgl.h>
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/DisplayApp.h"
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
2021-04-19 14:28:38 +00:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-10-20 03:42:48 +00:00
|
|
|
static void lap_event_handler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
auto* steps = static_cast<Steps*>(obj->user_data);
|
|
|
|
steps->lapBtnEventHandler(event);
|
|
|
|
}
|
|
|
|
|
2021-07-25 14:54:05 +00:00
|
|
|
Steps::Steps(Pinetime::Applications::DisplayApp* app,
|
|
|
|
Controllers::MotionController& motionController,
|
|
|
|
Controllers::Settings& settingsController)
|
|
|
|
: Screen(app), motionController {motionController}, settingsController {settingsController} {
|
2021-04-19 14:28:38 +00:00
|
|
|
|
|
|
|
stepsArc = lv_arc_create(lv_scr_act(), nullptr);
|
|
|
|
|
2021-07-04 18:06:50 +00:00
|
|
|
lv_obj_set_style_local_bg_opa(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, LV_OPA_0);
|
|
|
|
lv_obj_set_style_local_border_width(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 2);
|
|
|
|
lv_obj_set_style_local_radius(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0);
|
|
|
|
lv_obj_set_style_local_line_color(stepsArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, lv_color_hex(0x0000FF));
|
2021-04-19 14:28:38 +00:00
|
|
|
lv_arc_set_end_angle(stepsArc, 200);
|
2021-10-20 18:29:10 +00:00
|
|
|
lv_obj_set_size(stepsArc, 240, 240);
|
2021-04-19 14:28:38 +00:00
|
|
|
lv_arc_set_range(stepsArc, 0, 500);
|
2021-10-20 18:29:10 +00:00
|
|
|
lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, 0);
|
2021-04-19 14:28:38 +00:00
|
|
|
|
|
|
|
stepsCount = motionController.NbSteps();
|
2021-10-20 18:29:10 +00:00
|
|
|
currentTripSteps = stepsCount - motionController.GetTripSteps();
|
2021-04-19 14:28:38 +00:00
|
|
|
|
|
|
|
lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal()));
|
|
|
|
|
|
|
|
lSteps = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00));
|
2021-06-24 22:07:40 +00:00
|
|
|
lv_obj_set_style_local_text_font(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
2021-10-20 18:29:10 +00:00
|
|
|
lv_label_set_text_fmt(lSteps, "%li", stepsCount);
|
2021-10-20 03:42:48 +00:00
|
|
|
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
|
2021-04-19 14:28:38 +00:00
|
|
|
|
2021-07-25 14:54:05 +00:00
|
|
|
lv_obj_t* lstepsL = lv_label_create(lv_scr_act(), nullptr);
|
2022-04-22 20:26:38 +00:00
|
|
|
lv_obj_set_style_local_text_color(lstepsL, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
2021-07-04 18:06:50 +00:00
|
|
|
lv_label_set_text_static(lstepsL, "Steps");
|
2021-10-20 03:42:48 +00:00
|
|
|
lv_obj_align(lstepsL, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
|
2021-04-19 14:28:38 +00:00
|
|
|
|
2021-07-25 14:54:05 +00:00
|
|
|
lv_obj_t* lstepsGoal = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-19 14:28:38 +00:00
|
|
|
lv_obj_set_style_local_text_color(lstepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN);
|
2021-10-22 23:21:51 +00:00
|
|
|
lv_label_set_text_fmt(lstepsGoal, "Goal: %5lu", settingsController.GetStepsGoal());
|
2021-04-19 14:28:38 +00:00
|
|
|
lv_label_set_align(lstepsGoal, LV_LABEL_ALIGN_CENTER);
|
2021-10-22 23:21:51 +00:00
|
|
|
lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 40);
|
2021-04-19 14:28:38 +00:00
|
|
|
|
2021-07-04 18:06:50 +00:00
|
|
|
lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-19 14:28:38 +00:00
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text_static(backgroundLabel, "");
|
2021-07-19 13:26:12 +00:00
|
|
|
|
2021-10-23 17:41:10 +00:00
|
|
|
resetBtn = lv_btn_create(lv_scr_act(), nullptr);
|
|
|
|
resetBtn->user_data = this;
|
|
|
|
lv_obj_set_event_cb(resetBtn, lap_event_handler);
|
|
|
|
lv_obj_set_height(resetBtn, 50);
|
|
|
|
lv_obj_set_width(resetBtn, 115);
|
|
|
|
lv_obj_align(resetBtn, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
|
|
|
resetButtonLabel = lv_label_create(resetBtn, nullptr);
|
2022-03-20 14:47:25 +00:00
|
|
|
lv_label_set_text_static(resetButtonLabel, "Reset");
|
2021-10-20 18:29:10 +00:00
|
|
|
|
2021-10-22 03:37:35 +00:00
|
|
|
currentTripSteps = motionController.GetTripSteps();
|
2021-10-20 18:29:10 +00:00
|
|
|
|
2021-10-23 17:41:10 +00:00
|
|
|
tripLabel = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(tripLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
|
|
|
|
lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps);
|
|
|
|
lv_obj_align(tripLabel, lstepsGoal, LV_ALIGN_IN_LEFT_MID, 0, 20);
|
2021-10-20 03:42:48 +00:00
|
|
|
|
2021-07-19 13:26:12 +00:00
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
|
2021-04-19 14:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Steps::~Steps() {
|
2021-07-19 13:26:12 +00:00
|
|
|
lv_task_del(taskRefresh);
|
2021-04-19 14:28:38 +00:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-07-19 13:26:12 +00:00
|
|
|
void Steps::Refresh() {
|
2021-07-04 18:06:50 +00:00
|
|
|
stepsCount = motionController.NbSteps();
|
2021-10-22 03:37:35 +00:00
|
|
|
currentTripSteps = motionController.GetTripSteps();
|
2021-10-20 03:42:48 +00:00
|
|
|
|
2021-10-20 18:29:10 +00:00
|
|
|
lv_label_set_text_fmt(lSteps, "%li", stepsCount);
|
2021-10-20 03:42:48 +00:00
|
|
|
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
|
2021-07-19 13:26:12 +00:00
|
|
|
|
2021-10-31 15:53:13 +00:00
|
|
|
if (currentTripSteps < 100000) {
|
2021-10-23 17:41:10 +00:00
|
|
|
lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps);
|
2021-10-22 23:21:51 +00:00
|
|
|
} else {
|
2021-10-23 17:41:10 +00:00
|
|
|
lv_label_set_text_fmt(tripLabel, "Trip: 99999+");
|
2021-10-22 23:21:51 +00:00
|
|
|
}
|
2021-07-19 13:26:12 +00:00
|
|
|
lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal()));
|
2021-04-19 14:28:38 +00:00
|
|
|
}
|
2021-10-20 03:42:48 +00:00
|
|
|
|
|
|
|
void Steps::lapBtnEventHandler(lv_event_t event) {
|
|
|
|
if (event != LV_EVENT_CLICKED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stepsCount = motionController.NbSteps();
|
2021-10-22 03:37:35 +00:00
|
|
|
motionController.ResetTrip();
|
2021-10-20 03:42:48 +00:00
|
|
|
Refresh();
|
|
|
|
}
|