adjust module target version during build

master
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'; "use strict";
import { initLog } from './log'; Object.defineProperty(exports, "__esModule", { value: true });
import { ActivityStatus } from './state'; 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) { function startActivity(state) {
if (state.status === ActivityStatus.Stopped) { if (state.status === state_1.ActivityStatus.Stopped) {
initLog(state); (0, log_1.initLog)(state);
} }
if (state.status === ActivityStatus.Running) { if (state.status === state_1.ActivityStatus.Running) {
state.status = ActivityStatus.Paused; state.status = state_1.ActivityStatus.Paused;
} }
else { else {
state.status = ActivityStatus.Running; state.status = state_1.ActivityStatus.Running;
} }
draw(state); (0, display_1.draw)(state);
} }
exports.startActivity = startActivity;
function stopActivity(state) { function stopActivity(state) {
if (state.status === ActivityStatus.Paused) { if (state.status === state_1.ActivityStatus.Paused) {
clearActivity(state); clearActivity(state);
} }
if (state.status === ActivityStatus.Running) { if (state.status === state_1.ActivityStatus.Running) {
state.status = ActivityStatus.Paused; state.status = state_1.ActivityStatus.Paused;
} }
else { else {
state.status = ActivityStatus.Stopped; state.status = state_1.ActivityStatus.Stopped;
} }
draw(state); (0, display_1.draw)(state);
} }
exports.stopActivity = stopActivity;
function clearActivity(state) { function clearActivity(state) {
state.duration = 0; state.duration = 0;
state.distance = 0; state.distance = 0;
@ -32,4 +37,4 @@ function clearActivity(state) {
state.steps = 0; state.steps = 0;
state.cadence = 0; state.cadence = 0;
} }
export { clearActivity, startActivity, stopActivity }; exports.clearActivity = clearActivity;

View File

@ -1,13 +1,15 @@
import { startActivity, stopActivity } from './activity'; "use strict";
import { initDisplay } from './display'; Object.defineProperty(exports, "__esModule", { value: true });
import { initGps } from './gps'; const activity_1 = require("./activity");
import { initHrm } from './hrm'; const display_1 = require("./display");
import { initState } from './state'; const gps_1 = require("./gps");
import { initStep } from './step'; const hrm_1 = require("./hrm");
const appState = initState(); const state_1 = require("./state");
initGps(appState); const step_1 = require("./step");
initHrm(appState); const appState = (0, state_1.initState)();
initStep(appState); (0, gps_1.initGps)(appState);
initDisplay(appState); (0, hrm_1.initHrm)(appState);
setWatch(() => startActivity(appState), BTN1, { repeat: true, edge: 'falling' }); (0, step_1.initStep)(appState);
setWatch(() => stopActivity(appState), BTN3, { repeat: true, edge: 'falling' }); (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 = { const STATUS_COLORS = {
'STOP': 0xF800, 'STOP': 0xF800,
'PAUSE': 0xFFE0, 'PAUSE': 0xFFE0,
@ -14,6 +17,7 @@ function initDisplay(state) {
}); });
drawAll(state); drawAll(state);
} }
exports.initDisplay = initDisplay;
function drawBackground() { function drawBackground() {
g.clear(); g.clear();
g.setColor(0xC618); g.setColor(0xC618);
@ -26,12 +30,14 @@ function drawBackground() {
g.drawString('STEPS', 60, 152); g.drawString('STEPS', 60, 152);
g.drawString('CADENCE', 172, 152); g.drawString('CADENCE', 172, 152);
} }
exports.drawBackground = drawBackground;
function drawValue(value, x, y) { function drawValue(value, x, y) {
g.setColor(0x0000); g.setColor(0x0000);
g.fillRect(x - 60, y, x + 60, y + 30); g.fillRect(x - 60, y, x + 60, y + 30);
g.setColor(0xFFFF); g.setColor(0xFFFF);
g.drawString(value, x, y); g.drawString(value, x, y);
} }
exports.drawValue = drawValue;
function draw(state) { function draw(state) {
g.setFontVector(30); g.setFontVector(30);
g.setFontAlign(0, -1, 0); g.setFontAlign(0, -1, 0);
@ -55,27 +61,31 @@ function draw(state) {
g.setColor(0x0000); g.setColor(0x0000);
g.drawString(state.status, 200, 220); g.drawString(state.status, 200, 220);
g.setFont("6x8").setFontAlign(0, 0, 1).setColor(-1); 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); 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); g.drawString(" PAUSE ", 236, 60, 1).drawString(" PAUSE ", 236, 180, 1);
} }
else { else {
g.drawString("START", 236, 60, 1).drawString(" ", 236, 180, 1); g.drawString("START", 236, 60, 1).drawString(" ", 236, 180, 1);
} }
} }
exports.draw = draw;
function drawAll(state) { function drawAll(state) {
drawBackground(); drawBackground();
draw(state); draw(state);
Bangle.drawWidgets(); Bangle.drawWidgets();
} }
exports.drawAll = drawAll;
function formatClock(date) { function formatClock(date) {
return ('0' + date.getHours()).substr(-2) + ':' + ('0' + date.getMinutes()).substr(-2); return ('0' + date.getHours()).substr(-2) + ':' + ('0' + date.getMinutes()).substr(-2);
} }
exports.formatClock = formatClock;
function formatDistance(meters) { function formatDistance(meters) {
return (meters / 1000).toFixed(2); return (meters / 1000).toFixed(2);
} }
exports.formatDistance = formatDistance;
function formatPace(speed) { function formatPace(speed) {
if (speed < 0.1667) { if (speed < 0.1667) {
return `__'__"`; return `__'__"`;
@ -85,6 +95,7 @@ function formatPace(speed) {
const sec = pace % 60; const sec = pace % 60;
return ('0' + min).substr(-2) + `'` + ('0' + sec).substr(-2) + `"`; return ('0' + min).substr(-2) + `'` + ('0' + sec).substr(-2) + `"`;
} }
exports.formatPace = formatPace;
function formatTime(time) { function formatTime(time) {
const seconds = Math.round(time); const seconds = Math.round(time);
const hrs = Math.floor(seconds / 3600); const hrs = Math.floor(seconds / 3600);
@ -92,4 +103,4 @@ function formatTime(time) {
const sec = seconds % 60; const sec = seconds % 60;
return (hrs ? hrs + ':' : '') + ('0' + min).substr(-2) + `:` + ('0' + sec).substr(-2); 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'; "use strict";
import { updateLog } from './log'; Object.defineProperty(exports, "__esModule", { value: true });
import { ActivityStatus } from './state'; 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; const EARTH_RADIUS = 6371008.8;
function initGps(state) { function initGps(state) {
Bangle.on('GPS', (gps) => readGps(state, gps)); Bangle.on('GPS', (gps) => readGps(state, gps));
Bangle.setGPSPower(1); Bangle.setGPSPower(1);
} }
exports.initGps = initGps;
function readGps(state, gps) { function readGps(state, gps) {
state.lat = gps.lat; state.lat = gps.lat;
state.lon = gps.lon; state.lon = gps.lon;
@ -15,16 +19,17 @@ function readGps(state, gps) {
state.dop = gps.hdop; state.dop = gps.hdop;
state.gpsValid = state.fix > 0; state.gpsValid = state.fix > 0;
updateGps(state); updateGps(state);
draw(state); (0, display_1.draw)(state);
/* Only log GPS data every 5 secs if we /* Only log GPS data every 5 secs if we
have a fix and we're running. */ have a fix and we're running. */
if (state.gpsValid && if (state.gpsValid &&
state.status === ActivityStatus.Running && state.status === state_1.ActivityStatus.Running &&
state.timeSinceLog > 5) { state.timeSinceLog > 5) {
state.timeSinceLog = 0; state.timeSinceLog = 0;
updateLog(state); (0, log_1.updateLog)(state);
} }
} }
exports.readGps = readGps;
function updateGps(state) { function updateGps(state) {
const t = Date.now(); const t = Date.now();
let dt = (t - state.t) / 1000; let dt = (t - state.t) / 1000;
@ -32,7 +37,7 @@ function updateGps(state) {
dt = 0; dt = 0;
state.t = t; state.t = t;
state.timeSinceLog += dt; state.timeSinceLog += dt;
if (state.status === ActivityStatus.Running) { if (state.status === state_1.ActivityStatus.Running) {
state.duration += dt; state.duration += dt;
} }
if (!state.gpsValid) { if (!state.gpsValid) {
@ -57,10 +62,10 @@ function updateGps(state) {
state.x = x; state.x = x;
state.y = y; state.y = y;
state.z = z; state.z = z;
if (state.status === ActivityStatus.Running) { if (state.status === state_1.ActivityStatus.Running) {
state.distance += dpMag; state.distance += dpMag;
state.speed = (state.distance / state.duration) || 0; state.speed = (state.distance / state.duration) || 0;
state.cadence = (60 * state.steps / 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) { function initHrm(state) {
Bangle.on('HRM', (hrm) => updateHrm(state, hrm)); Bangle.on('HRM', (hrm) => updateHrm(state, hrm));
Bangle.setHRMPower(1); Bangle.setHRMPower(1);
} }
exports.initHrm = initHrm;
function updateHrm(state, hrm) { function updateHrm(state, hrm) {
if (hrm.confidence === 0) { if (hrm.confidence === 0) {
return; return;
@ -12,4 +16,4 @@ function updateHrm(state, hrm) {
state.hr += dHr * hrGain; state.hr += dHr * hrGain;
state.hrError += (hrError - state.hrError) * 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) { function initLog(state) {
const datetime = new Date().toISOString().replace(/[-:]/g, ''); const datetime = new Date().toISOString().replace(/[-:]/g, '');
const date = datetime.substr(2, 6); const date = datetime.substr(2, 6);
@ -8,6 +11,7 @@ function initLog(state) {
state.fileWritten = false; state.fileWritten = false;
return state; return state;
} }
exports.initLog = initLog;
function updateLog(state) { function updateLog(state) {
if (!state.fileWritten) { if (!state.fileWritten) {
state.file.write([ state.file.write([
@ -33,4 +37,4 @@ function updateLog(state) {
state.steps.toFixed(0), state.steps.toFixed(0),
].join(',') + '\n'); ].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; var ActivityStatus;
(function (ActivityStatus) { (function (ActivityStatus) {
ActivityStatus["Stopped"] = "STOP"; ActivityStatus["Stopped"] = "STOP";
ActivityStatus["Paused"] = "PAUSE"; ActivityStatus["Paused"] = "PAUSE";
ActivityStatus["Running"] = "RUN"; ActivityStatus["Running"] = "RUN";
})(ActivityStatus || (ActivityStatus = {})); })(ActivityStatus || (ActivityStatus = {}));
exports.ActivityStatus = ActivityStatus;
function initState() { function initState() {
return { return {
fix: NaN, fix: NaN,
@ -30,4 +34,4 @@ function initState() {
cadence: 0, 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) { function initStep(state) {
Bangle.on('step', () => updateStep(state)); Bangle.on('step', () => updateStep(state));
} }
exports.initStep = initStep;
function updateStep(state) { function updateStep(state) {
if (state.status === ActivityStatus.Running) { if (state.status === state_1.ActivityStatus.Running) {
state.steps += 1; state.steps += 1;
} }
} }
export { initStep, updateStep }; exports.updateStep = updateStep;

View File

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