Skip to content

Commit

Permalink
1.4.8 added more stroke values for usb
Browse files Browse the repository at this point in the history
  • Loading branch information
tijmenvangulik committed Apr 14, 2024
1 parent 89676a0 commit d90e403
Show file tree
Hide file tree
Showing 24 changed files with 602 additions and 250 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Basically ErgometerJS needs javascript and a blue tooth driver which can be (nob
http://www.concept2.com/files/pdf/us/monitors/PM5_BluetoothSmartInterfaceDefinition.pdf

# Change Log
- 1.4.8
New values for usb,:
* strokeDistance;
* driveTime;
* strokeRecoveryTime;
* strokeCount;
- 1.4.6
* Fixed PM5 usb communication problem, On some hardware/firmware combinations the buffer size was higher than expected. This gives problems with newer PM5 devices.
- 1.4.5
Expand Down
6 changes: 5 additions & 1 deletion api/lib/ergometer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ declare namespace ergometer.csafe {
getPowerCurve(params: ICommandPowerCurve): IBuffer;
}
interface ICommandStrokeStats {
onDataReceived: (driveTime: number, strokeRecoveryTime: number) => void;
onDataReceived: (strokeDistance: number, driveTime: number, strokeRecoveryTime: number, strokeCount: number) => void;
onError?: ErrorHandler;
}
interface IBuffer {
Expand Down Expand Up @@ -1763,6 +1763,10 @@ declare namespace ergometer {
totCalories: number;
caloriesPerHour: number;
heartRate: number;
strokeDistance: number;
driveTime: number;
strokeRecoveryTime: number;
strokeCount: number;
}
class TrainingData {
workoutType: WorkoutType;
Expand Down
38 changes: 33 additions & 5 deletions api/lib/ergometer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/lib/ergometer.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/lib/ergometer.min.js

Large diffs are not rendered by default.

32 changes: 25 additions & 7 deletions api/typescript/ergometer/csafe/long_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ namespace ergometer.csafe {
//----------------------------- get power curve ------------------------------------

export interface ICommandStrokeStats {
onDataReceived: (driveTime : number,strokeRecoveryTime : number) => void;
onDataReceived: (strokeDistance : number,driveTime : number,strokeRecoveryTime : number,strokeCount : number) => void;
onError?: ErrorHandler;
}
export interface IBuffer {
Expand All @@ -227,16 +227,34 @@ namespace ergometer.csafe {
buffer.addRawCommand({
waitForResponse: true,
command: csafe.defs.LONG_CFG_CMDS.SETUSERCFG1_CMD,
data:[0],
detailCommand: csafe.defs.PM_LONG_PULL_DATA_CMDS.CSAFE_PM_GET_STROKESTATS,
data: [],
onError: params.onError,
onDataReceived: (data: DataView) => {
/*
Byte 0: Stroke Distance (MSB)
Byte 1: Stroke Distance (LSB)
Byte 2: Stroke Drive Time
Byte 3: Stroke Recovery Time (MSB)
Byte 4: Stroke Recovery Time (LSB)
Byte 5: Stroke Length
Byte 6: Drive Counter (MSB)
Byte 7: Drive Counter (LSB)
Byte 8: Peak Drive Force (MSB)
Byte 9: Peak Drive Force (LSB)
Byte 10: Impulse Drive Force (MSB)
Byte 11: Impulse Drive Force (LSB)
Byte 12: Avg Drive Force (MSB)
Byte 13: Avg Drive Force (LSB)
Byte 14: Work Per Stroke (MSB)
Byte 15: Work Per Stroke (LSB)
*/
if (params.onDataReceived && data.byteLength>=3) {
var driveTime=data.getUint8(0);
var strokeRecoveryTime=
data.getUint8(1) +
data.getUint8(2)*256;
params.onDataReceived(driveTime,strokeRecoveryTime);
var strokeDistance= (data.getUint8(0)+data.getUint8(1)*256)/100;
var driveTime=data.getUint8(2);
var strokeRecoveryTime= data.getUint8(3)+data.getUint8(4)*256;
var strokeCount= data.getUint8(6)+data.getUint8(7)*256;
params.onDataReceived(strokeDistance,driveTime,strokeRecoveryTime,strokeCount);
}

}
Expand Down
20 changes: 17 additions & 3 deletions api/typescript/ergometer/performancemonitorUsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ namespace ergometer {
totCalories =0; // accumulated calories burned CSAFE_GETCALORIES_CMD
caloriesPerHour =0; // calories/Hr derived from pace (GETPACE)
heartRate =0;
strokeDistance: number;
driveTime: number;
strokeRecoveryTime: number;
strokeCount: number;
}
export class TrainingData
{
Expand Down Expand Up @@ -285,8 +289,7 @@ namespace ergometer {
this.newStrokeState(strokeState);

}
})

})
.send()
.then(()=>{ //send returns a promise
this.traceInfo("end high res update");
Expand Down Expand Up @@ -337,7 +340,7 @@ namespace ergometer {

}
private handlePowerCurve() : Promise<void>{
return this.newCsafeBuffer()
return this.newCsafeBuffer()
.getPowerCurve({
onDataReceived: (curve : number[]) =>{
this.powerCurveEvent.pub(curve);
Expand Down Expand Up @@ -534,6 +537,16 @@ namespace ergometer {
}

})
.getStrokeStats({
onDataReceived: (strokeDistance : number,driveTime : number,strokeRecoveryTime : number,strokeCount : number )=> {
this.strokeData.strokeDistance=strokeDistance;
this.strokeData.driveTime=driveTime;
this.strokeData.strokeRecoveryTime=strokeRecoveryTime;
this.strokeData.strokeCount=strokeCount;
this.strokeDataEvent.pub(this.strokeData);
}
})

.send()
.then(()=>{
/*console.log({
Expand All @@ -544,6 +557,7 @@ namespace ergometer {
});*/
this.traceInfo("after low res update");
this.strokeDataEvent.pub(this.strokeData);

});
}

Expand Down
14 changes: 7 additions & 7 deletions demos/ble_cordova_debug/platforms/android/android.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@
"/manifest/application/activity/intent-filter": [
{
"xml": "<action android:name=\"android.hardware.usb.action.USB_DEVICE_ATTACHED\" />",
"count": 1,
"count": 2,
"id": "config.xml"
}
],
"/manifest": [
{
"xml": "<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" />",
"count": 1,
"count": 2,
"id": "config.xml"
},
{
"xml": "<uses-permission android:name=\"android.permission.BLUETOOTH\" />",
"count": 1,
"count": 2,
"id": "config.xml"
},
{
"xml": "<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" />",
"count": 1,
"count": 2,
"id": "config.xml"
},
{
"xml": "<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" />",
"count": 1,
"count": 2,
"id": "config.xml"
},
{
"xml": "<uses-feature android:name=\"android.hardware.bluetooth_le\" android:required=\"true\" />",
"count": 1,
"count": 2,
"id": "config.xml"
}
]
Expand All @@ -48,7 +48,7 @@
"/widget": [
{
"xml": "<feature name=\"BLE\"><param name=\"android-package\" value=\"com.megster.cordova.ble.central.BLECentralPlugin\" /></feature>",
"count": 1,
"count": 2,
"id": "config.xml"
}
],
Expand Down
Loading

0 comments on commit d90e403

Please sign in to comment.