From ac7b2da611fa5ef4cc989a9feb027f66c0ebfc6c Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Wed, 13 Oct 2021 22:08:35 +0200 Subject: Update includes to to be relative to src directory Don't use relative imports like `../foo.h` as those depend on the relative position of both files. Rather than that use imports relative to the `src` directory, which explicitly is part of the include directories. --- src/displayapp/screens/Steps.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/displayapp/screens/Steps.cpp') diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index c41163ab..916138ed 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -1,7 +1,7 @@ -#include "Steps.h" +#include "displayapp/screens/Steps.h" #include -#include "../DisplayApp.h" -#include "Symbols.h" +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" using namespace Pinetime::Applications::Screens; -- cgit v1.2.3-70-g09d2 From d034bd131e11fd2a2ab33058991802aab7cfa305 Mon Sep 17 00:00:00 2001 From: Stephanie Date: Tue, 19 Oct 2021 23:42:48 -0400 Subject: Added "lap" button to step counter --- src/components/motion/MotionController.h | 7 +++++ src/displayapp/screens/Steps.cpp | 52 +++++++++++++++++++++++++++----- src/displayapp/screens/Steps.h | 6 ++++ 3 files changed, 57 insertions(+), 8 deletions(-) (limited to 'src/displayapp/screens/Steps.cpp') diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index c72d8a4a..3b4d78b8 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -28,6 +28,12 @@ namespace Pinetime { uint32_t NbSteps() const { return nbSteps; } + void SetPrevTotalSteps(uint32_t steps) { + stepsAtLastLap = steps; + } + uint32_t GetPrevTotalSteps() const { + return stepsAtLastLap; + } bool ShouldWakeUp(bool isSleeping); void IsSensorOk(bool isOk); @@ -44,6 +50,7 @@ namespace Pinetime { private: uint32_t nbSteps; + uint32_t stepsAtLastLap = 0; int16_t x; int16_t y; int16_t z; diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index 916138ed..572b9fb7 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -5,6 +5,11 @@ using namespace Pinetime::Applications::Screens; +static void lap_event_handler(lv_obj_t* obj, lv_event_t event) { + auto* steps = static_cast(obj->user_data); + steps->lapBtnEventHandler(event); +} + Steps::Steps(Pinetime::Applications::DisplayApp* app, Controllers::MotionController& motionController, Controllers::Settings& settingsController) @@ -17,30 +22,31 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, 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)); lv_arc_set_end_angle(stepsArc, 200); - lv_obj_set_size(stepsArc, 220, 220); + lv_obj_set_size(stepsArc, 200, 200); lv_arc_set_range(stepsArc, 0, 500); - lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, 0); + lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, -20); stepsCount = motionController.NbSteps(); + currentLapSteps = stepsCount - motionController.GetPrevTotalSteps(); 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)); lv_obj_set_style_local_text_font(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); - lv_label_set_text_fmt(lSteps, "%li", stepsCount); - lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -20); + lv_label_set_text_fmt(lSteps, "%li", currentLapSteps); + lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); lv_obj_t* lstepsL = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lstepsL, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); lv_label_set_text_static(lstepsL, "Steps"); - lv_obj_align(lstepsL, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); + lv_obj_align(lstepsL, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); lv_obj_t* lstepsGoal = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lstepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); lv_label_set_text_fmt(lstepsGoal, "Goal\n%lu", settingsController.GetStepsGoal()); lv_label_set_align(lstepsGoal, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 60); + lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 30); lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); @@ -48,6 +54,22 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, lv_obj_set_pos(backgroundLabel, 0, 0); lv_label_set_text_static(backgroundLabel, ""); + btnLap = lv_btn_create(lv_scr_act(), nullptr); + btnLap->user_data = this; + lv_obj_set_event_cb(btnLap, lap_event_handler); + lv_obj_set_height(btnLap, 50); + lv_obj_set_width(btnLap, 115); + lv_obj_align(btnLap, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_set_style_local_bg_color(btnLap, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x080808)); + txtLap = lv_label_create(btnLap, nullptr); + lv_obj_set_style_local_text_color(btnLap, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888)); + lv_label_set_text(txtLap, Symbols::lapsFlag); + + totalStepsText = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(totalStepsText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); + lv_label_set_text_fmt(totalStepsText, "Total\n%li", motionController.GetPrevTotalSteps()); + lv_obj_align(totalStepsText, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); } @@ -58,9 +80,23 @@ Steps::~Steps() { void Steps::Refresh() { stepsCount = motionController.NbSteps(); + currentLapSteps = stepsCount - motionController.GetPrevTotalSteps(); + + lv_label_set_text_fmt(lSteps, "%li", currentLapSteps); + lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); - lv_label_set_text_fmt(lSteps, "%li", stepsCount); - lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -20); + lv_label_set_text_fmt(totalStepsText, "Total\n%li", stepsCount); + lv_obj_align(totalStepsText, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal())); } + +void Steps::lapBtnEventHandler(lv_event_t event) { + if (event != LV_EVENT_CLICKED) { + return; + } + stepsCount = motionController.NbSteps(); + motionController.SetPrevTotalSteps(stepsCount); + Refresh(); +} + diff --git a/src/displayapp/screens/Steps.h b/src/displayapp/screens/Steps.h index 68daf16d..08f8ea25 100644 --- a/src/displayapp/screens/Steps.h +++ b/src/displayapp/screens/Steps.h @@ -20,14 +20,20 @@ namespace Pinetime { ~Steps() override; void Refresh() override; + void lapBtnEventHandler(lv_event_t event); private: Controllers::MotionController& motionController; Controllers::Settings& settingsController; + uint32_t currentLapSteps = 0; + lv_obj_t* lSteps; lv_obj_t* lStepsIcon; lv_obj_t* stepsArc; + lv_obj_t* btnLap; + lv_obj_t* txtLap; + lv_obj_t* totalStepsText; uint32_t stepsCount; -- cgit v1.2.3-70-g09d2 From fb87fdb2d9720ce1bca2c4920b859658a6480167 Mon Sep 17 00:00:00 2001 From: Stephanie Date: Wed, 20 Oct 2021 14:29:10 -0400 Subject: Changed lap counter to trip meter --- src/components/motion/MotionController.h | 10 +++--- src/displayapp/screens/Steps.cpp | 60 +++++++++++++++++++------------- src/displayapp/screens/Steps.h | 8 ++--- 3 files changed, 44 insertions(+), 34 deletions(-) (limited to 'src/displayapp/screens/Steps.cpp') diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index 3b4d78b8..aea82f76 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -28,11 +28,11 @@ namespace Pinetime { uint32_t NbSteps() const { return nbSteps; } - void SetPrevTotalSteps(uint32_t steps) { - stepsAtLastLap = steps; + void SetTripSteps(uint32_t steps) { + stepsAtLastTrip = steps; } - uint32_t GetPrevTotalSteps() const { - return stepsAtLastLap; + uint32_t GetTripSteps() const { + return stepsAtLastTrip; } bool ShouldWakeUp(bool isSleeping); @@ -50,7 +50,7 @@ namespace Pinetime { private: uint32_t nbSteps; - uint32_t stepsAtLastLap = 0; + uint32_t stepsAtLastTrip = 0; int16_t x; int16_t y; int16_t z; diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index 572b9fb7..5d8c3861 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -22,19 +22,19 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, 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)); lv_arc_set_end_angle(stepsArc, 200); - lv_obj_set_size(stepsArc, 200, 200); + lv_obj_set_size(stepsArc, 240, 240); lv_arc_set_range(stepsArc, 0, 500); - lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, 0); stepsCount = motionController.NbSteps(); - currentLapSteps = stepsCount - motionController.GetPrevTotalSteps(); + currentTripSteps = stepsCount - motionController.GetTripSteps(); 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)); lv_obj_set_style_local_text_font(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); - lv_label_set_text_fmt(lSteps, "%li", currentLapSteps); + lv_label_set_text_fmt(lSteps, "%li", stepsCount); lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); lv_obj_t* lstepsL = lv_label_create(lv_scr_act(), nullptr); @@ -44,7 +44,7 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, lv_obj_t* lstepsGoal = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lstepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); - lv_label_set_text_fmt(lstepsGoal, "Goal\n%lu", settingsController.GetStepsGoal()); + lv_label_set_text_fmt(lstepsGoal, "Goal: %lu", settingsController.GetStepsGoal()); lv_label_set_align(lstepsGoal, LV_LABEL_ALIGN_CENTER); lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 30); @@ -54,21 +54,27 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, lv_obj_set_pos(backgroundLabel, 0, 0); lv_label_set_text_static(backgroundLabel, ""); - btnLap = lv_btn_create(lv_scr_act(), nullptr); - btnLap->user_data = this; - lv_obj_set_event_cb(btnLap, lap_event_handler); - lv_obj_set_height(btnLap, 50); - lv_obj_set_width(btnLap, 115); - lv_obj_align(btnLap, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); - lv_obj_set_style_local_bg_color(btnLap, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x080808)); - txtLap = lv_label_create(btnLap, nullptr); - lv_obj_set_style_local_text_color(btnLap, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888)); - lv_label_set_text(txtLap, Symbols::lapsFlag); - - totalStepsText = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(totalStepsText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - lv_label_set_text_fmt(totalStepsText, "Total\n%li", motionController.GetPrevTotalSteps()); - lv_obj_align(totalStepsText, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + btnTrip = lv_btn_create(lv_scr_act(), nullptr); + btnTrip->user_data = this; + lv_obj_set_event_cb(btnTrip, lap_event_handler); + lv_obj_set_height(btnTrip, 50); + lv_obj_set_width(btnTrip, 115); + lv_obj_align(btnTrip, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_obj_set_style_local_bg_color(btnTrip, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x080808)); + txtTrip = lv_label_create(btnTrip, nullptr); + lv_obj_set_style_local_text_color(btnTrip, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888)); + lv_label_set_text(txtTrip, "Reset"); + + if(stepsCount >= motionController.GetTripSteps()){ + currentTripSteps = stepsCount - motionController.GetTripSteps(); + } else { + currentTripSteps = stepsCount + motionController.GetTripSteps(); + } + + tripText = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(tripText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); + lv_label_set_text_fmt(tripText, "Trip: %li", currentTripSteps); + lv_obj_align(tripText, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 50); taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); } @@ -80,13 +86,17 @@ Steps::~Steps() { void Steps::Refresh() { stepsCount = motionController.NbSteps(); - currentLapSteps = stepsCount - motionController.GetPrevTotalSteps(); + if(stepsCount >= motionController.GetTripSteps()){ + currentTripSteps = stepsCount - motionController.GetTripSteps(); + } else { + currentTripSteps = stepsCount + motionController.GetTripSteps(); + } - lv_label_set_text_fmt(lSteps, "%li", currentLapSteps); + lv_label_set_text_fmt(lSteps, "%li", stepsCount); lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); - lv_label_set_text_fmt(totalStepsText, "Total\n%li", stepsCount); - lv_obj_align(totalStepsText, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + lv_label_set_text_fmt(tripText, "Trip: %li", currentTripSteps); + lv_obj_align(tripText, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 50); lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal())); } @@ -96,7 +106,7 @@ void Steps::lapBtnEventHandler(lv_event_t event) { return; } stepsCount = motionController.NbSteps(); - motionController.SetPrevTotalSteps(stepsCount); + motionController.SetTripSteps(stepsCount); Refresh(); } diff --git a/src/displayapp/screens/Steps.h b/src/displayapp/screens/Steps.h index 08f8ea25..3510c500 100644 --- a/src/displayapp/screens/Steps.h +++ b/src/displayapp/screens/Steps.h @@ -26,14 +26,14 @@ namespace Pinetime { Controllers::MotionController& motionController; Controllers::Settings& settingsController; - uint32_t currentLapSteps = 0; + uint32_t currentTripSteps = 0; lv_obj_t* lSteps; lv_obj_t* lStepsIcon; lv_obj_t* stepsArc; - lv_obj_t* btnLap; - lv_obj_t* txtLap; - lv_obj_t* totalStepsText; + lv_obj_t* btnTrip; + lv_obj_t* txtTrip; + lv_obj_t* tripText; uint32_t stepsCount; -- cgit v1.2.3-70-g09d2 From f7d1b3f36847bcbd0699feeb8515bb6517690066 Mon Sep 17 00:00:00 2001 From: Stephanie Date: Thu, 21 Oct 2021 23:37:35 -0400 Subject: Moved trip meter update to MotionController and changed trip meter logic --- src/components/motion/MotionController.cpp | 4 ++++ src/components/motion/MotionController.h | 10 ++++++---- src/displayapp/screens/Steps.cpp | 14 +++----------- 3 files changed, 13 insertions(+), 15 deletions(-) (limited to 'src/displayapp/screens/Steps.cpp') diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index cae49105..59114f4c 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -14,7 +14,11 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) this->x = x; this->y = y; this->z = z; + deltaSteps = nbSteps - this->nbSteps; this->nbSteps = nbSteps; + if(deltaSteps > 0){ + currentTripSteps += deltaSteps; + } } bool MotionController::ShouldWakeUp(bool isSleeping) { diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index aea82f76..17bdc52e 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -28,11 +28,12 @@ namespace Pinetime { uint32_t NbSteps() const { return nbSteps; } - void SetTripSteps(uint32_t steps) { - stepsAtLastTrip = steps; + + void ResetTrip() { + currentTripSteps = 0; } uint32_t GetTripSteps() const { - return stepsAtLastTrip; + return currentTripSteps; } bool ShouldWakeUp(bool isSleeping); @@ -50,7 +51,8 @@ namespace Pinetime { private: uint32_t nbSteps; - uint32_t stepsAtLastTrip = 0; + int32_t deltaSteps = 0; + uint32_t currentTripSteps = 0; int16_t x; int16_t y; int16_t z; diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index 5d8c3861..cb1297b6 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -65,11 +65,7 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, lv_obj_set_style_local_text_color(btnTrip, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888)); lv_label_set_text(txtTrip, "Reset"); - if(stepsCount >= motionController.GetTripSteps()){ - currentTripSteps = stepsCount - motionController.GetTripSteps(); - } else { - currentTripSteps = stepsCount + motionController.GetTripSteps(); - } + currentTripSteps = motionController.GetTripSteps(); tripText = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(tripText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); @@ -86,11 +82,7 @@ Steps::~Steps() { void Steps::Refresh() { stepsCount = motionController.NbSteps(); - if(stepsCount >= motionController.GetTripSteps()){ - currentTripSteps = stepsCount - motionController.GetTripSteps(); - } else { - currentTripSteps = stepsCount + motionController.GetTripSteps(); - } + currentTripSteps = motionController.GetTripSteps(); lv_label_set_text_fmt(lSteps, "%li", stepsCount); lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); @@ -106,7 +98,7 @@ void Steps::lapBtnEventHandler(lv_event_t event) { return; } stepsCount = motionController.NbSteps(); - motionController.SetTripSteps(stepsCount); + motionController.ResetTrip(); Refresh(); } -- cgit v1.2.3-70-g09d2 From 7eff1dbcc631c41e05b372e993383be3554f348c Mon Sep 17 00:00:00 2001 From: Stephanie Date: Fri, 22 Oct 2021 19:21:51 -0400 Subject: Changed text to left pad --- src/displayapp/screens/Steps.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/displayapp/screens/Steps.cpp') diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index cb1297b6..ea11ca6d 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -44,9 +44,9 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, lv_obj_t* lstepsGoal = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lstepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); - lv_label_set_text_fmt(lstepsGoal, "Goal: %lu", settingsController.GetStepsGoal()); + lv_label_set_text_fmt(lstepsGoal, "Goal: %5lu", settingsController.GetStepsGoal()); lv_label_set_align(lstepsGoal, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 30); + lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 40); lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); @@ -69,8 +69,8 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, tripText = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(tripText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - lv_label_set_text_fmt(tripText, "Trip: %li", currentTripSteps); - lv_obj_align(tripText, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 50); + lv_label_set_text_fmt(tripText, "Trip: %5li", currentTripSteps); + lv_obj_align(tripText, lstepsGoal, LV_ALIGN_IN_LEFT_MID, 0, 20); taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); } @@ -87,9 +87,11 @@ void Steps::Refresh() { lv_label_set_text_fmt(lSteps, "%li", stepsCount); lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); - lv_label_set_text_fmt(tripText, "Trip: %li", currentTripSteps); - lv_obj_align(tripText, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 50); - + if (currentTripSteps < 100000){ + lv_label_set_text_fmt(tripText, "Trip: %5li", currentTripSteps); + } else { + lv_label_set_text_fmt(tripText, "Trip: 99999+"); + } lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal())); } -- cgit v1.2.3-70-g09d2 From a65f173e3c63730c7db3c29bf44e538773971dc7 Mon Sep 17 00:00:00 2001 From: Stephanie Date: Sat, 23 Oct 2021 13:41:10 -0400 Subject: Renamed confusing variables and general cleanup --- src/components/motion/MotionController.cpp | 2 +- src/components/motion/MotionController.h | 1 - src/displayapp/screens/Steps.cpp | 30 ++++++++++++++---------------- src/displayapp/screens/Steps.h | 6 +++--- 4 files changed, 18 insertions(+), 21 deletions(-) (limited to 'src/displayapp/screens/Steps.cpp') diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index 59114f4c..f2b36ad0 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -14,7 +14,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) this->x = x; this->y = y; this->z = z; - deltaSteps = nbSteps - this->nbSteps; + int32_t deltaSteps = nbSteps - this->nbSteps; this->nbSteps = nbSteps; if(deltaSteps > 0){ currentTripSteps += deltaSteps; diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index 17bdc52e..3de03d19 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -51,7 +51,6 @@ namespace Pinetime { private: uint32_t nbSteps; - int32_t deltaSteps = 0; uint32_t currentTripSteps = 0; int16_t x; int16_t y; diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index ea11ca6d..3ab28e43 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -54,23 +54,21 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app, lv_obj_set_pos(backgroundLabel, 0, 0); lv_label_set_text_static(backgroundLabel, ""); - btnTrip = lv_btn_create(lv_scr_act(), nullptr); - btnTrip->user_data = this; - lv_obj_set_event_cb(btnTrip, lap_event_handler); - lv_obj_set_height(btnTrip, 50); - lv_obj_set_width(btnTrip, 115); - lv_obj_align(btnTrip, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - lv_obj_set_style_local_bg_color(btnTrip, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x080808)); - txtTrip = lv_label_create(btnTrip, nullptr); - lv_obj_set_style_local_text_color(btnTrip, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888)); - lv_label_set_text(txtTrip, "Reset"); + 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); + lv_label_set_text(resetButtonLabel, "Reset"); currentTripSteps = motionController.GetTripSteps(); - tripText = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(tripText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - lv_label_set_text_fmt(tripText, "Trip: %5li", currentTripSteps); - lv_obj_align(tripText, lstepsGoal, LV_ALIGN_IN_LEFT_MID, 0, 20); + 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); taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); } @@ -88,9 +86,9 @@ void Steps::Refresh() { lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); if (currentTripSteps < 100000){ - lv_label_set_text_fmt(tripText, "Trip: %5li", currentTripSteps); + lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps); } else { - lv_label_set_text_fmt(tripText, "Trip: 99999+"); + lv_label_set_text_fmt(tripLabel, "Trip: 99999+"); } lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal())); } diff --git a/src/displayapp/screens/Steps.h b/src/displayapp/screens/Steps.h index 3510c500..f109e0f2 100644 --- a/src/displayapp/screens/Steps.h +++ b/src/displayapp/screens/Steps.h @@ -31,9 +31,9 @@ namespace Pinetime { lv_obj_t* lSteps; lv_obj_t* lStepsIcon; lv_obj_t* stepsArc; - lv_obj_t* btnTrip; - lv_obj_t* txtTrip; - lv_obj_t* tripText; + lv_obj_t* resetBtn; + lv_obj_t* resetButtonLabel; + lv_obj_t* tripLabel; uint32_t stepsCount; -- cgit v1.2.3-70-g09d2 From e0013e730448f4dc142e3610f970f22c807ac41e Mon Sep 17 00:00:00 2001 From: Stephanie Date: Sun, 31 Oct 2021 11:53:13 -0400 Subject: Ran clang-format --- src/components/motion/MotionController.cpp | 16 +++++++++++----- src/components/motion/MotionController.h | 4 ++-- src/displayapp/screens/Steps.cpp | 3 +-- 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src/displayapp/screens/Steps.cpp') diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index f2b36ad0..97a8feb2 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -16,7 +16,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) this->z = z; int32_t deltaSteps = nbSteps - this->nbSteps; this->nbSteps = nbSteps; - if(deltaSteps > 0){ + if (deltaSteps > 0) { currentTripSteps += deltaSteps; } } @@ -47,10 +47,16 @@ void MotionController::IsSensorOk(bool isOk) { isSensorOk = isOk; } void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) { - switch(types){ - case Drivers::Bma421::DeviceTypes::BMA421: this->deviceType = DeviceTypes::BMA421; break; - case Drivers::Bma421::DeviceTypes::BMA425: this->deviceType = DeviceTypes::BMA425; break; - default: this->deviceType = DeviceTypes::Unknown; break; + switch (types) { + case Drivers::Bma421::DeviceTypes::BMA421: + this->deviceType = DeviceTypes::BMA421; + break; + case Drivers::Bma421::DeviceTypes::BMA425: + this->deviceType = DeviceTypes::BMA425; + break; + default: + this->deviceType = DeviceTypes::Unknown; + break; } } void MotionController::SetService(Pinetime::Controllers::MotionService* service) { diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index 3de03d19..3eac7176 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -8,7 +8,7 @@ namespace Pinetime { namespace Controllers { class MotionController { public: - enum class DeviceTypes{ + enum class DeviceTypes { Unknown, BMA421, BMA425, @@ -28,7 +28,7 @@ namespace Pinetime { uint32_t NbSteps() const { return nbSteps; } - + void ResetTrip() { currentTripSteps = 0; } diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index 3ab28e43..3e7f8201 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -85,7 +85,7 @@ void Steps::Refresh() { lv_label_set_text_fmt(lSteps, "%li", stepsCount); lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40); - if (currentTripSteps < 100000){ + if (currentTripSteps < 100000) { lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps); } else { lv_label_set_text_fmt(tripLabel, "Trip: 99999+"); @@ -101,4 +101,3 @@ void Steps::lapBtnEventHandler(lv_event_t event) { motionController.ResetTrip(); Refresh(); } - -- cgit v1.2.3-70-g09d2