diff --git a/apps/pace/app.js b/apps/pace/app.js index 40d215869..d201bbab6 100644 --- a/apps/pace/app.js +++ b/apps/pace/app.js @@ -8,8 +8,8 @@ }, }, }); + var S_1 = require("Storage"); var drawTimeout_1; - var lastUnlazy_1 = 0; var splits_1 = []; var splitOffset_1 = 0, splitOffsetPx_1 = 0; var GPS_TIMEOUT_MS_1 = 30000; @@ -48,11 +48,6 @@ }, { lazy: true }); - var calculatePace_1 = function (time, dist) { - if (dist === 0) - return 0; - return time / dist / 1000 / 60; - }; var draw_1 = function () { if (!exs_1.state.active) { drawSplits_1(); @@ -70,39 +65,47 @@ else { pace = "No GPS"; } - var tm = time_utils_1.decodeTime(exs_1.state.duration); - layout_1["time"].label = tm.d ? time_utils_1.formatDuration(tm) : time_utils_1.formatTime(tm); + layout_1["time"].label = formatDuration_1(exs_1.state.duration); layout_1["pace"].label = pace; layout_1.render(); - if (now - lastUnlazy_1 > 30000) - layout_1.forgetLazyState(), lastUnlazy_1 = now; }; + var pad2_1 = function (n) { return "0".concat(n).substr(-2); }; + var formatDuration_1 = function (ms) { + var tm = time_utils_1.decodeTime(ms); + if (tm.h) + return "".concat(tm.h, ":").concat(pad2_1(tm.m), ":").concat(pad2_1(tm.s)); + return "".concat(pad2_1(tm.m), ":").concat(pad2_1(tm.s)); + }; + var calculatePace_1 = function (split) { return formatDuration_1(split.time / split.dist * 1000); }; var drawSplits_1 = function () { g.clearRect(Bangle.appRect); var barSize = 20; var barSpacing = 10; var w = g.getWidth(); var h = g.getHeight(); - var max = splits_1.reduce(function (a, x) { return Math.max(a, x); }, 0); + var max = splits_1.reduce(function (a, s) { return Math.max(a, s.time); }, 0); g.setFont("6x8", 2).setFontAlign(-1, -1); var i = 0; - var totalTime = 0; for (;; i++) { var split = splits_1[i + splitOffset_1]; if (split == null) break; - totalTime += split; - var y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2; - if (y > h) + var y_1 = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2; + if (y_1 > h) break; - var size = w * split / max; - g.setColor("#00f").fillRect(0, y, size, y + barSize); - var splitPace = calculatePace_1(split, 1); - g.setColor("#fff").drawString("".concat(i + 1 + splitOffset_1, " @ ").concat(splitPace.toFixed(2)), 0, y); + var size = w * split.time / max; + g.setColor("#00f").fillRect(0, y_1, size, y_1 + barSize); + var splitPace = calculatePace_1(split); + drawSplit_1(i, y_1, splitPace); } var pace = exs_1.stats.pacec.getString(); - var splitTime = exs_1.state.duration - totalTime; - g.setColor("#fff").drawString("".concat(i + 1 + splitOffset_1, " @ ").concat(pace, " (").concat((splitTime / 1000).toFixed(2), ")"), 0, Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2); + var y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2; + drawSplit_1(i, y, pace); + }; + var drawSplit_1 = function (i, y, pace) { + g + .setColor("#fff") + .drawString("".concat(i + 1 + splitOffset_1, " ").concat(typeof pace === "number" ? pace.toFixed(2) : pace), 0, y); }; var pauseRun_1 = function () { exs_1.stop(); @@ -122,17 +125,24 @@ else resumeRun_1(); }; + exs_1.start(); exs_1.stats.dist.on("notify", function (dist) { - var prev = splits_1[splits_1.length - 1] || 0; + var prev = { time: 0, dist: 0 }; + for (var _i = 0, splits_2 = splits_1; _i < splits_2.length; _i++) { + var s = splits_2[_i]; + prev.time += s.time; + prev.dist += s.dist; + } var totalDist = dist.getValue(); - var thisSplit = totalDist - prev; - var prevTime = splits_1.reduce(function (a, b) { return a + b; }, 0); - var time = exs_1.state.duration - prevTime; - while (thisSplit > 0) { - splits_1.push(time); - time = 0; + 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; } + exs_1.state.notify.dist.next -= thisSplit; + S_1.writeJSON("pace.json", { splits: splits_1 }); }); Bangle.on('lock', function (locked) { if (!locked && exs_1.state.active) @@ -155,6 +165,9 @@ } draw_1(); }); + Bangle.on('twist', function () { + Bangle.setBacklight(1); + }); Bangle.loadWidgets(); Bangle.drawWidgets(); g.clearRect(Bangle.appRect);