adjust module target version during build

pull/1052/head
Sebastian Di Luzio 2022-01-20 21:23:17 +01:00
parent 4727652627
commit ebbbf69670
9 changed files with 88 additions and 49 deletions

View File

@ -1,30 +1,35 @@
import { draw } from './display';
import { initLog } from './log';
import { ActivityStatus } from './state';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stopActivity = exports.startActivity = exports.clearActivity = void 0;
const display_1 = require("./display");
const log_1 = require("./log");
const state_1 = require("./state");
function startActivity(state) {
if (state.status === ActivityStatus.Stopped) {
initLog(state);
if (state.status === state_1.ActivityStatus.Stopped) {
(0, log_1.initLog)(state);
}
if (state.status === ActivityStatus.Running) {
state.status = ActivityStatus.Paused;
if (state.status === state_1.ActivityStatus.Running) {
state.status = state_1.ActivityStatus.Paused;
}
else {
state.status = ActivityStatus.Running;
state.status = state_1.ActivityStatus.Running;
}
draw(state);
(0, display_1.draw)(state);
}
exports.startActivity = startActivity;
function stopActivity(state) {
if (state.status === ActivityStatus.Paused) {
if (state.status === state_1.ActivityStatus.Paused) {
clearActivity(state);
}
if (state.status === ActivityStatus.Running) {
state.status = ActivityStatus.Paused;
if (state.status === state_1.ActivityStatus.Running) {
state.status = state_1.ActivityStatus.Paused;
}
else {
state.status = ActivityStatus.Stopped;
state.status = state_1.ActivityStatus.Stopped;
}
draw(state);
(0, display_1.draw)(state);
}
exports.stopActivity = stopActivity;
function clearActivity(state) {
state.duration = 0;
state.distance = 0;
@ -32,4 +37,4 @@ function clearActivity(state) {
state.steps = 0;
state.cadence = 0;
}
export { clearActivity, startActivity, stopActivity };
exports.clearActivity = clearActivity;

View File

@ -1,13 +1,15 @@
import { startActivity, stopActivity } from './activity';
import { initDisplay } from './display';
import { initGps } from './gps';
import { initHrm } from './hrm';
import { initState } from './state';
import { initStep } from './step';
const appState = initState();
initGps(appState);
initHrm(appState);
initStep(appState);
initDisplay(appState);
setWatch(() => startActivity(appState), BTN1, { repeat: true, edge: 'falling' });
setWatch(() => stopActivity(appState), BTN3, { repeat: true, edge: 'falling' });
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const activity_1 = require("./activity");
const display_1 = require("./display");
const gps_1 = require("./gps");
const hrm_1 = require("./hrm");
const state_1 = require("./state");
const step_1 = require("./step");
const appState = (0, state_1.initState)();
(0, gps_1.initGps)(appState);
(0, hrm_1.initHrm)(appState);
(0, step_1.initStep)(appState);
(0, display_1.initDisplay)(appState);
setWatch(() => (0, activity_1.startActivity)(appState), BTN1, { repeat: true, edge: 'falling' });
setWatch(() => (0, activity_1.stopActivity)(appState), BTN3, { repeat: true, edge: 'falling' });

View File

@ -1,4 +1,7 @@
import { ActivityStatus } from './state';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initDisplay = exports.formatTime = exports.formatPace = exports.formatDistance = exports.formatClock = exports.drawValue = exports.drawBackground = exports.drawAll = exports.draw = void 0;
const state_1 = require("./state");
const STATUS_COLORS = {
'STOP': 0xF800,
'PAUSE': 0xFFE0,
@ -14,6 +17,7 @@ function initDisplay(state) {
});
drawAll(state);
}
exports.initDisplay = initDisplay;
function drawBackground() {
g.clear();
g.setColor(0xC618);
@ -26,12 +30,14 @@ function drawBackground() {
g.drawString('STEPS', 60, 152);
g.drawString('CADENCE', 172, 152);
}
exports.drawBackground = drawBackground;
function drawValue(value, x, y) {
g.setColor(0x0000);
g.fillRect(x - 60, y, x + 60, y + 30);
g.setColor(0xFFFF);
g.drawString(value, x, y);
}
exports.drawValue = drawValue;
function draw(state) {
g.setFontVector(30);
g.setFontAlign(0, -1, 0);
@ -55,27 +61,31 @@ function draw(state) {
g.setColor(0x0000);
g.drawString(state.status, 200, 220);
g.setFont("6x8").setFontAlign(0, 0, 1).setColor(-1);
if (state.status === ActivityStatus.Paused) {
if (state.status === state_1.ActivityStatus.Paused) {
g.drawString("START", 236, 60, 1).drawString(" CLEAR ", 236, 180, 1);
}
else if (state.status === ActivityStatus.Running) {
else if (state.status === state_1.ActivityStatus.Running) {
g.drawString(" PAUSE ", 236, 60, 1).drawString(" PAUSE ", 236, 180, 1);
}
else {
g.drawString("START", 236, 60, 1).drawString(" ", 236, 180, 1);
}
}
exports.draw = draw;
function drawAll(state) {
drawBackground();
draw(state);
Bangle.drawWidgets();
}
exports.drawAll = drawAll;
function formatClock(date) {
return ('0' + date.getHours()).substr(-2) + ':' + ('0' + date.getMinutes()).substr(-2);
}
exports.formatClock = formatClock;
function formatDistance(meters) {
return (meters / 1000).toFixed(2);
}
exports.formatDistance = formatDistance;
function formatPace(speed) {
if (speed < 0.1667) {
return `__'__"`;
@ -85,6 +95,7 @@ function formatPace(speed) {
const sec = pace % 60;
return ('0' + min).substr(-2) + `'` + ('0' + sec).substr(-2) + `"`;
}
exports.formatPace = formatPace;
function formatTime(time) {
const seconds = Math.round(time);
const hrs = Math.floor(seconds / 3600);
@ -92,4 +103,4 @@ function formatTime(time) {
const sec = seconds % 60;
return (hrs ? hrs + ':' : '') + ('0' + min).substr(-2) + `:` + ('0' + sec).substr(-2);
}
export { draw, drawAll, drawBackground, drawValue, formatClock, formatDistance, formatPace, formatTime, initDisplay, };
exports.formatTime = formatTime;

View File

@ -1,11 +1,15 @@
import { draw } from './display';
import { updateLog } from './log';
import { ActivityStatus } from './state';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateGps = exports.readGps = exports.initGps = void 0;
const display_1 = require("./display");
const log_1 = require("./log");
const state_1 = require("./state");
const EARTH_RADIUS = 6371008.8;
function initGps(state) {
Bangle.on('GPS', (gps) => readGps(state, gps));
Bangle.setGPSPower(1);
}
exports.initGps = initGps;
function readGps(state, gps) {
state.lat = gps.lat;
state.lon = gps.lon;
@ -15,16 +19,17 @@ function readGps(state, gps) {
state.dop = gps.hdop;
state.gpsValid = state.fix > 0;
updateGps(state);
draw(state);
(0, display_1.draw)(state);
/* Only log GPS data every 5 secs if we
have a fix and we're running. */
if (state.gpsValid &&
state.status === ActivityStatus.Running &&
state.status === state_1.ActivityStatus.Running &&
state.timeSinceLog > 5) {
state.timeSinceLog = 0;
updateLog(state);
(0, log_1.updateLog)(state);
}
}
exports.readGps = readGps;
function updateGps(state) {
const t = Date.now();
let dt = (t - state.t) / 1000;
@ -32,7 +37,7 @@ function updateGps(state) {
dt = 0;
state.t = t;
state.timeSinceLog += dt;
if (state.status === ActivityStatus.Running) {
if (state.status === state_1.ActivityStatus.Running) {
state.duration += dt;
}
if (!state.gpsValid) {
@ -57,10 +62,10 @@ function updateGps(state) {
state.x = x;
state.y = y;
state.z = z;
if (state.status === ActivityStatus.Running) {
if (state.status === state_1.ActivityStatus.Running) {
state.distance += dpMag;
state.speed = (state.distance / state.duration) || 0;
state.cadence = (60 * state.steps / state.duration) || 0;
}
}
export { initGps, readGps, updateGps };
exports.updateGps = updateGps;

View File

@ -1,7 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateHrm = exports.initHrm = void 0;
function initHrm(state) {
Bangle.on('HRM', (hrm) => updateHrm(state, hrm));
Bangle.setHRMPower(1);
}
exports.initHrm = initHrm;
function updateHrm(state, hrm) {
if (hrm.confidence === 0) {
return;
@ -12,4 +16,4 @@ function updateHrm(state, hrm) {
state.hr += dHr * hrGain;
state.hrError += (hrError - state.hrError) * hrGain;
}
export { initHrm, updateHrm };
exports.updateHrm = updateHrm;

View File

@ -1,3 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateLog = exports.initLog = void 0;
function initLog(state) {
const datetime = new Date().toISOString().replace(/[-:]/g, '');
const date = datetime.substr(2, 6);
@ -8,6 +11,7 @@ function initLog(state) {
state.fileWritten = false;
return state;
}
exports.initLog = initLog;
function updateLog(state) {
if (!state.fileWritten) {
state.file.write([
@ -33,4 +37,4 @@ function updateLog(state) {
state.steps.toFixed(0),
].join(',') + '\n');
}
export { initLog, updateLog };
exports.updateLog = updateLog;

View File

@ -1,9 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initState = exports.ActivityStatus = void 0;
var ActivityStatus;
(function (ActivityStatus) {
ActivityStatus["Stopped"] = "STOP";
ActivityStatus["Paused"] = "PAUSE";
ActivityStatus["Running"] = "RUN";
})(ActivityStatus || (ActivityStatus = {}));
exports.ActivityStatus = ActivityStatus;
function initState() {
return {
fix: NaN,
@ -30,4 +34,4 @@ function initState() {
cadence: 0,
};
}
export { ActivityStatus, initState };
exports.initState = initState;

View File

@ -1,10 +1,14 @@
import { ActivityStatus } from './state';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateStep = exports.initStep = void 0;
const state_1 = require("./state");
function initStep(state) {
Bangle.on('step', () => updateStep(state));
}
exports.initStep = initStep;
function updateStep(state) {
if (state.status === ActivityStatus.Running) {
if (state.status === state_1.ActivityStatus.Running) {
state.steps += 1;
}
}
export { initStep, updateStep };
exports.updateStep = updateStep;

View File

@ -1,8 +1,8 @@
{
"compilerOptions": {
"module": "es2015",
"module": "commonjs",
"noImplicitAny": true,
"target": "es2015",
"target": "es6",
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitOverride": true,