aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/ble/MotionService.cpp4
-rw-r--r--src/components/motion/MotionController.cpp15
-rw-r--r--src/components/motion/MotionController.h19
-rw-r--r--src/displayapp/screens/Steps.cpp21
-rw-r--r--src/displayapp/screens/Steps.h1
-rw-r--r--src/systemtask/SystemTask.cpp1
6 files changed, 50 insertions, 11 deletions
diff --git a/src/components/ble/MotionService.cpp b/src/components/ble/MotionService.cpp
index 4b223c1e..44ad755f 100644
--- a/src/components/ble/MotionService.cpp
+++ b/src/components/ble/MotionService.cpp
@@ -64,7 +64,7 @@ int MotionService::OnStepCountRequested(uint16_t attributeHandle, ble_gatt_acces
NRF_LOG_INFO("Motion-stepcount : handle = %d", stepCountHandle);
uint32_t buffer = motionController.NbSteps();
- int res = os_mbuf_append(context->om, &buffer, 4);
+ int res = os_mbuf_append(context->om, &buffer, sizeof(buffer));
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
if (attributeHandle == motionValuesHandle) {
@@ -82,7 +82,7 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
}
uint32_t buffer = stepCount;
- auto* om = ble_hs_mbuf_from_flat(&buffer, 4);
+ auto* om = ble_hs_mbuf_from_flat(&buffer, sizeof(buffer));
uint16_t connectionHandle = nimble.connHandle();
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index 6cfff61f..ce959f0e 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -35,8 +35,17 @@ namespace {
}
}
+void MotionController::AdvanceDay() {
+ --nbSteps; // Higher index = further in the past
+ SetSteps(Days::Today, 0);
+ if (service != nullptr) {
+ service->OnNewStepCountValue(NbSteps(Days::Today));
+ }
+}
+
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
- if (this->nbSteps != nbSteps && service != nullptr) {
+ uint32_t oldSteps = NbSteps(Days::Today);
+ if (oldSteps != nbSteps && service != nullptr) {
service->OnNewStepCountValue(nbSteps);
}
@@ -64,11 +73,11 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
stats = GetAccelStats();
- int32_t deltaSteps = nbSteps - this->nbSteps;
+ int32_t deltaSteps = nbSteps - oldSteps;
if (deltaSteps > 0) {
currentTripSteps += deltaSteps;
}
- this->nbSteps = nbSteps;
+ SetSteps(Days::Today, nbSteps);
}
MotionController::AccelStats MotionController::GetAccelStats() const {
diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h
index ad95f31f..ed6cbbd1 100644
--- a/src/components/motion/MotionController.h
+++ b/src/components/motion/MotionController.h
@@ -18,6 +18,15 @@ namespace Pinetime {
BMA425,
};
+ enum class Days : uint8_t {
+ Today = 0,
+ Yesterday,
+ };
+
+ static constexpr size_t stepHistorySize = 2; // Store this many day's step counter
+
+ void AdvanceDay();
+
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
int16_t X() const {
@@ -32,8 +41,8 @@ namespace Pinetime {
return zHistory[0];
}
- uint32_t NbSteps() const {
- return nbSteps;
+ uint32_t NbSteps(Days day = Days::Today) const {
+ return nbSteps[static_cast<std::underlying_type_t<Days>>(day)];
}
void ResetTrip() {
@@ -66,9 +75,13 @@ namespace Pinetime {
}
private:
- uint32_t nbSteps = 0;
+ Utility::CircularBuffer<uint32_t, stepHistorySize> nbSteps = {0};
uint32_t currentTripSteps = 0;
+ void SetSteps(Days day, uint32_t steps) {
+ nbSteps[static_cast<std::underlying_type_t<Days>>(day)] = steps;
+ }
+
TickType_t lastTime = 0;
TickType_t time = 0;
diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp
index c5faaf05..2e73dab5 100644
--- a/src/displayapp/screens/Steps.cpp
+++ b/src/displayapp/screens/Steps.cpp
@@ -5,6 +5,12 @@
using namespace Pinetime::Applications::Screens;
+using Days = Pinetime::Controllers::MotionController::Days;
+
+namespace {
+ constexpr const char* yesterdayStr = "Yest: %5lu";
+}
+
static void lap_event_handler(lv_obj_t* obj, lv_event_t event) {
auto* steps = static_cast<Steps*>(obj->user_data);
steps->lapBtnEventHandler(event);
@@ -33,13 +39,19 @@ Steps::Steps(Controllers::MotionController& motionController, Controllers::Setti
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_LIME);
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_label_set_text_fmt(lSteps, "%lu", stepsCount);
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, Colors::lightGray);
lv_label_set_text_static(lstepsL, "Steps");
- lv_obj_align(lstepsL, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
+ lv_obj_align(lstepsL, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
+
+ lStepsYesterday = lv_label_create(lv_scr_act(), nullptr);
+ lv_obj_set_style_local_text_color(lStepsYesterday, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
+ lv_label_set_text_fmt(lStepsYesterday, yesterdayStr, motionController.NbSteps(Days::Yesterday));
+ lv_label_set_align(lStepsYesterday, LV_LABEL_ALIGN_CENTER);
+ lv_obj_align(lStepsYesterday, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
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);
@@ -76,7 +88,10 @@ void Steps::Refresh() {
stepsCount = motionController.NbSteps();
currentTripSteps = motionController.GetTripSteps();
- lv_label_set_text_fmt(lSteps, "%li", stepsCount);
+ lv_label_set_text_fmt(lSteps, "%lu", stepsCount);
+ lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
+
+ lv_label_set_text_fmt(lStepsYesterday, yesterdayStr, motionController.NbSteps(Days::Yesterday));
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
if (currentTripSteps < 100000) {
diff --git a/src/displayapp/screens/Steps.h b/src/displayapp/screens/Steps.h
index 1a4fe647..4824be6a 100644
--- a/src/displayapp/screens/Steps.h
+++ b/src/displayapp/screens/Steps.h
@@ -32,6 +32,7 @@ namespace Pinetime {
uint32_t currentTripSteps = 0;
lv_obj_t* lSteps;
+ lv_obj_t* lStepsYesterday;
lv_obj_t* stepsArc;
lv_obj_t* resetBtn;
lv_obj_t* resetButtonLabel;
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 28a63552..56bf9273 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -334,6 +334,7 @@ void SystemTask::Work() {
break;
case Messages::OnNewDay:
motionSensor.ResetStepCounter();
+ motionController.AdvanceDay();
break;
case Messages::OnNewHour:
using Pinetime::Controllers::AlarmController;