pace: merge gps layout updating with passing gps to render

master
Rob Pilling 2025-06-05 08:03:12 +01:00
parent a41c92ceaf
commit 651c05d005
2 changed files with 8 additions and 15 deletions

View File

@ -12,13 +12,12 @@ var _a;
var S_1 = require("Storage"); var S_1 = require("Storage");
var drawTimeout_1; var drawTimeout_1;
var menuShown_1 = false; var menuShown_1 = false;
var latestGps_1;
var splits_1 = ((_a = S_1.readJSON("pace.json", 1)) === null || _a === void 0 ? void 0 : _a.splits) || []; var splits_1 = ((_a = S_1.readJSON("pace.json", 1)) === null || _a === void 0 ? void 0 : _a.splits) || [];
var splitOffset_1 = 0, splitOffsetPx_1 = 0; var splitOffset_1 = 0, splitOffsetPx_1 = 0;
var GPS_TIMEOUT_MS_1 = 30000; var GPS_TIMEOUT_MS_1 = 30000;
var drawGpsLvl = function (l) { var drawGpsLvl = function (l) {
var _a; var _a;
var gps = latestGps_1; var gps = l.gps;
var nsats = (_a = gps === null || gps === void 0 ? void 0 : gps.satellites) !== null && _a !== void 0 ? _a : 0; var nsats = (_a = gps === null || gps === void 0 ? void 0 : gps.satellites) !== null && _a !== void 0 ? _a : 0;
if (!gps || !gps.fix) if (!gps || !gps.fix)
g.setColor("#FF0000"); g.setColor("#FF0000");
@ -42,7 +41,6 @@ var _a;
filly: 1, filly: 1,
width: 10, width: 10,
bgCol: g.theme.bg, bgCol: g.theme.bg,
redraw: -1,
}, },
{ {
type: "v", type: "v",
@ -240,11 +238,9 @@ var _a;
Bangle.drawWidgets(); Bangle.drawWidgets();
Bangle.setGPSPower(1, "pace"); Bangle.setGPSPower(1, "pace");
Bangle.on("GPS", function (gps) { Bangle.on("GPS", function (gps) {
var newSats = gps === null || gps === void 0 ? void 0 : gps.satellites;
var l = layout_1["gpslvl"]; var l = layout_1["gpslvl"];
if (l && newSats !== (latestGps_1 === null || latestGps_1 === void 0 ? void 0 : latestGps_1.satellites)) if (l)
l.redraw = newSats; l.gps = gps;
latestGps_1 = gps;
}); });
g.clearRect(Bangle.appRect); g.clearRect(Bangle.appRect);
draw_1(); draw_1();

View File

@ -15,7 +15,6 @@ const S = require("Storage");
let drawTimeout: TimeoutId | undefined; let drawTimeout: TimeoutId | undefined;
let menuShown = false; let menuShown = false;
let latestGps: GPSFix | undefined;
type Dist = number & { brand: 'dist' }; type Dist = number & { brand: 'dist' };
type Time = number & { brand: 'time' }; type Time = number & { brand: 'time' };
@ -25,6 +24,8 @@ type Split = {
time: Time, time: Time,
}; };
type LayoutWithGPS = Layout.RenderedHierarchy & { gps?: GPSFix };
type PaceState = { splits: Split[] }; type PaceState = { splits: Split[] };
const splits: PaceState["splits"] = const splits: PaceState["splits"] =
@ -35,7 +36,7 @@ let splitOffset = 0, splitOffsetPx = 0;
const GPS_TIMEOUT_MS = 30000; const GPS_TIMEOUT_MS = 30000;
const drawGpsLvl = (l: Layout.RenderedHierarchy) => { const drawGpsLvl = (l: Layout.RenderedHierarchy) => {
const gps = latestGps; const gps = (l as LayoutWithGPS).gps;
const nsats = gps?.satellites ?? 0; const nsats = gps?.satellites ?? 0;
if (!gps || !gps.fix) if (!gps || !gps.fix)
@ -67,7 +68,6 @@ const layout = new Layout({
filly: 1, filly: 1,
width: 10, width: 10,
bgCol: g.theme.bg, // automatically clears before render() bgCol: g.theme.bg, // automatically clears before render()
redraw: -1, // see below gps updating
} as unknown as { } as unknown as {
// hack to avoid a more complex id-mapping Layout inference // hack to avoid a more complex id-mapping Layout inference
type: "custom", type: "custom",
@ -309,11 +309,8 @@ Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
Bangle.setGPSPower(1, "pace"); Bangle.setGPSPower(1, "pace");
Bangle.on("GPS", gps => { Bangle.on("GPS", gps => {
const newSats = gps?.satellites; const l = layout["gpslvl"] as unknown as LayoutWithGPS | undefined;
const l = layout["gpslvl"] as unknown as Layout.RenderedHierarchy | undefined; if(l) l.gps = gps; // force a redraw
if(l && newSats !== latestGps?.satellites)
(l as any).redraw = newSats; // force a redraw
latestGps = gps;
}); });
g.clearRect(Bangle.appRect); g.clearRect(Bangle.appRect);