mirror of https://github.com/espruino/BangleApps
pace: generate js
parent
53a4f4b002
commit
7718374e12
|
@ -8,8 +8,8 @@
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
var S_1 = require("Storage");
|
||||||
var drawTimeout_1;
|
var drawTimeout_1;
|
||||||
var lastUnlazy_1 = 0;
|
|
||||||
var splits_1 = [];
|
var splits_1 = [];
|
||||||
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;
|
||||||
|
@ -48,11 +48,6 @@
|
||||||
}, {
|
}, {
|
||||||
lazy: true
|
lazy: true
|
||||||
});
|
});
|
||||||
var calculatePace_1 = function (time, dist) {
|
|
||||||
if (dist === 0)
|
|
||||||
return 0;
|
|
||||||
return time / dist / 1000 / 60;
|
|
||||||
};
|
|
||||||
var draw_1 = function () {
|
var draw_1 = function () {
|
||||||
if (!exs_1.state.active) {
|
if (!exs_1.state.active) {
|
||||||
drawSplits_1();
|
drawSplits_1();
|
||||||
|
@ -70,39 +65,47 @@
|
||||||
else {
|
else {
|
||||||
pace = "No GPS";
|
pace = "No GPS";
|
||||||
}
|
}
|
||||||
var tm = time_utils_1.decodeTime(exs_1.state.duration);
|
layout_1["time"].label = formatDuration_1(exs_1.state.duration);
|
||||||
layout_1["time"].label = tm.d ? time_utils_1.formatDuration(tm) : time_utils_1.formatTime(tm);
|
|
||||||
layout_1["pace"].label = pace;
|
layout_1["pace"].label = pace;
|
||||||
layout_1.render();
|
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 () {
|
var drawSplits_1 = function () {
|
||||||
g.clearRect(Bangle.appRect);
|
g.clearRect(Bangle.appRect);
|
||||||
var barSize = 20;
|
var barSize = 20;
|
||||||
var barSpacing = 10;
|
var barSpacing = 10;
|
||||||
var w = g.getWidth();
|
var w = g.getWidth();
|
||||||
var h = g.getHeight();
|
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);
|
g.setFont("6x8", 2).setFontAlign(-1, -1);
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var totalTime = 0;
|
|
||||||
for (;; i++) {
|
for (;; i++) {
|
||||||
var split = splits_1[i + splitOffset_1];
|
var split = splits_1[i + splitOffset_1];
|
||||||
if (split == null)
|
if (split == null)
|
||||||
break;
|
break;
|
||||||
totalTime += split;
|
var y_1 = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2;
|
||||||
var y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2;
|
if (y_1 > h)
|
||||||
if (y > h)
|
|
||||||
break;
|
break;
|
||||||
var size = w * split / max;
|
var size = w * split.time / max;
|
||||||
g.setColor("#00f").fillRect(0, y, size, y + barSize);
|
g.setColor("#00f").fillRect(0, y_1, size, y_1 + barSize);
|
||||||
var splitPace = calculatePace_1(split, 1);
|
var splitPace = calculatePace_1(split);
|
||||||
g.setColor("#fff").drawString("".concat(i + 1 + splitOffset_1, " @ ").concat(splitPace.toFixed(2)), 0, y);
|
drawSplit_1(i, y_1, splitPace);
|
||||||
}
|
}
|
||||||
var pace = exs_1.stats.pacec.getString();
|
var pace = exs_1.stats.pacec.getString();
|
||||||
var splitTime = exs_1.state.duration - totalTime;
|
var y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2;
|
||||||
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);
|
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 () {
|
var pauseRun_1 = function () {
|
||||||
exs_1.stop();
|
exs_1.stop();
|
||||||
|
@ -122,17 +125,24 @@
|
||||||
else
|
else
|
||||||
resumeRun_1();
|
resumeRun_1();
|
||||||
};
|
};
|
||||||
|
exs_1.start();
|
||||||
exs_1.stats.dist.on("notify", function (dist) {
|
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 totalDist = dist.getValue();
|
||||||
var thisSplit = totalDist - prev;
|
var thisSplit = totalDist - prev.dist;
|
||||||
var prevTime = splits_1.reduce(function (a, b) { return a + b; }, 0);
|
var thisTime = exs_1.state.duration - prev.time;
|
||||||
var time = exs_1.state.duration - prevTime;
|
while (thisSplit > 1000) {
|
||||||
while (thisSplit > 0) {
|
splits_1.push({ dist: thisSplit, time: thisTime });
|
||||||
splits_1.push(time);
|
thisTime = 0;
|
||||||
time = 0;
|
|
||||||
thisSplit -= 1000;
|
thisSplit -= 1000;
|
||||||
}
|
}
|
||||||
|
exs_1.state.notify.dist.next -= thisSplit;
|
||||||
|
S_1.writeJSON("pace.json", { splits: splits_1 });
|
||||||
});
|
});
|
||||||
Bangle.on('lock', function (locked) {
|
Bangle.on('lock', function (locked) {
|
||||||
if (!locked && exs_1.state.active)
|
if (!locked && exs_1.state.active)
|
||||||
|
@ -155,6 +165,9 @@
|
||||||
}
|
}
|
||||||
draw_1();
|
draw_1();
|
||||||
});
|
});
|
||||||
|
Bangle.on('twist', function () {
|
||||||
|
Bangle.setBacklight(1);
|
||||||
|
});
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
g.clearRect(Bangle.appRect);
|
g.clearRect(Bangle.appRect);
|
||||||
|
|
Loading…
Reference in New Issue