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

runplus - Add lock, gps, pulse indicators to karvonen screen #3373

Merged
merged 11 commits into from
May 2, 2024
12 changes: 0 additions & 12 deletions apps/lint_exemptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,6 @@ module.exports = {
"no-unused-vars"
]
},
"runplus/app.js": {
"hash": "fabec449552d17ceb5d510aa058e420757f3caba11999efbe6ebf2ac1a81eb32",
"rules": [
"no-unused-vars"
]
},
"powermanager/boot.js": {
"hash": "662d9d29a80a4f2c2855097b4073a099604f4f6d444c13a33304346c788cc5cb",
"rules": [
Expand Down Expand Up @@ -747,12 +741,6 @@ module.exports = {
"no-undef"
]
},
"runplus/karvonen.js": {
"hash": "3011bbc5afc3e17bb873f4544d680acc8765105dd825417eadb01047ecadbcb7",
"rules": [
"no-undef"
]
},
"rescalc/app.js": {
"hash": "925f00a439817fadf92f4e7a7fcd509eb9d9c7e1e4309e315ea92a6881e18b4b",
"rules": [
Expand Down
1 change: 1 addition & 0 deletions apps/runplus/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ Write to correct settings file, fixing settings not working.
0.21: Rebase on "Run" app ver. 0.16.
0.22: Ensure screen redraws after "Resume run?" menu (#3044)
0.23: Minor code improvements
0.24: Add indicators for lock,gps and pulse to karvonen screen
1 change: 1 addition & 0 deletions apps/runplus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ so if you have no GPS lock you just need to wait.

Unlock the screen and navigate between displays by swiping left or right.
The upper number is the limit before next heart rate zone. The lower number is the limit before previous heart rate zone. The number in the middle is the heart rate. The Z1 to Z5 number indicates the heart rate zone where you are. The circle provides a quick visualisation of the hr zone in which you are.
Indicator icons for lock, heartrate and location are updated on arrival off internal system events. The heart icon shows if the exstats module decided that the heart rate value is usable. The location icon shows if there was an GPS event with a position fix in it.

## Recording Tracks

Expand Down
42 changes: 20 additions & 22 deletions apps/runplus/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Use widget utils to show/hide widgets
let wu = require("widget_utils");

let runInterval;
let karvonenActive = false;
// Run interface wrapped in a function
let ExStats = require("exstats");
const ExStats = require("exstats");
let B2 = process.env.HWVERSION===2;
let Layout = require("Layout");
let locale = require("locale");
Expand All @@ -13,11 +10,10 @@ let fontValue = B2 ? "6x15:2" : "6x8:3";
let headingCol = "#888";
let fixCount = 0;
let isMenuDisplayed = false;
const wu = require("widget_utils");

g.reset().clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
wu.show();

// ---------------------------
let settings = Object.assign({
Expand Down Expand Up @@ -100,7 +96,7 @@ function onStartStop() {
}
}

promise = promise.then(() => {
promise.then(() => {
if (running) {
if (shouldResume)
exs.resume()
Expand Down Expand Up @@ -139,7 +135,7 @@ lc.push({ type:"h", filly:1, c:[
// Now calculate the layout
let layout = new Layout( {
type:"v", c: lc
},{lazy:true, btns:[{ label:"---", cb: (()=>{if (karvonenActive) {stopKarvonenUI();run();} onStartStop();}), id:"button"}]});
},{lazy:true, btns:[{ label:"---", cb: (()=>{if (karvonenActive) {run();} onStartStop();}), id:"button"}]});
delete lc;
setStatus(exs.state.active);
layout.render();
Expand Down Expand Up @@ -169,17 +165,21 @@ Bangle.on("GPS", function(fix) {
}
});

// run() function used to switch between traditional run UI and karvonen UI
// run() function used to start updating traditional run ui
function run() {
require("runplus_karvonen").stop();
karvonenActive = false;
wu.show();
Bangle.drawWidgets();
g.reset().clearRect(Bangle.appRect);
layout.lazy = false;
layout.render();
layout.lazy = true;
// We always call ourselves once a second to update
if (!runInterval){
runInterval = setInterval(function() {
layout.clock.label = locale.time(new Date(),1);
if (!isMenuDisplayed && !karvonenActive) layout.render();
if (!isMenuDisplayed) layout.render();
}, 1000);
}
}
Expand All @@ -189,25 +189,23 @@ run();
// Karvonen
///////////////////////////////////////////////

function stopRunUI() {
function karvonen(){
// stop updating and drawing the traditional run app UI
clearInterval(runInterval);
if (runInterval) clearInterval(runInterval);
runInterval = undefined;
g.reset().clearRect(Bangle.appRect);
require("runplus_karvonen").start(settings.HRM, exs.stats.bpm);
karvonenActive = true;
}

function stopKarvonenUI() {
g.reset().clear();
clearInterval(karvonenInterval);
karvonenInterval = undefined;
karvonenActive = false;
}

let karvonenInterval;
// Define the function to go back and forth between the different UI's
function swipeHandler(LR,_) {
if (LR==-1 && karvonenActive && !isMenuDisplayed) {stopKarvonenUI(); run();}
if (LR==1 && !karvonenActive && !isMenuDisplayed) {stopRunUI(); karvonenInterval = eval(require("Storage").read("runplus_karvonen"))(settings.HRM, exs.stats.bpm);}
if (!isMenuDisplayed){
if (LR==-1 && karvonenActive)
run();
if (LR==1 && !karvonenActive)
karvonen();
}
}
// Listen for swipes with the swipeHandler
Bangle.on("swipe", swipeHandler);