Skip to content

Commit 95fb716

Browse files
committed
Bangle.js2: Added Bangle.setOptions({hrmSportMode})
1 parent 2c30516 commit 95fb716

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
JIT: Implemented do { a } while (b)
2020
Ensure that for(in), Object.keys and Object.getOwnPropertyNames return array indices as strings (not numbers)
2121
Fix memory leak when an error happens while parsing function arguments - eg `print(1,2,3,JSON.parse("!%^$^"),123)`
22+
Bangle.js2: Added Bangle.setOptions({hrmSportMode})
2223

2324
2v17 : Bangle.js: When reading file info from a filename table, do it in blocks of 8 (20% faster file search)
2425
Bangle.js2: Increase flash buffer size from 16->32 bytes (5% performance increase)

libs/banglejs/jswrap_bangle.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,9 @@ for before the clock is reloaded? 1500ms default, or 0 means never.
23372337
and polling rate may not be exact. The algorithm's filtering is tuned for
23382338
20-40ms poll intervals, so higher/lower intervals may effect the reliability
23392339
of the BPM reading.
2340+
* `hrmSportMode` - on the newest Bangle.js 2 builds with with the proprietary
2341+
heart rate algorithm, this is the sport mode passed to the algorithm. See `libs/misc/vc31_binary/algo.h`
2342+
for more info. 0 = normal (default), 1 = running, 2 = ...
23402343
* `seaLevelPressure` (Bangle.js 2) Normally 1013.25 millibars - this is used for
23412344
calculating altitude with the pressure sensor
23422345
@@ -2357,6 +2360,9 @@ JsVar * _jswrap_banglejs_setOptions(JsVar *options, bool createObject) {
23572360
#ifdef HEARTRATE
23582361
int _hrmPollInterval = hrmPollInterval;
23592362
#endif
2363+
#ifdef HEARTRATE_VC31_BINARY
2364+
int _hrmSportMode = hrmInfo.sportMode;
2365+
#endif
23602366
#ifdef TOUCH_DEVICE
23612367
int touchX1 = touchMinX;
23622368
int touchY1 = touchMinY;
@@ -2366,6 +2372,9 @@ JsVar * _jswrap_banglejs_setOptions(JsVar *options, bool createObject) {
23662372
jsvConfigObject configs[] = {
23672373
#ifdef HEARTRATE
23682374
{"hrmPollInterval", JSV_INTEGER, &_hrmPollInterval},
2375+
#endif
2376+
#ifdef HEARTRATE_VC31_BINARY
2377+
{"hrmSportMode", JSV_INTEGER, &_hrmSportMode},
23692378
#endif
23702379
#ifdef PRESSURE_DEVICE
23712380
{"seaLevelPressure", JSV_FLOAT, &barometerSeaLevelPressure},
@@ -2416,6 +2425,9 @@ JsVar * _jswrap_banglejs_setOptions(JsVar *options, bool createObject) {
24162425
#ifdef HEARTRATE
24172426
hrmPollInterval = (uint16_t)_hrmPollInterval;
24182427
#endif
2428+
#ifdef HEARTRATE_VC31_BINARY
2429+
hrmInfo.sportMode = _hrmSportMode;
2430+
#endif
24192431
#ifdef TOUCH_DEVICE
24202432
touchMinX = touchX1;
24212433
touchMinY = touchY1;

libs/misc/heartrate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef struct {
5353
value so we have to guess based on when it changes */
5454
int lastHRM, lastConfidence;
5555
int msSinceLastHRM; // how long was it since the last HRM reading?
56+
uint8_t sportMode; // The sport mode passed to the algorithm
5657
#endif
5758
} HrmInfo;
5859

libs/misc/heartrate_vc31_binary.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void hrm_init() {
3030
memset(&hrmInfo, 0, sizeof(hrmInfo));
3131
hrmInfo.isWorn = false;
3232
hrmInfo.lastPPGTime = jshGetSystemTime();
33+
hrmInfo.sportMode = SPORT_TYPE_NORMAL;
3334
}
3435

3536
/// Add new heart rate value
@@ -64,7 +65,7 @@ bool hrm_new(int ppgValue, Vector3 *acc) {
6465
inputData.ppgSample = vcInfo.ppgValue | (vcInfo.wasAdjusted ? 0x1000 : 0);
6566
inputData.envSample = vcInfo.envValue;
6667
hrmInfo.msSinceLastHRM += timeDiff;
67-
Algo_Input(&inputData, timeDiff, SPORT_TYPE_NORMAL,0/*surfaceRecogMode*/,0/*opticalAidMode*/);
68+
Algo_Input(&inputData, timeDiff, hrmInfo.sportMode, 0/*surfaceRecogMode*/,0/*opticalAidMode*/);
6869
AlgoOutputData_t outputData;
6970
Algo_Output(&outputData);
7071
//jsiConsolePrintf("HRM %d %d %d\n", outputData.hrData, outputData.reliability, hrmInfo.msSinceLastHRM);

0 commit comments

Comments
 (0)