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

pace: handle GPS skew, allow reset of time/splits #3683

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/pace/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
0.01: New app!
0.02: Show elapsed time on pause screen
0.03: Avoid initial GPS skew and allow reset of time/splits
34 changes: 30 additions & 4 deletions apps/pace/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@
var totalDist = dist.getValue();
var thisSplit = totalDist - prev.dist;
var thisTime = exs_1.state.duration - prev.time;
while (thisSplit > 1000) {
splits_1.push({ dist: thisSplit, time: thisTime });
thisTime = 0;
thisSplit -= 1000;
if (thisSplit > 1000) {
if (thisTime > 0) {
if (splits_1.length || thisTime > 1000 * 60)
splits_1.push({ dist: thisSplit, time: thisTime });
}
thisSplit %= 1000;
}
exs_1.state.notify.dist.next -= thisSplit;
S_1.writeJSON("pace.json", { splits: splits_1 });
Expand Down Expand Up @@ -172,6 +174,30 @@
Bangle.on('twist', function () {
Bangle.setBacklight(1);
});
Bangle.on('tap', function (_e) {
if (exs_1.state.active)
return;
var menu = {
"": {
remove: function () {
draw_1();
},
},
"< Back": function () {
Bangle.setUI();
},
"Zero time": function () {
exs_1.start();
exs_1.stop();
Bangle.setUI();
},
"Clear splits": function () {
splits_1.splice(0, splits_1.length);
Bangle.setUI();
},
};
E.showMenu(menu);
});
Bangle.loadWidgets();
Bangle.drawWidgets();
g.clearRect(Bangle.appRect);
Expand Down
39 changes: 35 additions & 4 deletions apps/pace/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ exs.stats.dist.on("notify", (dist) => {
let thisSplit = totalDist - prev.dist;
let thisTime = exs.state.duration - prev.time;

while(thisSplit > 1000) {
splits.push({ dist: thisSplit as Dist, time: thisTime as Time });
thisTime = 0; // if we've jumped more than 1k, credit the time to the first split
thisSplit -= 1000;
if (thisSplit > 1000) {
if (thisTime > 0) {
// if we have splits, or time isn't ridiculous, store the split
// (otherwise we're initialising GPS and it's inaccurate)
if (splits.length || thisTime > 1000 * 60)
splits.push({ dist: thisSplit as Dist, time: thisTime as Time });
}

thisSplit %= 1000;
}

// subtract <how much we're over> off the next split notify
Expand Down Expand Up @@ -221,6 +226,32 @@ Bangle.on('twist', () => {
Bangle.setBacklight(1);
});

Bangle.on('tap', _e => {
if(exs.state.active) return;

const menu: Menu = {
"": {
remove: () => {
draw();
},
},
"< Back": () => {
Bangle.setUI(); // calls `remove`, which handles redrawing
},
"Zero time": () => {
exs.start(); // calls reset
exs.stop(); // re-pauses
Bangle.setUI();
},
"Clear splits": () => {
splits.splice(0, splits.length);
Bangle.setUI();
},
};

E.showMenu(menu);
});

Bangle.loadWidgets();
Bangle.drawWidgets();

Expand Down
2 changes: 1 addition & 1 deletion apps/pace/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pace",
"name": "Pace",
"version": "0.02",
"version": "0.03",
"description": "Show pace and time running splits",
"icon": "app.png",
"tags": "run,running,fitness,outdoors",
Expand Down
Loading