From f1c0091a7abb30f06339a567b27e1e326621e36f Mon Sep 17 00:00:00 2001 From: Lars Berning <151194+laberning@users.noreply.github.com> Date: Fri, 26 Mar 2021 21:06:02 +0000 Subject: [PATCH] set split to infinity while pausing --- app/ble/ftms/RowerDataCharacteristic.js | 3 ++- app/ble/pm5/characteristic/AdditionalStatus.js | 3 ++- app/client/app.js | 3 --- app/engine/RowingStatistics.js | 3 ++- app/server.js | 11 ++++++----- app/tools/RowingRecorder.js | 4 ++-- doc/backlog.md | 2 -- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/ble/ftms/RowerDataCharacteristic.js b/app/ble/ftms/RowerDataCharacteristic.js index b92e38a..a537ba2 100644 --- a/app/ble/ftms/RowerDataCharacteristic.js +++ b/app/ble/ftms/RowerDataCharacteristic.js @@ -65,7 +65,8 @@ export default class RowerDataCharacteristic extends bleno.Characteristic { // Total Distance in meters bufferBuilder.writeUInt24LE(data.distanceTotal) // Instantaneous Pace in seconds/500m - bufferBuilder.writeUInt16LE(data.split) + // if split is infinite (i.e. while pausing), use the highest possible number + bufferBuilder.writeUInt16LE(data.split !== Infinity ? data.split : 0xFFFF) // Instantaneous Power in watts bufferBuilder.writeUInt16LE(data.power) // Energy in kcal diff --git a/app/ble/pm5/characteristic/AdditionalStatus.js b/app/ble/pm5/characteristic/AdditionalStatus.js index 093c5d7..f74e6a6 100644 --- a/app/ble/pm5/characteristic/AdditionalStatus.js +++ b/app/ble/pm5/characteristic/AdditionalStatus.js @@ -46,7 +46,8 @@ export default class AdditionalStatus extends bleno.Characteristic { // heartRate: UInt8 in bpm, 255 if invalid bufferBuilder.writeUInt8(255) // currentPace: UInt16LE in 0.01 sec/500m - bufferBuilder.writeUInt16LE(data.split * 100) + // if split is infinite (i.e. while pausing), use the highest possible number + bufferBuilder.writeUInt16LE(data.split !== Infinity ? data.split * 100 : 0xFFFF) // averagePace: UInt16LE in 0.01 sec/500m let averagePace = 0 if (data.distanceTotal && data.distanceTotal !== 0) { diff --git a/app/client/app.js b/app/client/app.js index d49f7a0..166a897 100644 --- a/app/client/app.js +++ b/app/client/app.js @@ -87,9 +87,6 @@ export function createApp () { // eslint-disable-next-line no-undef const noSleep = new NoSleep() checkAlwaysOn() - setInterval(() => { - checkAlwaysOn() - }, 3000) document.addEventListener('click', function enableNoSleep () { document.removeEventListener('click', enableNoSleep, false) noSleep.enable().then(checkAlwaysOn) diff --git a/app/engine/RowingStatistics.js b/app/engine/RowingStatistics.js index f036fb4..1be31d2 100644 --- a/app/engine/RowingStatistics.js +++ b/app/engine/RowingStatistics.js @@ -70,7 +70,7 @@ function createRowingStatistics () { } function getMetrics () { - const splitTime = speedAverager.weightedAverage() !== 0 ? (500.0 / speedAverager.weightedAverage()) : 0 + const splitTime = speedAverager.weightedAverage() !== 0 ? (500.0 / speedAverager.weightedAverage()) : Infinity return { durationTotal, durationTotalFormatted: secondsToTimeString(durationTotal), @@ -143,6 +143,7 @@ function createRowingStatistics () { // converts a timeStamp in seconds to a human readable hh:mm:ss format function secondsToTimeString (secondsTimeStamp) { + if (secondsTimeStamp === Infinity) return '∞' const hours = Math.floor(secondsTimeStamp / 60 / 60) const minutes = Math.floor(secondsTimeStamp / 60) - (hours * 60) const seconds = Math.floor(secondsTimeStamp % 60) diff --git a/app/server.js b/app/server.js index a2a8832..9d984e3 100644 --- a/app/server.js +++ b/app/server.js @@ -8,13 +8,15 @@ */ import { fork } from 'child_process' import log from 'loglevel' +// eslint-disable-next-line no-unused-vars +import fs from 'fs' import config from './config.js' import { createRowingEngine } from './engine/RowingEngine.js' import { createRowingStatistics } from './engine/RowingStatistics.js' import { createWebServer } from './WebServer.js' import { createPeripheralManager } from './ble/PeripheralManager.js' // eslint-disable-next-line no-unused-vars -import { recordRowingSession, replayRowingSession } from './tools/RowingRecorder.js' +import { replayRowingSession } from './tools/RowingRecorder.js' // set the log levels log.setLevel(config.loglevel.default) @@ -60,6 +62,7 @@ peripheralManager.on('control', (event) => { const gpioTimerService = fork('./app/gpio/GpioTimerService.js') gpioTimerService.on('message', (dataPoint) => { rowingEngine.handleRotationImpulse(dataPoint) + // fs.appendFile('recordings/wrx700_2magnets_long.csv', `${dataPoint}\n`, (err) => { if (err) log.error(err) }) }) const rowingEngine = createRowingEngine() @@ -101,9 +104,8 @@ rowingStatistics.on('rowingPaused', (data) => { caloriesPerHour: 0, strokesPerMinute: 0, power: 0, - // todo: setting split to 0 might be dangerous, depending on what the client does with this - splitFormatted: '00:00', - split: 0, + splitFormatted: '∞', + split: Infinity, speed: 0, strokeState: 'RECOVERY' } @@ -137,7 +139,6 @@ webServer.on('clientConnected', () => { webServer.notifyClients({ peripheralMode: peripheralManager.getPeripheralMode() }) }) -// recordRowingSession('recordings/wrx700_2magnets.csv') /* replayRowingSession(rowingEngine.handleRotationImpulse, { filename: 'recordings/wrx700_2magnets.csv', diff --git a/app/tools/RowingRecorder.js b/app/tools/RowingRecorder.js index ad26e3f..b73df54 100644 --- a/app/tools/RowingRecorder.js +++ b/app/tools/RowingRecorder.js @@ -14,8 +14,8 @@ function recordRowingSession (filename) { // to track time close to realtime const gpioTimerService = fork('./app/gpio/GpioTimerService.js') gpioTimerService.on('message', (dataPoint) => { - log.debug(dataPoint.delta) - fs.appendFile(filename, `${dataPoint.delta}\n`, (err) => { if (err) log.error(err) }) + log.debug(dataPoint) + fs.appendFile(filename, `${dataPoint}\n`, (err) => { if (err) log.error(err) }) }) } diff --git a/doc/backlog.md b/doc/backlog.md index 4707ef9..ddff3dd 100644 --- a/doc/backlog.md +++ b/doc/backlog.md @@ -6,8 +6,6 @@ This is the very minimalistic Backlog for further development of this project. * investigate: occasionally stroke rate is too high - seems to happen after rowing pause * figure out where to set the Service Advertising Data (FTMS.pdf p 15) -* investigate bug: crash, when one unsubscribe to BLE "Generic Attribute", probably a bleno bug "handleAttribute.emit is not a function" -* what value should we use for split, if we are in a rowing pause? technically should be infinity... * set up a Raspberry Pi with the installation instructions to see if they are correct ## Later