Skip to content

Commit

Permalink
Update CpsMeasurementCharacteristic.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JaapvanEkris authored Sep 3, 2024
1 parent fcf1b85 commit 818b3d1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/peripherals/ble/cps/CpsMeasurementCharacteristic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
/*
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
*/
import bleno from '@abandonware/bleno'
import log from 'loglevel'
Expand Down Expand Up @@ -70,19 +70,19 @@ export default class CyclingPowerMeasurementCharacteristic extends bleno.Charact
bufferBuilder.writeUInt16LE(cpsMeasurementFeaturesFlags.wheelRevolutionDataPresent | cpsMeasurementFeaturesFlags.crankRevolutionDataPresent)

// Instantaneous Power
bufferBuilder.writeUInt16LE(Math.round(data.cyclePower))
bufferBuilder.writeUInt16LE(data.cyclePower > 0 ? Math.round(data.cyclePower) : 0)

// Wheel revolution count (basically the distance in cm)
bufferBuilder.writeUInt32LE(Math.round(Math.round(data.totalLinearDistance * 100)))
bufferBuilder.writeUInt32LE(data.totalLinearDistance > 0 ? Math.round(Math.round(data.totalLinearDistance * 100)) : 0)

// Wheel revolution time (ushort with 2048 resolution, resetting in every 32sec)
bufferBuilder.writeUInt16LE(Math.round(data.totalMovingTime * 2048) % Math.pow(2, 16))
bufferBuilder.writeUInt16LE(data.totalMovingTime > 0 ? Math.round(data.totalMovingTime * 2048) % Math.pow(2, 16) : 0)

// Total stroke count
bufferBuilder.writeUInt16LE(Math.round(data.totalNumberOfStrokes))
bufferBuilder.writeUInt16LE(data.totalNumberOfStrokes > 0 ? Math.round(data.totalNumberOfStrokes) : 0)

// last stroke time time (ushort with 1024 resolution, resetting in every 64sec)
bufferBuilder.writeUInt16LE(Math.round(data.driveLastStartTime * 1024) % Math.pow(2, 16))
bufferBuilder.writeUInt16LE(data.driveLastStartTime > 0 ? Math.round(data.driveLastStartTime * 1024) % Math.pow(2, 16) : 0)

const buffer = bufferBuilder.getBuffer()
if (buffer.length > this._subscriberMaxValueSize) {
Expand Down

0 comments on commit 818b3d1

Please sign in to comment.