From a41c92ceaffb660ad35a2affdbea331970ec4f17 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 14 May 2025 22:36:59 +0100 Subject: [PATCH] pace: generate js --- apps/pace/app.js | 91 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 26 deletions(-) diff --git a/apps/pace/app.js b/apps/pace/app.js index 62001ac0c..49322e2e4 100644 --- a/apps/pace/app.js +++ b/apps/pace/app.js @@ -1,3 +1,4 @@ +var _a; { var Layout_1 = require("Layout"); var time_utils_1 = require("time_utils"); @@ -11,39 +12,70 @@ var S_1 = require("Storage"); var drawTimeout_1; var menuShown_1 = false; - var splits_1 = []; + var latestGps_1; + 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 GPS_TIMEOUT_MS_1 = 30000; + var drawGpsLvl = function (l) { + var _a; + var gps = latestGps_1; + var nsats = (_a = gps === null || gps === void 0 ? void 0 : gps.satellites) !== null && _a !== void 0 ? _a : 0; + if (!gps || !gps.fix) + g.setColor("#FF0000"); + else if (gps.satellites < 4) + g.setColor("#FF5500"); + else if (gps.satellites < 6) + g.setColor("#FF8800"); + else if (gps.satellites < 8) + g.setColor("#FFCC00"); + else + g.setColor("#00FF00"); + g.fillRect(l.x, l.y + l.h - 10 - (l.h - 10) * ((nsats > 12 ? 12 : nsats) / 12), l.x + l.w - 1, l.y + l.h - 1); + }; var layout_1 = new Layout_1({ - type: "v", + type: "h", c: [ { - type: "txt", - font: "6x8:2", - label: "Pace", - id: "paceLabel", - pad: 4 + type: "custom", + render: drawGpsLvl, + id: "gpslvl", + filly: 1, + width: 10, + bgCol: g.theme.bg, + redraw: -1, }, { - type: "txt", - font: "Vector:40", - label: "", - id: "pace", - halign: 0 - }, - { - type: "txt", - font: "6x8:2", - label: "Time", - id: "timeLabel", - pad: 4 - }, - { - type: "txt", - font: "Vector:40", - label: "", - id: "time", - halign: 0 + type: "v", + c: [ + { + type: "txt", + font: "6x8:2", + label: "Pace", + id: "paceLabel", + pad: 4 + }, + { + type: "txt", + font: "Vector:40", + label: "", + id: "pace", + halign: 0 + }, + { + type: "txt", + font: "6x8:2", + label: "Time", + id: "timeLabel", + pad: 4 + }, + { + type: "txt", + font: "Vector:40", + label: "", + id: "time", + halign: 0 + }, + ] }, ] }, { @@ -207,6 +239,13 @@ Bangle.loadWidgets(); Bangle.drawWidgets(); Bangle.setGPSPower(1, "pace"); + Bangle.on("GPS", function (gps) { + var newSats = gps === null || gps === void 0 ? void 0 : gps.satellites; + var l = layout_1["gpslvl"]; + if (l && newSats !== (latestGps_1 === null || latestGps_1 === void 0 ? void 0 : latestGps_1.satellites)) + l.redraw = newSats; + latestGps_1 = gps; + }); g.clearRect(Bangle.appRect); draw_1(); }