Skip to content

Commit cc05172

Browse files
authored
Merge pull request #3683 from bobrippling/feat/pace-reset
pace: handle GPS skew, allow reset of time/splits
2 parents ed35b19 + dfa5789 commit cc05172

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

apps/pace/ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
0.01: New app!
22
0.02: Show elapsed time on pause screen
3+
0.03: Avoid initial GPS skew and allow reset of time/splits

apps/pace/app.js

+30-4
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@
140140
var totalDist = dist.getValue();
141141
var thisSplit = totalDist - prev.dist;
142142
var thisTime = exs_1.state.duration - prev.time;
143-
while (thisSplit > 1000) {
144-
splits_1.push({ dist: thisSplit, time: thisTime });
145-
thisTime = 0;
146-
thisSplit -= 1000;
143+
if (thisSplit > 1000) {
144+
if (thisTime > 0) {
145+
if (splits_1.length || thisTime > 1000 * 60)
146+
splits_1.push({ dist: thisSplit, time: thisTime });
147+
}
148+
thisSplit %= 1000;
147149
}
148150
exs_1.state.notify.dist.next -= thisSplit;
149151
S_1.writeJSON("pace.json", { splits: splits_1 });
@@ -172,6 +174,30 @@
172174
Bangle.on('twist', function () {
173175
Bangle.setBacklight(1);
174176
});
177+
Bangle.on('tap', function (_e) {
178+
if (exs_1.state.active)
179+
return;
180+
var menu = {
181+
"": {
182+
remove: function () {
183+
draw_1();
184+
},
185+
},
186+
"< Back": function () {
187+
Bangle.setUI();
188+
},
189+
"Zero time": function () {
190+
exs_1.start();
191+
exs_1.stop();
192+
Bangle.setUI();
193+
},
194+
"Clear splits": function () {
195+
splits_1.splice(0, splits_1.length);
196+
Bangle.setUI();
197+
},
198+
};
199+
E.showMenu(menu);
200+
});
175201
Bangle.loadWidgets();
176202
Bangle.drawWidgets();
177203
g.clearRect(Bangle.appRect);

apps/pace/app.ts

+35-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,15 @@ exs.stats.dist.on("notify", (dist) => {
184184
let thisSplit = totalDist - prev.dist;
185185
let thisTime = exs.state.duration - prev.time;
186186

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

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

229+
Bangle.on('tap', _e => {
230+
if(exs.state.active) return;
231+
232+
const menu: Menu = {
233+
"": {
234+
remove: () => {
235+
draw();
236+
},
237+
},
238+
"< Back": () => {
239+
Bangle.setUI(); // calls `remove`, which handles redrawing
240+
},
241+
"Zero time": () => {
242+
exs.start(); // calls reset
243+
exs.stop(); // re-pauses
244+
Bangle.setUI();
245+
},
246+
"Clear splits": () => {
247+
splits.splice(0, splits.length);
248+
Bangle.setUI();
249+
},
250+
};
251+
252+
E.showMenu(menu);
253+
});
254+
224255
Bangle.loadWidgets();
225256
Bangle.drawWidgets();
226257

apps/pace/metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "pace",
33
"name": "Pace",
4-
"version": "0.02",
4+
"version": "0.03",
55
"description": "Show pace and time running splits",
66
"icon": "app.png",
77
"tags": "run,running,fitness,outdoors",

0 commit comments

Comments
 (0)