Skip to content

Commit f823d75

Browse files
author
thyttan
committed
Merge remote-tracking branch 'bobrippling/feature/pace-improvements' into app-loader
2 parents fc4e756 + 5841ccf commit f823d75

File tree

5 files changed

+122
-54
lines changed

5 files changed

+122
-54
lines changed

apps/pace/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
0.04: Bump exstats module - show active time, not elapsed
55
0.05: Fix menu display - don't draw over the menu and vice-versa. Require
66
double-tap for menu
7+
0.06: Show GPS strength bar on the left and restore splits from previous run

apps/pace/app.js

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,68 @@
1111
var S_1 = require("Storage");
1212
var drawTimeout_1;
1313
var menuShown_1 = false;
14-
var splits_1 = [];
14+
var latestGps_1;
15+
var splits_1 = S_1.readJSON("pace.json", 1) || [];
1516
var splitOffset_1 = 0, splitOffsetPx_1 = 0;
1617
var GPS_TIMEOUT_MS_1 = 30000;
18+
var drawGpsLvl = function (l) {
19+
var _a;
20+
var gps = latestGps_1;
21+
var nsats = (_a = gps === null || gps === void 0 ? void 0 : gps.satellites) !== null && _a !== void 0 ? _a : 0;
22+
if (!gps || !gps.fix)
23+
g.setColor("#FF0000");
24+
else if (gps.satellites < 4)
25+
g.setColor("#FF5500");
26+
else if (gps.satellites < 6)
27+
g.setColor("#FF8800");
28+
else if (gps.satellites < 8)
29+
g.setColor("#FFCC00");
30+
else
31+
g.setColor("#00FF00");
32+
g.fillRect(l.x, l.y + l.h - 10 - (l.h - 10) * ((nsats > 12 ? 12 : nsats) / 12), l.x + l.w, l.y + l.h);
33+
};
1734
var layout_1 = new Layout_1({
18-
type: "v",
35+
type: "h",
1936
c: [
2037
{
21-
type: "txt",
22-
font: "6x8:2",
23-
label: "Pace",
24-
id: "paceLabel",
25-
pad: 4
26-
},
27-
{
28-
type: "txt",
29-
font: "Vector:40",
30-
label: "",
31-
id: "pace",
32-
halign: 0
33-
},
34-
{
35-
type: "txt",
36-
font: "6x8:2",
37-
label: "Time",
38-
id: "timeLabel",
39-
pad: 4
38+
type: "custom",
39+
render: drawGpsLvl,
40+
filly: 1,
41+
width: 10,
42+
bgCol: g.theme.bg,
4043
},
4144
{
42-
type: "txt",
43-
font: "Vector:40",
44-
label: "",
45-
id: "time",
46-
halign: 0
45+
type: "v",
46+
c: [
47+
{
48+
type: "txt",
49+
font: "6x8:2",
50+
label: "Pace",
51+
id: "paceLabel",
52+
pad: 4
53+
},
54+
{
55+
type: "txt",
56+
font: "Vector:40",
57+
label: "",
58+
id: "pace",
59+
halign: 0
60+
},
61+
{
62+
type: "txt",
63+
font: "6x8:2",
64+
label: "Time",
65+
id: "timeLabel",
66+
pad: 4
67+
},
68+
{
69+
type: "txt",
70+
font: "Vector:40",
71+
label: "",
72+
id: "time",
73+
halign: 0
74+
},
75+
]
4776
},
4877
]
4978
}, {
@@ -207,6 +236,7 @@
207236
Bangle.loadWidgets();
208237
Bangle.drawWidgets();
209238
Bangle.setGPSPower(1, "pace");
239+
Bangle.on("GPS", function (gps) { return latestGps_1 = gps; });
210240
g.clearRect(Bangle.appRect);
211241
draw_1();
212242
}

apps/pace/app.ts

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const S = require("Storage");
1515

1616
let drawTimeout: TimeoutId | undefined;
1717
let menuShown = false;
18+
let latestGps: GPSFix | undefined;
1819

1920
type Dist = number & { brand: 'dist' };
2021
type Time = number & { brand: 'time' };
@@ -24,41 +25,76 @@ type Split = {
2425
time: Time,
2526
};
2627

27-
const splits: Split[] = []; // times
28+
const splits: Split[] = (S.readJSON("pace.json", 1) as Split[]) || []; // times
2829
let splitOffset = 0, splitOffsetPx = 0;
2930

3031
const GPS_TIMEOUT_MS = 30000;
3132

33+
const drawGpsLvl = (l: Layout.RenderedHierarchy) => {
34+
const gps = latestGps;
35+
const nsats = gps?.satellites ?? 0;
36+
37+
if (!gps || !gps.fix)
38+
g.setColor("#FF0000");
39+
else if (gps.satellites < 4)
40+
g.setColor("#FF5500");
41+
else if (gps.satellites < 6)
42+
g.setColor("#FF8800");
43+
else if (gps.satellites < 8)
44+
g.setColor("#FFCC00");
45+
else
46+
g.setColor("#00FF00");
47+
48+
g.fillRect(
49+
l.x,
50+
l.y + l.h - 10 - (l.h - 10) * ((nsats > 12 ? 12 : nsats) / 12),
51+
l.x + l.w,
52+
l.y + l.h
53+
);
54+
};
55+
3256
const layout = new Layout({
33-
type: "v",
57+
type: "h",
3458
c: [
3559
{
36-
type: "txt",
37-
font: "6x8:2",
38-
label: "Pace",
39-
id: "paceLabel",
40-
pad: 4
41-
},
42-
{
43-
type: "txt",
44-
font: "Vector:40",
45-
label: "",
46-
id: "pace",
47-
halign: 0
48-
},
49-
{
50-
type: "txt",
51-
font: "6x8:2",
52-
label: "Time",
53-
id: "timeLabel",
54-
pad: 4
60+
type: "custom",
61+
render: drawGpsLvl,
62+
filly: 1,
63+
width: 10,
64+
bgCol: g.theme.bg, // automatically clears before render()
5565
},
5666
{
57-
type: "txt",
58-
font: "Vector:40",
59-
label: "",
60-
id: "time",
61-
halign: 0
67+
type: "v",
68+
c: [
69+
{
70+
type: "txt",
71+
font: "6x8:2",
72+
label: "Pace",
73+
id: "paceLabel",
74+
pad: 4
75+
},
76+
{
77+
type: "txt",
78+
font: "Vector:40",
79+
label: "",
80+
id: "pace",
81+
halign: 0
82+
},
83+
{
84+
type: "txt",
85+
font: "6x8:2",
86+
label: "Time",
87+
id: "timeLabel",
88+
pad: 4
89+
},
90+
{
91+
type: "txt",
92+
font: "Vector:40",
93+
label: "",
94+
id: "time",
95+
halign: 0
96+
},
97+
]
6298
},
6399
]
64100
}, {
@@ -262,6 +298,7 @@ Bangle.on('tap', e => {
262298
Bangle.loadWidgets();
263299
Bangle.drawWidgets();
264300
Bangle.setGPSPower(1, "pace");
301+
Bangle.on("GPS", gps => latestGps = gps);
265302

266303
g.clearRect(Bangle.appRect);
267304
draw();

apps/pace/metadata.json

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

typescript/types/layout.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,6 @@ declare module Layout {
153153
r?: Rotation,
154154
} | {
155155
type: "custom",
156-
render: (h: RenderedHierarchy) => void,
156+
render: (this: RenderedHierarchy, h: RenderedHierarchy) => void,
157157
};
158158
}

0 commit comments

Comments
 (0)