|
|
|
|
@ -1,6 +1,11 @@
@@ -1,6 +1,11 @@
|
|
|
|
|
import { BaseInterface } from "./base"; |
|
|
|
|
import { BaseService, BaseCharacteritic, BaseApplication } from "./bluez-gatt"; |
|
|
|
|
|
|
|
|
|
const Mode = Object.freeze({ |
|
|
|
|
SIM: Symbol("sim"), |
|
|
|
|
ERG: Symbol("erg"), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
export class FTMSService extends BaseService { |
|
|
|
|
UUID = "00001826-0000-1000-8000-00805f9b34fb"; |
|
|
|
|
Primary = true; |
|
|
|
|
@ -30,6 +35,7 @@ class FTMSFeature extends BaseCharacteritic {
@@ -30,6 +35,7 @@ class FTMSFeature extends BaseCharacteritic {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class FTMSControlPoint extends BaseCharacteritic { |
|
|
|
|
mode = Mode.SIM; |
|
|
|
|
wind = 0; |
|
|
|
|
grade = 0; |
|
|
|
|
crr = 0; |
|
|
|
|
@ -57,10 +63,16 @@ class FTMSControlPoint extends BaseCharacteritic {
@@ -57,10 +63,16 @@ class FTMSControlPoint extends BaseCharacteritic {
|
|
|
|
|
} else if (value[0] === 0x01) { |
|
|
|
|
// reset machine
|
|
|
|
|
this.notify([0x80, 0x01, 0x01]); |
|
|
|
|
} else if (value[0] === 0x05) { |
|
|
|
|
// set target power aka ERG mode
|
|
|
|
|
this.mode = Mode.ERG; |
|
|
|
|
const power = view.getInt16(1, true); |
|
|
|
|
this.notify([0x80, 0x05, 0x01]); |
|
|
|
|
} else if (value[0] === 0x07) { |
|
|
|
|
// start/resume
|
|
|
|
|
this.notify([0x80, 0x07, 0x01]); |
|
|
|
|
} else if (value[0] === 0x11) { |
|
|
|
|
this.mode = Mode.SIM; |
|
|
|
|
// set simulations param (wind, grade, etc)
|
|
|
|
|
const wind = view.getInt16(1, true); |
|
|
|
|
const grade = view.getInt16(3, true); |
|
|
|
|
@ -72,13 +84,12 @@ class FTMSControlPoint extends BaseCharacteritic {
@@ -72,13 +84,12 @@ class FTMSControlPoint extends BaseCharacteritic {
|
|
|
|
|
this.crr = crr * 0.001; |
|
|
|
|
this.cw = cw * 0.01; |
|
|
|
|
|
|
|
|
|
console.log(wind * 0.001); |
|
|
|
|
console.log(grade * 0.01); |
|
|
|
|
console.log(crr * 0.0001); |
|
|
|
|
console.log(cw * 0.01); |
|
|
|
|
|
|
|
|
|
console.log( |
|
|
|
|
`wind=${this.wind} - grade=${this.grade} - crr=${this.crr} - cw=${this.cw}` |
|
|
|
|
); |
|
|
|
|
this.notify([0x80, 0x11, 0x01]); |
|
|
|
|
} else { |
|
|
|
|
this.notify([0x80, value[0], 0x02]); |
|
|
|
|
console.log("FTMS Control point op code " + value[0] + "not supported"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -107,7 +118,7 @@ class IndoorBikeData extends BaseCharacteritic {
@@ -107,7 +118,7 @@ class IndoorBikeData extends BaseCharacteritic {
|
|
|
|
|
this.Notifying = true; |
|
|
|
|
|
|
|
|
|
this.interval = setInterval(() => { |
|
|
|
|
console.log("FTMS Notif Indoor Bike"); |
|
|
|
|
//console.log("FTMS Notif Indoor Bike");
|
|
|
|
|
// 0x44 0x02 = fields included: cadence (2), power (6), hr (9)
|
|
|
|
|
// 0x00 0x00 = average speed, always included
|
|
|
|
|
// cadence is *2 (resolution 0.5 s^-1)
|
|
|
|
|
|