Skip to content

Commit

Permalink
Renamed variables and nudged some text to make room for total steps
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanie-eng committed Oct 20, 2021
1 parent 4c47c62 commit a7bea85
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace Pinetime {
uint32_t NbSteps() const {
return nbSteps;
}
void SetLapSteps(uint32_t lap) {
lapSteps = lap;
void SetPrevTotalSteps(uint32_t steps) {
stepsAtLastLap = steps;
}
uint32_t GetLapSteps() const {
return lapSteps;
uint32_t GetPrevTotalSteps() const {
return stepsAtLastLap;
}
bool ShouldWakeUp(bool isSleeping);

Expand All @@ -48,7 +48,7 @@ namespace Pinetime {

private:
uint32_t nbSteps;
uint32_t lapSteps = 0;
uint32_t stepsAtLastLap = 0;
int16_t x;
int16_t y;
int16_t z;
Expand Down
39 changes: 19 additions & 20 deletions src/displayapp/screens/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
using namespace Pinetime::Applications::Screens;

static void lap_event_handler(lv_obj_t* obj, lv_event_t event) {
auto steps = static_cast<Steps*>(obj->user_data);
auto* steps = static_cast<Steps*>(obj->user_data);
steps->lapBtnEventHandler(event);
}

Steps::Steps(Pinetime::Applications::DisplayApp* app,
Controllers::MotionController& motionController,
Controllers::Settings& settingsController)
Expand All @@ -26,26 +27,26 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app,
lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, -20);

stepsCount = motionController.NbSteps();
newLapSteps = stepsCount - motionController.GetLapSteps();
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", newLapSteps);
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, 20);
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);
Expand All @@ -64,12 +65,12 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app,
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);

lapText = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(lapText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
lv_label_set_text_fmt(lapText, "Total:\n %li", motionController.GetLapSteps());
lv_obj_align(lapText, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
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, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
}

Steps::~Steps() {
Expand All @@ -79,11 +80,14 @@ Steps::~Steps() {

void Steps::Refresh() {
stepsCount = motionController.NbSteps();
newLapSteps = stepsCount - lapSteps;
currentLapSteps = stepsCount - motionController.GetPrevTotalSteps();

lv_label_set_text_fmt(lSteps, "%li", newLapSteps);
lv_label_set_text_fmt(lSteps, "%li", currentLapSteps);
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_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal()));
}

Expand All @@ -92,12 +96,7 @@ void Steps::lapBtnEventHandler(lv_event_t event) {
return;
}
stepsCount = motionController.NbSteps();
motionController.SetLapSteps(stepsCount);
newLapSteps = 0;

lv_label_set_text_fmt(lSteps, "%li", newLapSteps);
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);

lv_label_set_text_fmt(lapText, "Total:\n%li", stepsCount);
lv_obj_align(lapText, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
motionController.SetPrevTotalSteps(stepsCount);
Refresh();
}

8 changes: 4 additions & 4 deletions src/displayapp/screens/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ namespace Pinetime {
Controllers::MotionController& motionController;
Controllers::Settings& settingsController;

uint32_t lapSteps = 0;
uint32_t newLapSteps = 0;
uint32_t currentLapSteps = 0;

lv_obj_t* lSteps;
lv_obj_t* lStepsIcon;
lv_obj_t* stepsArc;
lv_obj_t *btnLap, *txtLap;
lv_obj_t *lapText;
lv_obj_t* btnLap;
lv_obj_t* txtLap;
lv_obj_t* totalStepsText;

uint32_t stepsCount;

Expand Down

0 comments on commit a7bea85

Please sign in to comment.