Changed lap counter to trip meter

This commit is contained in:
Stephanie 2021-10-20 14:29:10 -04:00 committed by JF
parent d034bd131e
commit fb87fdb2d9
3 changed files with 43 additions and 33 deletions

View file

@ -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;

View file

@ -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);
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");
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);
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();
}

View file

@ -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;