incyclist-devices 1.4.83 → 1.4.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ble/ble-device.js +2 -0
- package/lib/ble/ble-interface.js +22 -18
- package/lib/ble/ble-st-mode.js +0 -3
- package/lib/ble/consts.d.ts +1 -0
- package/lib/ble/consts.js +2 -1
- package/lib/ble/fm.js +2 -1
- package/lib/ble/hrm.js +1 -1
- package/lib/ble/incyclist-protocol.js +14 -11
- package/lib/ble/pwr.d.ts +1 -0
- package/lib/ble/pwr.js +2 -1
- package/lib/ble/tacx.js +1 -1
- package/lib/ble/wahoo-kickr.d.ts +1 -0
- package/lib/ble/wahoo-kickr.js +97 -47
- package/package.json +1 -1
package/lib/ble/ble-device.js
CHANGED
|
@@ -202,6 +202,8 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
202
202
|
this.peripheral = devices[0].peripheral;
|
|
203
203
|
yield this.connectPeripheral(this.peripheral);
|
|
204
204
|
this.logEvent({ message: 'connect result: success', mode: 'device', device: { id, name, address } });
|
|
205
|
+
this.connectState.isConnecting = false;
|
|
206
|
+
this.connectState.isConnected = true;
|
|
205
207
|
return true;
|
|
206
208
|
}
|
|
207
209
|
}
|
package/lib/ble/ble-interface.js
CHANGED
|
@@ -362,7 +362,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
362
362
|
createDevice(DeviceClass, peripheral, characteristics) {
|
|
363
363
|
try {
|
|
364
364
|
const C = DeviceClass;
|
|
365
|
-
const device = new C({ peripheral });
|
|
365
|
+
const device = new C({ peripheral, logger: this.logger });
|
|
366
366
|
const cids = characteristics ? characteristics.map(c => (0, ble_1.uuid)(c.uuid)) : [];
|
|
367
367
|
this.logEvent({ message: 'trying to create device', peripheral: peripheral.address, characteristics: cids, profile: device.getProfile() });
|
|
368
368
|
const existingDevice = this.devices.find(i => i.device.id === device.id && i.device.getProfile() === device.getProfile());
|
|
@@ -395,6 +395,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
395
395
|
this.scanState.isConnecting = true;
|
|
396
396
|
const existing = this.devices.find(i => (!profile || i.device.getProfile() === profile) && (i.device.address === requested.address || i.device.id === requested.id || i.device.name === requested.name));
|
|
397
397
|
if (existing) {
|
|
398
|
+
this.logEvent({ message: 'connect existing device' });
|
|
398
399
|
yield existing.device.connect();
|
|
399
400
|
this.scanState.isConnecting = false;
|
|
400
401
|
return existing.device;
|
|
@@ -415,6 +416,9 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
415
416
|
}
|
|
416
417
|
}
|
|
417
418
|
}
|
|
419
|
+
const connectedDevice = this.devices.find(d => d.isConnected);
|
|
420
|
+
if (connectedDevice)
|
|
421
|
+
return connectedDevice.device;
|
|
418
422
|
}
|
|
419
423
|
let devices = [];
|
|
420
424
|
let retry = false;
|
|
@@ -649,26 +653,26 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
649
653
|
});
|
|
650
654
|
}
|
|
651
655
|
stopScan() {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
656
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
657
|
+
this.logEvent({ message: 'scan stop request' });
|
|
658
|
+
if (!this.scanState.isScanning) {
|
|
659
|
+
this.logEvent({ message: 'scan stop result: not scanning' });
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
if (!this.getBinding())
|
|
663
|
+
throw new Error('no binding defined');
|
|
664
|
+
this.getBinding().removeAllListeners('discover');
|
|
665
|
+
const ongoing = this.peripheralCache.filter(i => i.state.isLoading);
|
|
666
|
+
if (ongoing)
|
|
667
|
+
ongoing.forEach(i => { i.isInterrupted = true; });
|
|
668
|
+
yield this.getBinding().stopScanning();
|
|
669
|
+
this.scanState.isScanning = false;
|
|
670
|
+
this.logEvent({ message: 'scan stop result: success' });
|
|
671
|
+
return true;
|
|
668
672
|
});
|
|
669
673
|
}
|
|
670
674
|
isScanning() {
|
|
671
|
-
return this.scanState.isScanning;
|
|
675
|
+
return this.scanState.isScanning === true;
|
|
672
676
|
}
|
|
673
677
|
addConnectedDevice(device) {
|
|
674
678
|
const existigDevice = this.devices.find(i => i.device.id === device.id && i.device.getProfile() === device.getProfile());
|
package/lib/ble/ble-st-mode.js
CHANGED
|
@@ -70,9 +70,6 @@ class FtmsCyclingMode extends power_base_1.default {
|
|
|
70
70
|
let power = bikeData.power || 0;
|
|
71
71
|
const slope = (prevData.slope !== undefined ? prevData.slope : prevRequest.slope || 0);
|
|
72
72
|
const distanceInternal = prevData.distanceInternal || 0;
|
|
73
|
-
if (bikeData.pedalRpm === 0 || bikeData.isPedalling === false) {
|
|
74
|
-
power = 0;
|
|
75
|
-
}
|
|
76
73
|
const m = this.getWeight();
|
|
77
74
|
const t = this.getTimeSinceLastUpdate();
|
|
78
75
|
const { speed, distance } = this.calculateSpeedAndDistance(power, slope, m, t, { bikeType });
|
package/lib/ble/consts.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export declare const CSP = "1818";
|
|
|
9
9
|
export declare const CSP_MEASUREMENT = "2a63";
|
|
10
10
|
export declare const CSP_FEATURE = "2a65";
|
|
11
11
|
export declare const WAHOO_ADVANCED_TRAINER_CP = "a026e005";
|
|
12
|
+
export declare const WAHOO_ADVANCED_TRAINER_CP_FULL = "A026E005-0A7D-4AB3-97FA-F1500F9FEB8B";
|
package/lib/ble/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WAHOO_ADVANCED_TRAINER_CP = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = exports.TACX_FE_C_TX = exports.TACX_FE_C_RX = exports.TACX_FE_C_BLE = void 0;
|
|
3
|
+
exports.WAHOO_ADVANCED_TRAINER_CP_FULL = exports.WAHOO_ADVANCED_TRAINER_CP = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = exports.TACX_FE_C_TX = exports.TACX_FE_C_RX = exports.TACX_FE_C_BLE = void 0;
|
|
4
4
|
exports.TACX_FE_C_BLE = '6e40fec1';
|
|
5
5
|
exports.TACX_FE_C_RX = '6e40fec2';
|
|
6
6
|
exports.TACX_FE_C_TX = '6e40fec3';
|
|
@@ -12,3 +12,4 @@ exports.CSP = '1818';
|
|
|
12
12
|
exports.CSP_MEASUREMENT = '2a63';
|
|
13
13
|
exports.CSP_FEATURE = '2a65';
|
|
14
14
|
exports.WAHOO_ADVANCED_TRAINER_CP = 'a026e005';
|
|
15
|
+
exports.WAHOO_ADVANCED_TRAINER_CP_FULL = 'A026E005-0A7D-4AB3-97FA-F1500F9FEB8B';
|
package/lib/ble/fm.js
CHANGED
|
@@ -105,6 +105,7 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
|
|
|
105
105
|
}
|
|
106
106
|
subscribeWriteResponse(cuuid) {
|
|
107
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
this.logEvent({ message: 'subscribe to CP response', characteristics: cuuid });
|
|
108
109
|
const connector = this.ble.getConnector(this.peripheral);
|
|
109
110
|
const isAlreadySubscribed = connector.isSubscribed(cuuid);
|
|
110
111
|
if (!isAlreadySubscribed) {
|
|
@@ -610,7 +611,7 @@ class FmAdapter extends Device_1.default {
|
|
|
610
611
|
}
|
|
611
612
|
start(props) {
|
|
612
613
|
return __awaiter(this, void 0, void 0, function* () {
|
|
613
|
-
this.logger.logEvent({ message: 'start requested', profile: this.getProfile(), props });
|
|
614
|
+
this.logger.logEvent({ message: 'ftms: start requested', profile: this.getProfile(), props });
|
|
614
615
|
if (this.ble.isScanning())
|
|
615
616
|
yield this.ble.stopScan();
|
|
616
617
|
try {
|
package/lib/ble/hrm.js
CHANGED
|
@@ -102,7 +102,7 @@ class HrmAdapter extends Device_1.default {
|
|
|
102
102
|
}
|
|
103
103
|
start(props) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
this.logger.logEvent({ message: 'start requested', profile: this.getProfile(), props });
|
|
105
|
+
this.logger.logEvent({ message: 'hrm: start requested', profile: this.getProfile(), props });
|
|
106
106
|
try {
|
|
107
107
|
const bleDevice = yield this.ble.connectDevice(this.device);
|
|
108
108
|
if (bleDevice) {
|
|
@@ -39,8 +39,8 @@ const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
|
39
39
|
const fm_1 = __importStar(require("./fm"));
|
|
40
40
|
const hrm_1 = __importStar(require("./hrm"));
|
|
41
41
|
const pwr_1 = __importStar(require("./pwr"));
|
|
42
|
-
const wahoo_kickr_1 =
|
|
43
|
-
const tacx_1 =
|
|
42
|
+
const wahoo_kickr_1 = __importStar(require("./wahoo-kickr"));
|
|
43
|
+
const tacx_1 = __importStar(require("./tacx"));
|
|
44
44
|
class BleProtocol extends DeviceProtocol_1.default {
|
|
45
45
|
constructor(binding) {
|
|
46
46
|
super();
|
|
@@ -82,16 +82,19 @@ class BleProtocol extends DeviceProtocol_1.default {
|
|
|
82
82
|
device = bleDevice;
|
|
83
83
|
else {
|
|
84
84
|
device = this.ble.findDeviceInCache(Object.assign(Object.assign({}, props()), { profile }));
|
|
85
|
-
if (!device) {
|
|
86
|
-
if (profile.toLowerCase() === 'wahoo smart trainer')
|
|
87
|
-
device = new wahoo_kickr_1.default(props());
|
|
88
|
-
else if (profile === tacx_1.default.PROFILE)
|
|
89
|
-
device = new tacx_1.default(props());
|
|
90
|
-
else
|
|
91
|
-
device = new fm_1.default(props());
|
|
92
|
-
}
|
|
93
85
|
}
|
|
94
|
-
|
|
86
|
+
if (profile.toLowerCase() === 'wahoo smart trainer') {
|
|
87
|
+
device = device || new wahoo_kickr_1.default(props());
|
|
88
|
+
return new wahoo_kickr_1.WahooAdvancedFmAdapter(device, this);
|
|
89
|
+
}
|
|
90
|
+
else if (profile === tacx_1.default.PROFILE) {
|
|
91
|
+
device = device || new tacx_1.default(props());
|
|
92
|
+
return new tacx_1.TacxBleFEAdapter(device, this);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
device = device || new fm_1.default(props());
|
|
96
|
+
return new fm_1.FmAdapter(device, this);
|
|
97
|
+
}
|
|
95
98
|
case 'cp':
|
|
96
99
|
case 'power meter':
|
|
97
100
|
return new pwr_1.PwrAdapter(fromDevice ? bleDevice : new pwr_1.default(props()), this);
|
package/lib/ble/pwr.d.ts
CHANGED
package/lib/ble/pwr.js
CHANGED
|
@@ -173,6 +173,7 @@ class PwrAdapter extends Device_1.default {
|
|
|
173
173
|
this.mode = this.getDefaultCyclingMode();
|
|
174
174
|
this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
|
|
175
175
|
}
|
|
176
|
+
select() { this.selected = true; }
|
|
176
177
|
isBike() { return true; }
|
|
177
178
|
isHrm() { return false; }
|
|
178
179
|
isPower() { return true; }
|
|
@@ -277,7 +278,7 @@ class PwrAdapter extends Device_1.default {
|
|
|
277
278
|
this.userSettings = props.user;
|
|
278
279
|
if (props && props.bikeSettings)
|
|
279
280
|
this.bikeSettings = props.bikeSettings;
|
|
280
|
-
this.logger.logEvent({ message: 'start requested', profile: this.getProfile(), props });
|
|
281
|
+
this.logger.logEvent({ message: 'csp: start requested', profile: this.getProfile(), props });
|
|
281
282
|
try {
|
|
282
283
|
const bleDevice = yield this.ble.connectDevice(this.device);
|
|
283
284
|
if (bleDevice) {
|
package/lib/ble/tacx.js
CHANGED
|
@@ -673,7 +673,7 @@ class TacxBleFEAdapter extends fm_1.FmAdapter {
|
|
|
673
673
|
}
|
|
674
674
|
start(props) {
|
|
675
675
|
return __awaiter(this, void 0, void 0, function* () {
|
|
676
|
-
this.logger.logEvent({ message: 'start requested', profile: this.getProfile(), props });
|
|
676
|
+
this.logger.logEvent({ message: 'tacx: start requested', profile: this.getProfile(), props });
|
|
677
677
|
if (this.ble.isScanning())
|
|
678
678
|
yield this.ble.stopScan();
|
|
679
679
|
try {
|
package/lib/ble/wahoo-kickr.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export default class WahooAdvancedFitnessMachineDevice extends BleFitnessMachine
|
|
|
36
36
|
tsPrevWrite: any;
|
|
37
37
|
prevSlope: any;
|
|
38
38
|
wahooCP: string;
|
|
39
|
+
isSimMode: boolean;
|
|
39
40
|
constructor(props?: any);
|
|
40
41
|
isMatching(characteristics: string[]): boolean;
|
|
41
42
|
init(): Promise<boolean>;
|
package/lib/ble/wahoo-kickr.js
CHANGED
|
@@ -71,6 +71,11 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
71
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
72
|
try {
|
|
73
73
|
yield this.subscribeWriteResponse(this.wahooCP);
|
|
74
|
+
try {
|
|
75
|
+
yield this.subscribeWriteResponse(consts_1.WAHOO_ADVANCED_TRAINER_CP_FULL.toLowerCase());
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
}
|
|
74
79
|
yield _super.initDevice.call(this);
|
|
75
80
|
return true;
|
|
76
81
|
}
|
|
@@ -81,6 +86,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
81
86
|
});
|
|
82
87
|
}
|
|
83
88
|
setCharacteristicUUIDs(uuids) {
|
|
89
|
+
this.logEvent({ message: 'set uuids', uuids });
|
|
84
90
|
uuids.forEach(c => {
|
|
85
91
|
if ((0, ble_1.matches)(c, consts_1.WAHOO_ADVANCED_TRAINER_CP))
|
|
86
92
|
this.wahooCP = c;
|
|
@@ -163,9 +169,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
163
169
|
onData(characteristic, data) {
|
|
164
170
|
super.onData(characteristic, data);
|
|
165
171
|
const isDuplicate = this.checkForDuplicate(characteristic, data);
|
|
166
|
-
|
|
167
|
-
return;
|
|
168
|
-
const uuid = characteristic.toLocaleLowerCase();
|
|
172
|
+
const uuid = characteristic.toLowerCase();
|
|
169
173
|
let res = undefined;
|
|
170
174
|
switch (uuid) {
|
|
171
175
|
case '2a63':
|
|
@@ -181,6 +185,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
181
185
|
res = this.parseFitnessMachineStatus(data);
|
|
182
186
|
break;
|
|
183
187
|
default:
|
|
188
|
+
this.logEvent({ message: 'data', uuid, data: data.toString('hex') });
|
|
184
189
|
break;
|
|
185
190
|
}
|
|
186
191
|
if (res)
|
|
@@ -192,14 +197,14 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
192
197
|
const opcode = Buffer.alloc(1);
|
|
193
198
|
opcode.writeUInt8(requestedOpCode, 0);
|
|
194
199
|
const message = Buffer.concat([opcode, data]);
|
|
200
|
+
this.logEvent({ message: 'wahoo cp:write', data: message.toString('hex') });
|
|
195
201
|
const res = yield this.write(this.wahooCP, message);
|
|
196
202
|
const responseData = Buffer.from(res);
|
|
197
203
|
const result = responseData.readUInt8(0);
|
|
198
|
-
this.logEvent({ message: 'response', opCode: requestedOpCode, response: responseData.toString('hex') });
|
|
199
204
|
return result === 1;
|
|
200
205
|
}
|
|
201
206
|
catch (err) {
|
|
202
|
-
this.logEvent({ message: '
|
|
207
|
+
this.logEvent({ message: 'wahoo cp:write failed', opCode: requestedOpCode, reason: err.message });
|
|
203
208
|
return false;
|
|
204
209
|
}
|
|
205
210
|
});
|
|
@@ -209,8 +214,6 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
209
214
|
if (this.hasControl)
|
|
210
215
|
return true;
|
|
211
216
|
this.logEvent({ message: 'requestControl' });
|
|
212
|
-
this.hasControl = true;
|
|
213
|
-
return;
|
|
214
217
|
const data = Buffer.alloc(2);
|
|
215
218
|
data.writeUInt8(0xEE, 0);
|
|
216
219
|
data.writeUInt8(0xFC, 1);
|
|
@@ -238,61 +241,105 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
238
241
|
}
|
|
239
242
|
setErgMode(power) {
|
|
240
243
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
|
|
244
|
+
this.logger.logEvent({ message: 'setErgMode', power });
|
|
245
|
+
try {
|
|
246
|
+
if (this.isPowerAdjusting())
|
|
247
|
+
return false;
|
|
248
|
+
const data = Buffer.alloc(2);
|
|
249
|
+
data.writeInt16LE(Math.round(power), 0);
|
|
250
|
+
const res = yield this.writeWahooFtmsMessage(66, data);
|
|
251
|
+
if (res === true) {
|
|
252
|
+
this.setPowerAdjusting();
|
|
253
|
+
this.data.targetPower = power;
|
|
254
|
+
this.isSimMode = false;
|
|
255
|
+
}
|
|
256
|
+
return res;
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
this.logEvent({ message: 'error', fn: 'setErgMode', error: err.message || err, stack: err.stack });
|
|
242
260
|
return false;
|
|
243
|
-
const data = Buffer.alloc(2);
|
|
244
|
-
data.writeInt16LE(Math.round(power), 0);
|
|
245
|
-
const res = yield this.writeWahooFtmsMessage(66, data);
|
|
246
|
-
if (res === true) {
|
|
247
|
-
this.setPowerAdjusting();
|
|
248
|
-
this.data.targetPower = power;
|
|
249
261
|
}
|
|
250
|
-
return res;
|
|
251
262
|
});
|
|
252
263
|
}
|
|
253
264
|
setSimMode(weight, crr, cw) {
|
|
254
265
|
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
266
|
+
this.logger.logEvent({ message: 'setSimMode', weight, crr, cw });
|
|
267
|
+
try {
|
|
268
|
+
const data = Buffer.alloc(6);
|
|
269
|
+
data.writeInt16LE(Math.round(weight * 100), 0);
|
|
270
|
+
data.writeInt16LE(Math.round(crr * 10000), 2);
|
|
271
|
+
data.writeInt16LE(Math.round(cw * 1000), 4);
|
|
272
|
+
const res = yield this.writeWahooFtmsMessage(67, data);
|
|
273
|
+
this.isSimMode = true;
|
|
274
|
+
return res;
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
this.logEvent({ message: 'error', fn: 'setSimMode', error: err.message || err, stack: err.stack });
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
261
280
|
});
|
|
262
281
|
}
|
|
263
282
|
setSimCRR(crr) {
|
|
264
283
|
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
284
|
+
this.logger.logEvent({ message: 'setSimCRR', crr });
|
|
285
|
+
try {
|
|
286
|
+
const data = Buffer.alloc(2);
|
|
287
|
+
data.writeInt16LE(Math.round(crr * 10000), 0);
|
|
288
|
+
const res = yield this.writeWahooFtmsMessage(68, data);
|
|
289
|
+
return res;
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
this.logEvent({ message: 'error', fn: 'setSimCRR', error: err.message || err, stack: err.stack });
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
269
295
|
});
|
|
270
296
|
}
|
|
271
297
|
setSimWindResistance(cw) {
|
|
272
298
|
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
299
|
+
this.logger.logEvent({ message: 'setSimWindResistance', cw });
|
|
300
|
+
try {
|
|
301
|
+
const data = Buffer.alloc(2);
|
|
302
|
+
data.writeInt16LE(Math.round(cw * 1000), 0);
|
|
303
|
+
const res = yield this.writeWahooFtmsMessage(69, data);
|
|
304
|
+
return res;
|
|
305
|
+
}
|
|
306
|
+
catch (err) {
|
|
307
|
+
this.logEvent({ message: 'error', fn: 'setSimWindResistance', error: err.message || err, stack: err.stack });
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
277
310
|
});
|
|
278
311
|
}
|
|
279
312
|
setSimGrade(slope) {
|
|
280
313
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
314
|
+
this.logger.logEvent({ message: 'setSimGrade', slope });
|
|
315
|
+
try {
|
|
316
|
+
const value = (Math.min(1, Math.max(-1, slope)) + 1.0) * 65535 / 2.0;
|
|
317
|
+
const slopeVal = Math.floor(value);
|
|
318
|
+
const data = Buffer.alloc(2);
|
|
319
|
+
data.writeInt16LE(slopeVal, 0);
|
|
320
|
+
const res = yield this.writeWahooFtmsMessage(70, data);
|
|
321
|
+
return res;
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
this.logEvent({ message: 'error', fn: 'setSimGrade', error: err.message || err, stack: err.stack });
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
287
327
|
});
|
|
288
328
|
}
|
|
289
329
|
setSimWindSpeed(v) {
|
|
290
330
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
331
|
+
this.logger.logEvent({ message: 'setSimWindSpeed', v });
|
|
332
|
+
try {
|
|
333
|
+
const value = (Math.max(-32.767, Math.min(32.767, v)) + 32.767) * 1000;
|
|
334
|
+
const data = Buffer.alloc(2);
|
|
335
|
+
data.writeInt16LE(Math.round(value), 0);
|
|
336
|
+
const res = yield this.writeWahooFtmsMessage(71, data);
|
|
337
|
+
return res;
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
this.logEvent({ message: 'error', fn: 'setSimWindSpeed', error: err.message || err, stack: err.stack });
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
296
343
|
});
|
|
297
344
|
}
|
|
298
345
|
setTargetPower(power) {
|
|
@@ -316,7 +363,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
316
363
|
try {
|
|
317
364
|
const hasControl = yield this.requestControl();
|
|
318
365
|
if (!hasControl) {
|
|
319
|
-
this.logEvent({ message: '
|
|
366
|
+
this.logEvent({ message: 'setSlope failed', reason: 'control is disabled' });
|
|
320
367
|
return false;
|
|
321
368
|
}
|
|
322
369
|
const res = yield this.setSimGrade(slope);
|
|
@@ -332,6 +379,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
332
379
|
}
|
|
333
380
|
reset() {
|
|
334
381
|
this.data = {};
|
|
382
|
+
this.isSimMode = undefined;
|
|
335
383
|
}
|
|
336
384
|
}
|
|
337
385
|
exports.default = WahooAdvancedFitnessMachineDevice;
|
|
@@ -359,12 +407,14 @@ class WahooAdvancedFmAdapter extends fm_1.FmAdapter {
|
|
|
359
407
|
}
|
|
360
408
|
start(props) {
|
|
361
409
|
return __awaiter(this, void 0, void 0, function* () {
|
|
362
|
-
this.logger.logEvent({ message: 'start requested', profile: this.getProfile(), props });
|
|
363
|
-
if (this.ble.isScanning())
|
|
364
|
-
yield this.ble.stopScan();
|
|
410
|
+
this.logger.logEvent({ message: 'wahoo: start requested', profile: this.getProfile(), props, isScanning: this.ble.isScanning() });
|
|
365
411
|
try {
|
|
412
|
+
this.logger.logEvent({ message: 'wahoo: stop previous scan', isScanning: this.ble.isScanning() });
|
|
413
|
+
if (this.ble.isScanning())
|
|
414
|
+
yield this.ble.stopScan();
|
|
415
|
+
this.logger.logEvent({ message: 'wahoo trying device connect' });
|
|
366
416
|
const bleDevice = yield this.ble.connectDevice(this.device);
|
|
367
|
-
|
|
417
|
+
this.logger.logEvent({ message: 'wahoo device connected', connected: (bleDevice !== null && bleDevice !== undefined) });
|
|
368
418
|
if (bleDevice) {
|
|
369
419
|
this.device = bleDevice;
|
|
370
420
|
const mode = this.getCyclingMode();
|
|
@@ -384,8 +434,8 @@ class WahooAdvancedFmAdapter extends fm_1.FmAdapter {
|
|
|
384
434
|
}
|
|
385
435
|
}
|
|
386
436
|
const { user } = props || {};
|
|
387
|
-
const weight = (user && user.weight ? user.weight : Device_1.DEFAULT_USER_WEIGHT) + Device_1.DEFAULT_BIKE_WEIGHT;
|
|
388
|
-
this.device.setSimMode(weight, this.device.getCrr(), this.device.getCw());
|
|
437
|
+
const weight = (user && user.weight ? Number(user.weight) : Device_1.DEFAULT_USER_WEIGHT) + Device_1.DEFAULT_BIKE_WEIGHT;
|
|
438
|
+
yield this.device.setSimMode(weight, this.device.getCrr(), this.device.getCw());
|
|
389
439
|
const startRequest = this.getCyclingMode().getBikeInitRequest();
|
|
390
440
|
yield this.sendUpdate(startRequest);
|
|
391
441
|
bleDevice.on('data', (data) => {
|