Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions modules/exstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ print(ExStats.getList());
{name: "Steps", id:"step"},
{name: "Heart (BPM)", id:"bpm"},
{name: "Max BPM", id:"maxbpm"},
{name: "Pace (avr)", id:"pacea"},
{name: "Pace (avg)", id:"pacea"},
{name: "Pace (current)", id:"pacec"},
{name: "Cadence", id:"caden"},
{name: "ETA (avg)", id:"etaa"},
{name: "ETA (current)", id:"etac"},
]

// Setup and load all statistic types
var exs = ExStats.getStats(["dist", "time", "pacea","bpm","step","caden"], options);
var exs = ExStats.getStats(["dist", "time", "pacea","bpm","step","caden","etaa","etac"], options);
// exs contains
{
stats : { time : {
Expand Down Expand Up @@ -143,6 +145,13 @@ function formatPace(speed, paceLength) {
return ('0' + min).substr(-2) + `:` + ('0' + sec).substr(-2);
}

function eta(speed, state) {
if (speed <= 0) return Infinity;

const distRemaining = (state.distance || 0) % 5000;
return distRemaining / speed;
}

Bangle.on("GPS", function(fix) {
if (!fix.fix) return; // only process actual fixes
state.lastGPS = state.thisGPS;
Expand Down Expand Up @@ -208,7 +217,9 @@ exports.getList = function() {
{name: "Pace (curr)", id:"pacec"},
{name: "Speed", id:"speed"},
{name: "Cadence", id:"caden"},
{name: "Altitude (GPS)", id:"altg"}
{name: "Altitude (GPS)", id:"altg"},
{name: "ETA (avg)", id:"etaa"},
{name: "ETA (current)", id:"etac"},
];
if (Bangle.setBarometerPower) l.push({name: "Altitude (baro)", id:"altb"});
return l;
Expand Down Expand Up @@ -311,6 +322,22 @@ exports.getStats = function(statIDs, options) {
getString : function() { return (state.alt===undefined)?"-":state.alti+"m"; },
};
}
if (statIDs.includes("etaa")) {
needGPS = true;
stats["etaa"]={
title : "A ETA",
getValue : function() { return eta(state.avrSpeed, state); },
getString : function() { const t = this.getValue(); return isFinite(t) ? formatTime(t) : "__:__"; },
};
}
if (statIDs.includes("etac")) {
needGPS = true;
stats["etac"]={
title : "C ETA",
getValue : function() { return eta(state.curSpeed, state); },
getString : function() { const t = this.getValue(); return isFinite(t) ? formatTime(t) : "__:__"; },
};
}
// ======================
for (var i in stats) stats[i].id=i; // set up ID field
if (needGPS) Bangle.setGPSPower(true,"exs");
Expand Down