set split to infinity while pausing

This commit is contained in:
Lars Berning 2021-03-26 21:06:02 +00:00
parent 9885a64a02
commit f1c0091a7a
7 changed files with 14 additions and 15 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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)

View File

@ -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)

View File

@ -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',

View File

@ -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) })
})
}

View File

@ -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