Compare commits

...

17 commits

Author SHA1 Message Date
Hunman 9fa5f5f116
Merge 85c1f4e90c into 8598142c27 2024-10-10 23:39:24 +01:00
NeroBurner 8598142c27
Remove unused submodule QCBOR (#2138)
Some checks failed
CI / build-firmware (push) Successful in 5m57s
CI / build-simulator (push) Failing after 3s
CI / get-base-ref-size (push) Has been skipped
CI / Compare build size (push) Has been skipped
The submodule isn't used anymore. Remove the submodule reference
completely.
2024-10-09 20:26:08 +02:00
Sándor Rátkai 85c1f4e90c Changed MotionController::stepHistorySize to hard-coded value again 2024-09-23 14:54:53 +02:00
Sándor Rátkai 66e29db565 Changed MotionController::Days from enum to enum class 2024-09-23 14:54:53 +02:00
Sándor Rátkai a2c7e96839 Reverted to the original MotionController and MotionService dependency 2024-09-23 14:54:53 +02:00
Sándor Rátkai bcb4748b11 Removed step_t 2024-09-23 14:54:53 +02:00
Sándor Rátkai 6fbace5f2b Removed step counter history getter 2024-09-23 14:54:53 +02:00
Sándor Rátkai f0aef99783 MotionController::NbSteps should take a Days enum as parameter
Since most if not all calls expect today, I set it as default value
2024-09-23 14:54:53 +02:00
Sándor Rátkai 355178bdc4 Capitalising Day enum's members "Today" and "Yesterday" 2024-09-23 14:54:53 +02:00
Sándor Rátkai 29f8c8e30c Do not set unsigned step count to -1 2024-09-23 14:54:53 +02:00
Sándor Rátkai 5b38885b44 Clang-format changes 2024-09-23 14:54:53 +02:00
Sándor Rátkai 64ec5131b0 At midnight, "shift" the step counter history 2024-09-23 14:54:53 +02:00
Sándor Rátkai 1cce240787 Display yesterday's step counter on the Steps screen 2024-09-23 14:54:53 +02:00
Sándor Rátkai 090c3bfe21 Added an enum for the index of today and yesterday 2024-09-23 14:54:53 +02:00
Sándor Rátkai 9687154f2f Converted MotionController::nbSteps to CircularBuffer internally 2024-09-23 14:54:53 +02:00
Sándor Rátkai a083358b98 Inverted the circular dependency of MotionService and MotionController 2024-09-23 14:54:53 +02:00
Sándor Rátkai d030982902 Introduce an alias for the step counter's type 2024-09-23 14:54:53 +02:00
8 changed files with 50 additions and 16 deletions

3
.gitmodules vendored
View file

@ -4,9 +4,6 @@
[submodule "src/libs/littlefs"]
path = src/libs/littlefs
url = https://github.com/littlefs-project/littlefs.git
[submodule "src/libs/QCBOR"]
path = src/libs/QCBOR
url = https://github.com/laurencelundblade/QCBOR.git
[submodule "src/libs/arduinoFFT"]
path = src/libs/arduinoFFT
url = https://github.com/kosme/arduinoFFT.git

View file

@ -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;
} else if (attributeHandle == motionValuesHandle) {
int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()};
@ -80,7 +80,7 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
return;
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();

View file

@ -35,8 +35,17 @@ namespace {
}
}
void MotionController::AdvanceDay() {
--nbSteps; // Higher index = further in the past
NbStepsRef(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 = NbStepsRef(Days::Today);
if (oldSteps != nbSteps && service != nullptr) {
service->OnNewStepCountValue(nbSteps);
}
@ -56,11 +65,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;
oldSteps = nbSteps;
}
MotionController::AccelStats MotionController::GetAccelStats() const {

View file

@ -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() {
@ -67,9 +76,13 @@ namespace Pinetime {
}
private:
uint32_t nbSteps = 0;
Utility::CircularBuffer<uint32_t, stepHistorySize> nbSteps = {0};
uint32_t currentTripSteps = 0;
uint32_t& NbStepsRef(Days day = Days::Today) {
return nbSteps[static_cast<std::underlying_type_t<Days>>(day)];
}
TickType_t lastTime = 0;
TickType_t time = 0;

View file

@ -5,13 +5,16 @@
using namespace Pinetime::Applications::Screens;
using Days = Pinetime::Controllers::MotionController::Days;
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(Controllers::MotionController& motionController, Controllers::Settings& settingsController)
: motionController {motionController}, settingsController {settingsController} {
: motionController {motionController},
settingsController {settingsController} {
stepsArc = lv_arc_create(lv_scr_act(), nullptr);
@ -33,13 +36,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 +85,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) {

View file

@ -32,11 +32,14 @@ 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;
lv_obj_t* tripLabel;
static constexpr const char* yesterdayStr = "Yest: %5lu";
uint32_t stepsCount;
lv_task_t* taskRefresh;

@ -1 +0,0 @@
Subproject commit 56b17bf9f74096774944bcac0829adcd887d391e

View file

@ -426,6 +426,7 @@ void SystemTask::UpdateMotion() {
if (stepCounterMustBeReset) {
motionSensor.ResetStepCounter();
motionController.AdvanceDay();
stepCounterMustBeReset = false;
}