Skip to content

Commit

Permalink
Bangle.js2: Ensure HRM-raw.raw is set correctly after we moved to b…
Browse files Browse the repository at this point in the history
…inary hrm algorithm
  • Loading branch information
gfwilliams committed Aug 14, 2023
1 parent b5b7ee3 commit d58609f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Graphics: fix for images in drawString when completely offscreen (regression after drawImage optimisation)
Storage: Output progress on FactoryReset and Compact
nRF5x: Ensure we don't start advertising immediately after softdevice restart if NRF.sleep() was used
Bangle.js2: Ensure `HRM-raw.raw` is set correctly after we moved to binary hrm algorithm

2v18 : Fix drawString with setClipRect with 90/270-degree rotation (fix #2343)
Pico/Wifi: Enabled JIT compiler
Expand Down
11 changes: 7 additions & 4 deletions libs/misc/heartrate_vc31_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ HrmInfo hrmInfo;
void hrm_init() {
memset(&hrmInfo, 0, sizeof(hrmInfo));
hrmInfo.isWorn = false;
hrmInfo.lastPPGTime = jshGetSystemTime();
hrmInfo.lastPPGTime = jshGetSystemTime();
hrmInfo.sportMode = SPORT_TYPE_NORMAL;
}

Expand All @@ -39,13 +39,13 @@ bool hrm_new(int ppgValue, Vector3 *acc) {
JsSysTime time = jshGetSystemTime();
int timeDiff = (int)(jshGetMillisecondsFromTime(time-hrmInfo.lastPPGTime)+0.5);
hrmInfo.lastPPGTime = time;
// if we've just started wearing again, reset the algorith
// if we've just started wearing again, reset the algorithm
if (vcInfo.isWearing && !hrmInfo.isWorn) {
hrmInfo.isWorn = true;
// initialise VC31 algorithm (should do when going from wearing to not wearing)
Algo_Init();
hrmInfo.lastHRM = 0;
hrmInfo.lastConfidence = 0;
hrmInfo.lastConfidence = 0;
hrmInfo.msSinceLastHRM = 0;
hrmInfo.avg = ppgValue;
} else {
Expand All @@ -56,7 +56,10 @@ bool hrm_new(int ppgValue, Vector3 *acc) {
if (f < HRMVALUE_MIN) f = HRMVALUE_MIN;
if (f > HRMVALUE_MAX) f = HRMVALUE_MAX;
hrmInfo.filtered = f;
hrmInfo.avg = ((int)hrmInfo.avg*7 + ppgValue) >> 3;
hrmInfo.avg = ((int)hrmInfo.avg*7 + ppgValue) >> 3;
if (ppgValue<HRMVALUE_MIN) ppgValue=HRMVALUE_MIN;
if (ppgValue>HRMVALUE_MAX) ppgValue=HRMVALUE_MAX;
hrmInfo.raw = ppgValue;
// Feed data into algorithm
AlgoInputData_t inputData;
inputData.axes.x = acc->y >> 5; // perpendicular to the direction of the arm
Expand Down

0 comments on commit d58609f

Please sign in to comment.