Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Trip meter to Steps app #764

Merged
merged 6 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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;
int32_t deltaSteps = nbSteps - this->nbSteps;
this->nbSteps = nbSteps;
if (deltaSteps > 0) {
currentTripSteps += deltaSteps;
}
}

bool MotionController::ShouldWakeUp(bool isSleeping) {
Expand Down Expand Up @@ -35,9 +39,15 @@ 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;
}
}
10 changes: 9 additions & 1 deletion src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Pinetime {
namespace Controllers {
class MotionController {
public:
enum class DeviceTypes{
enum class DeviceTypes {
Unknown,
BMA421,
BMA425,
Expand All @@ -27,6 +27,13 @@ namespace Pinetime {
uint32_t NbSteps() const {
return nbSteps;
}

void ResetTrip() {
currentTripSteps = 0;
}
uint32_t GetTripSteps() const {
Avamander marked this conversation as resolved.
Show resolved Hide resolved
return currentTripSteps;
}
bool ShouldWakeUp(bool isSleeping);

void IsSensorOk(bool isOk);
Expand All @@ -42,6 +49,7 @@ namespace Pinetime {

private:
uint32_t nbSteps;
uint32_t currentTripSteps = 0;
int16_t x;
int16_t y;
int16_t z;
Expand Down
49 changes: 43 additions & 6 deletions src/displayapp/screens/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Steps*>(obj->user_data);
steps->lapBtnEventHandler(event);
}

Steps::Steps(Pinetime::Applications::DisplayApp* app,
Controllers::MotionController& motionController,
Controllers::Settings& settingsController)
Expand All @@ -17,37 +22,54 @@ 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, 240, 240);
lv_arc_set_range(stepsArc, 0, 500);
lv_obj_align(stepsArc, nullptr, LV_ALIGN_CENTER, 0, 0);

stepsCount = motionController.NbSteps();
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", stepsCount);
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -20);
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_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, 60);
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);
lv_obj_set_size(backgroundLabel, 240, 240);
lv_obj_set_pos(backgroundLabel, 0, 0);
lv_label_set_text_static(backgroundLabel, "");

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();

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);
}

Expand All @@ -58,9 +80,24 @@ Steps::~Steps() {

void Steps::Refresh() {
stepsCount = motionController.NbSteps();
currentTripSteps = motionController.GetTripSteps();

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

if (currentTripSteps < 100000) {
lv_label_set_text_fmt(tripLabel, "Trip: %5li", currentTripSteps);
} else {
lv_label_set_text_fmt(tripLabel, "Trip: 99999+");
}
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.ResetTrip();
Refresh();
}
6 changes: 6 additions & 0 deletions src/displayapp/screens/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 currentTripSteps = 0;

lv_obj_t* lSteps;
lv_obj_t* lStepsIcon;
lv_obj_t* stepsArc;
lv_obj_t* resetBtn;
lv_obj_t* resetButtonLabel;
lv_obj_t* tripLabel;

uint32_t stepsCount;

Expand Down