incyclist-devices 3.0.49 → 3.0.51
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/cjs/ble/base/interface.js +9 -2
- package/lib/cjs/ble/zwift/play/sensor.js +38 -39
- package/lib/cjs/serial/kettler/ergo-racer/adapter.js +3 -0
- package/lib/esm/ble/base/interface.js +9 -2
- package/lib/esm/ble/zwift/play/sensor.js +38 -39
- package/lib/esm/serial/kettler/ergo-racer/adapter.js +3 -0
- package/lib/types/ble/zwift/play/sensor.d.ts +4 -1
- package/package.json +1 -1
|
@@ -365,7 +365,8 @@ class BleInterface extends node_events_1.EventEmitter {
|
|
|
365
365
|
const { peripheral } = service;
|
|
366
366
|
if (peripheral.address === undefined || peripheral.address === '')
|
|
367
367
|
peripheral.address = peripheral.id || peripheral.name;
|
|
368
|
-
|
|
368
|
+
const isZwiftFC82Controller = service.name === 'Zwift Ride' || service.name === 'Zwift Click';
|
|
369
|
+
if (isZwiftFC82Controller && service.serviceUUIDs.some(uuid => (0, utils_js_1.matches)(uuid, 'FC82'))) {
|
|
369
370
|
const protocol = 'zwift-play';
|
|
370
371
|
const { id, name, address } = (0, utils_js_1.getPeripheralInfo)(peripheral);
|
|
371
372
|
return { interface: BleInterface.INTERFACE_NAME, protocol, id, name, address };
|
|
@@ -684,8 +685,13 @@ class BleInterface extends node_events_1.EventEmitter {
|
|
|
684
685
|
return false;
|
|
685
686
|
const found = service.serviceUUIDs.map(utils_js_1.parseUUID);
|
|
686
687
|
const expected = this.expectedServices.map(utils_js_1.parseUUID);
|
|
687
|
-
if (service.name.startsWith('Zwift'))
|
|
688
|
+
if (service.name.startsWith('Zwift')) {
|
|
689
|
+
if (isZwiftClickV2Right(service.manufacturerData)) {
|
|
690
|
+
this.logEvent({ message: 'Zwift Click v2 right side ignored', address: service.peripheral?.address });
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
688
693
|
return true;
|
|
694
|
+
}
|
|
689
695
|
const supported = found.filter(uuid => expected.includes(uuid)) ?? [];
|
|
690
696
|
if (!supported.length) {
|
|
691
697
|
this.logEvent({ message: 'peripheral not supported', name: service.name, uuids: service.serviceUUIDs });
|
|
@@ -855,3 +861,4 @@ class BleInterfaceFactory extends types_js_1.InterfaceFactory {
|
|
|
855
861
|
}
|
|
856
862
|
}
|
|
857
863
|
exports.BleInterfaceFactory = BleInterfaceFactory;
|
|
864
|
+
const isZwiftClickV2Right = (manufacturerData) => manufacturerData?.length >= 3 && manufacturerData[0] === 0x4a && manufacturerData[1] === 0x09 && manufacturerData[2] === 0x0a;
|
|
@@ -7,6 +7,15 @@ const utils_js_1 = require("../../../utils/utils.js");
|
|
|
7
7
|
const utils_js_2 = require("../../utils.js");
|
|
8
8
|
const node_events_1 = require("node:events");
|
|
9
9
|
const index_js_1 = require("../../../bindings/index.js");
|
|
10
|
+
const ZWIFT_DEVICE_TYPES = {
|
|
11
|
+
0x02: 'right',
|
|
12
|
+
0x03: 'left',
|
|
13
|
+
0x07: 'ride-right',
|
|
14
|
+
0x08: 'ride-left',
|
|
15
|
+
0x09: 'click',
|
|
16
|
+
0x0A: 'click-v2-right',
|
|
17
|
+
0x0B: 'click-v2-left',
|
|
18
|
+
};
|
|
10
19
|
class BleZwiftPlaySensor extends sensor_js_1.TBleSensor {
|
|
11
20
|
static profile = 'Controller';
|
|
12
21
|
static protocol = 'zwift-play';
|
|
@@ -132,25 +141,7 @@ class BleZwiftPlaySensor extends sensor_js_1.TBleSensor {
|
|
|
132
141
|
}
|
|
133
142
|
else if (this.peripheral?.getManufacturerData) {
|
|
134
143
|
const manufacturerData = this.getManufacturerData();
|
|
135
|
-
|
|
136
|
-
const typeVal = Number('0x' + manufacturerData.substring(2, 4));
|
|
137
|
-
if (typeVal === 9) {
|
|
138
|
-
this.deviceType = 'click';
|
|
139
|
-
this.encrypted = false;
|
|
140
|
-
}
|
|
141
|
-
else if (typeVal === 2) {
|
|
142
|
-
this.deviceType = 'right';
|
|
143
|
-
}
|
|
144
|
-
else if (typeVal === 3) {
|
|
145
|
-
this.deviceType = 'left';
|
|
146
|
-
}
|
|
147
|
-
else if (typeVal === 7) {
|
|
148
|
-
this.deviceType = 'ride-right';
|
|
149
|
-
}
|
|
150
|
-
else if (typeVal === 8) {
|
|
151
|
-
this.deviceType = 'ride-left';
|
|
152
|
-
}
|
|
153
|
-
}
|
|
144
|
+
this.setDeviceTypeFromManufacturerData(manufacturerData);
|
|
154
145
|
}
|
|
155
146
|
console.log('# [ZwiftPlay] device type ', this.deviceType, this.peripheral?.getInfo().name, this.peripheral?.getInfo().address);
|
|
156
147
|
if (!this.deviceType && !this.encryptedSupported()) {
|
|
@@ -477,7 +468,7 @@ class BleZwiftPlaySensor extends sensor_js_1.TBleSensor {
|
|
|
477
468
|
});
|
|
478
469
|
this.rideKeyPadStates.forEach((state, bit) => {
|
|
479
470
|
if (!currentPresses.has(bit) && state.pressed) {
|
|
480
|
-
const keyName = buttonNames.get(bit);
|
|
471
|
+
const keyName = this.getKeyName(buttonNames.get(bit));
|
|
481
472
|
const duration = Date.now() - state.timestamp;
|
|
482
473
|
this.logEvent({ message: 'key pressed', key: keyName, name, address, duration, deviceType: this.deviceType });
|
|
483
474
|
this.emit('key-pressed', { key: keyName, duration, deviceType: this.deviceType });
|
|
@@ -644,25 +635,7 @@ class BleZwiftPlaySensor extends sensor_js_1.TBleSensor {
|
|
|
644
635
|
}
|
|
645
636
|
else if (this.peripheral?.getManufacturerData) {
|
|
646
637
|
manufacturerData = this.getManufacturerData();
|
|
647
|
-
|
|
648
|
-
const typeVal = Number('0x' + manufacturerData.substring(2, 4));
|
|
649
|
-
if (typeVal === 9) {
|
|
650
|
-
this.deviceType = 'click';
|
|
651
|
-
this.encrypted = false;
|
|
652
|
-
}
|
|
653
|
-
else if (typeVal === 2) {
|
|
654
|
-
this.deviceType = 'right';
|
|
655
|
-
}
|
|
656
|
-
else if (typeVal === 3) {
|
|
657
|
-
this.deviceType = 'left';
|
|
658
|
-
}
|
|
659
|
-
else if (typeVal === 7) {
|
|
660
|
-
this.deviceType = 'ride-right';
|
|
661
|
-
}
|
|
662
|
-
else if (typeVal === 8) {
|
|
663
|
-
this.deviceType = 'ride-left';
|
|
664
|
-
}
|
|
665
|
-
}
|
|
638
|
+
this.setDeviceTypeFromManufacturerData(manufacturerData);
|
|
666
639
|
}
|
|
667
640
|
if (!this.deviceType && !this.encryptedSupported()) {
|
|
668
641
|
this.deviceType = 'click';
|
|
@@ -674,6 +647,9 @@ class BleZwiftPlaySensor extends sensor_js_1.TBleSensor {
|
|
|
674
647
|
if (this.isFM) {
|
|
675
648
|
message = Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x01])]);
|
|
676
649
|
}
|
|
650
|
+
else if (this.isClickV2()) {
|
|
651
|
+
message = Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x03])]);
|
|
652
|
+
}
|
|
677
653
|
else if (this.encrypted) {
|
|
678
654
|
const { publicKey, privateKey } = this.createKeyPair();
|
|
679
655
|
this.privateKey = this.privateKey ?? Buffer.from(privateKey);
|
|
@@ -697,6 +673,29 @@ class BleZwiftPlaySensor extends sensor_js_1.TBleSensor {
|
|
|
697
673
|
}
|
|
698
674
|
reset() {
|
|
699
675
|
}
|
|
676
|
+
setDeviceTypeFromManufacturerData(manufacturerData) {
|
|
677
|
+
if (!manufacturerData?.startsWith('4a09'))
|
|
678
|
+
return;
|
|
679
|
+
const deviceType = ZWIFT_DEVICE_TYPES[Number('0x' + manufacturerData.substring(4, 6))];
|
|
680
|
+
if (!deviceType)
|
|
681
|
+
return;
|
|
682
|
+
this.deviceType = deviceType;
|
|
683
|
+
if (deviceType === 'click')
|
|
684
|
+
this.encrypted = false;
|
|
685
|
+
}
|
|
686
|
+
getKeyName(rideKeyName) {
|
|
687
|
+
this.getDeviceType();
|
|
688
|
+
if (!this.isClickV2())
|
|
689
|
+
return rideKeyName;
|
|
690
|
+
if (rideKeyName === 'r-shift-up')
|
|
691
|
+
return 'up';
|
|
692
|
+
if (rideKeyName === 'l-shift-up')
|
|
693
|
+
return 'down';
|
|
694
|
+
return rideKeyName;
|
|
695
|
+
}
|
|
696
|
+
isClickV2() {
|
|
697
|
+
return this.deviceType === 'click-v2-left' || this.deviceType === 'click-v2-right';
|
|
698
|
+
}
|
|
700
699
|
getManufacturerData() {
|
|
701
700
|
const data = this.peripheral?.getManufacturerData?.();
|
|
702
701
|
if (typeof data === 'string')
|
|
@@ -283,6 +283,7 @@ class KettlerRacerAdapter extends adapter_js_1.SerialIncyclistDevice {
|
|
|
283
283
|
return info.data;
|
|
284
284
|
}
|
|
285
285
|
catch (err) {
|
|
286
|
+
this.started = false;
|
|
286
287
|
try {
|
|
287
288
|
await this.reset();
|
|
288
289
|
}
|
|
@@ -293,6 +294,7 @@ class KettlerRacerAdapter extends adapter_js_1.SerialIncyclistDevice {
|
|
|
293
294
|
}
|
|
294
295
|
}, 5, 1000)
|
|
295
296
|
.then((data) => {
|
|
297
|
+
this.started = true;
|
|
296
298
|
this.startUpdatePull();
|
|
297
299
|
return true;
|
|
298
300
|
});
|
|
@@ -318,6 +320,7 @@ class KettlerRacerAdapter extends adapter_js_1.SerialIncyclistDevice {
|
|
|
318
320
|
}
|
|
319
321
|
stop() {
|
|
320
322
|
this.logEvent({ message: 'stop request' });
|
|
323
|
+
this.started = false;
|
|
321
324
|
return new Promise(async (resolve, reject) => {
|
|
322
325
|
try {
|
|
323
326
|
if (this.iv) {
|
|
@@ -362,7 +362,8 @@ export class BleInterface extends EventEmitter {
|
|
|
362
362
|
const { peripheral } = service;
|
|
363
363
|
if (peripheral.address === undefined || peripheral.address === '')
|
|
364
364
|
peripheral.address = peripheral.id || peripheral.name;
|
|
365
|
-
|
|
365
|
+
const isZwiftFC82Controller = service.name === 'Zwift Ride' || service.name === 'Zwift Click';
|
|
366
|
+
if (isZwiftFC82Controller && service.serviceUUIDs.some(uuid => matches(uuid, 'FC82'))) {
|
|
366
367
|
const protocol = 'zwift-play';
|
|
367
368
|
const { id, name, address } = getPeripheralInfo(peripheral);
|
|
368
369
|
return { interface: BleInterface.INTERFACE_NAME, protocol, id, name, address };
|
|
@@ -681,8 +682,13 @@ export class BleInterface extends EventEmitter {
|
|
|
681
682
|
return false;
|
|
682
683
|
const found = service.serviceUUIDs.map(parseUUID);
|
|
683
684
|
const expected = this.expectedServices.map(parseUUID);
|
|
684
|
-
if (service.name.startsWith('Zwift'))
|
|
685
|
+
if (service.name.startsWith('Zwift')) {
|
|
686
|
+
if (isZwiftClickV2Right(service.manufacturerData)) {
|
|
687
|
+
this.logEvent({ message: 'Zwift Click v2 right side ignored', address: service.peripheral?.address });
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
685
690
|
return true;
|
|
691
|
+
}
|
|
686
692
|
const supported = found.filter(uuid => expected.includes(uuid)) ?? [];
|
|
687
693
|
if (!supported.length) {
|
|
688
694
|
this.logEvent({ message: 'peripheral not supported', name: service.name, uuids: service.serviceUUIDs });
|
|
@@ -850,3 +856,4 @@ export class BleInterfaceFactory extends InterfaceFactory {
|
|
|
850
856
|
return this.iface;
|
|
851
857
|
}
|
|
852
858
|
}
|
|
859
|
+
const isZwiftClickV2Right = (manufacturerData) => manufacturerData?.length >= 3 && manufacturerData[0] === 0x4a && manufacturerData[1] === 0x09 && manufacturerData[2] === 0x0a;
|
|
@@ -4,6 +4,15 @@ import { sleep } from "../../../utils/utils.js";
|
|
|
4
4
|
import { beautifyUUID, fullUUID } from "../../utils.js";
|
|
5
5
|
import { EventEmitter } from "node:events";
|
|
6
6
|
import { BindingsFactory } from "../../../bindings/index.js";
|
|
7
|
+
const ZWIFT_DEVICE_TYPES = {
|
|
8
|
+
0x02: 'right',
|
|
9
|
+
0x03: 'left',
|
|
10
|
+
0x07: 'ride-right',
|
|
11
|
+
0x08: 'ride-left',
|
|
12
|
+
0x09: 'click',
|
|
13
|
+
0x0A: 'click-v2-right',
|
|
14
|
+
0x0B: 'click-v2-left',
|
|
15
|
+
};
|
|
7
16
|
export class BleZwiftPlaySensor extends TBleSensor {
|
|
8
17
|
static profile = 'Controller';
|
|
9
18
|
static protocol = 'zwift-play';
|
|
@@ -129,25 +138,7 @@ export class BleZwiftPlaySensor extends TBleSensor {
|
|
|
129
138
|
}
|
|
130
139
|
else if (this.peripheral?.getManufacturerData) {
|
|
131
140
|
const manufacturerData = this.getManufacturerData();
|
|
132
|
-
|
|
133
|
-
const typeVal = Number('0x' + manufacturerData.substring(2, 4));
|
|
134
|
-
if (typeVal === 9) {
|
|
135
|
-
this.deviceType = 'click';
|
|
136
|
-
this.encrypted = false;
|
|
137
|
-
}
|
|
138
|
-
else if (typeVal === 2) {
|
|
139
|
-
this.deviceType = 'right';
|
|
140
|
-
}
|
|
141
|
-
else if (typeVal === 3) {
|
|
142
|
-
this.deviceType = 'left';
|
|
143
|
-
}
|
|
144
|
-
else if (typeVal === 7) {
|
|
145
|
-
this.deviceType = 'ride-right';
|
|
146
|
-
}
|
|
147
|
-
else if (typeVal === 8) {
|
|
148
|
-
this.deviceType = 'ride-left';
|
|
149
|
-
}
|
|
150
|
-
}
|
|
141
|
+
this.setDeviceTypeFromManufacturerData(manufacturerData);
|
|
151
142
|
}
|
|
152
143
|
console.log('# [ZwiftPlay] device type ', this.deviceType, this.peripheral?.getInfo().name, this.peripheral?.getInfo().address);
|
|
153
144
|
if (!this.deviceType && !this.encryptedSupported()) {
|
|
@@ -474,7 +465,7 @@ export class BleZwiftPlaySensor extends TBleSensor {
|
|
|
474
465
|
});
|
|
475
466
|
this.rideKeyPadStates.forEach((state, bit) => {
|
|
476
467
|
if (!currentPresses.has(bit) && state.pressed) {
|
|
477
|
-
const keyName = buttonNames.get(bit);
|
|
468
|
+
const keyName = this.getKeyName(buttonNames.get(bit));
|
|
478
469
|
const duration = Date.now() - state.timestamp;
|
|
479
470
|
this.logEvent({ message: 'key pressed', key: keyName, name, address, duration, deviceType: this.deviceType });
|
|
480
471
|
this.emit('key-pressed', { key: keyName, duration, deviceType: this.deviceType });
|
|
@@ -641,25 +632,7 @@ export class BleZwiftPlaySensor extends TBleSensor {
|
|
|
641
632
|
}
|
|
642
633
|
else if (this.peripheral?.getManufacturerData) {
|
|
643
634
|
manufacturerData = this.getManufacturerData();
|
|
644
|
-
|
|
645
|
-
const typeVal = Number('0x' + manufacturerData.substring(2, 4));
|
|
646
|
-
if (typeVal === 9) {
|
|
647
|
-
this.deviceType = 'click';
|
|
648
|
-
this.encrypted = false;
|
|
649
|
-
}
|
|
650
|
-
else if (typeVal === 2) {
|
|
651
|
-
this.deviceType = 'right';
|
|
652
|
-
}
|
|
653
|
-
else if (typeVal === 3) {
|
|
654
|
-
this.deviceType = 'left';
|
|
655
|
-
}
|
|
656
|
-
else if (typeVal === 7) {
|
|
657
|
-
this.deviceType = 'ride-right';
|
|
658
|
-
}
|
|
659
|
-
else if (typeVal === 8) {
|
|
660
|
-
this.deviceType = 'ride-left';
|
|
661
|
-
}
|
|
662
|
-
}
|
|
635
|
+
this.setDeviceTypeFromManufacturerData(manufacturerData);
|
|
663
636
|
}
|
|
664
637
|
if (!this.deviceType && !this.encryptedSupported()) {
|
|
665
638
|
this.deviceType = 'click';
|
|
@@ -671,6 +644,9 @@ export class BleZwiftPlaySensor extends TBleSensor {
|
|
|
671
644
|
if (this.isFM) {
|
|
672
645
|
message = Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x01])]);
|
|
673
646
|
}
|
|
647
|
+
else if (this.isClickV2()) {
|
|
648
|
+
message = Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x03])]);
|
|
649
|
+
}
|
|
674
650
|
else if (this.encrypted) {
|
|
675
651
|
const { publicKey, privateKey } = this.createKeyPair();
|
|
676
652
|
this.privateKey = this.privateKey ?? Buffer.from(privateKey);
|
|
@@ -694,6 +670,29 @@ export class BleZwiftPlaySensor extends TBleSensor {
|
|
|
694
670
|
}
|
|
695
671
|
reset() {
|
|
696
672
|
}
|
|
673
|
+
setDeviceTypeFromManufacturerData(manufacturerData) {
|
|
674
|
+
if (!manufacturerData?.startsWith('4a09'))
|
|
675
|
+
return;
|
|
676
|
+
const deviceType = ZWIFT_DEVICE_TYPES[Number('0x' + manufacturerData.substring(4, 6))];
|
|
677
|
+
if (!deviceType)
|
|
678
|
+
return;
|
|
679
|
+
this.deviceType = deviceType;
|
|
680
|
+
if (deviceType === 'click')
|
|
681
|
+
this.encrypted = false;
|
|
682
|
+
}
|
|
683
|
+
getKeyName(rideKeyName) {
|
|
684
|
+
this.getDeviceType();
|
|
685
|
+
if (!this.isClickV2())
|
|
686
|
+
return rideKeyName;
|
|
687
|
+
if (rideKeyName === 'r-shift-up')
|
|
688
|
+
return 'up';
|
|
689
|
+
if (rideKeyName === 'l-shift-up')
|
|
690
|
+
return 'down';
|
|
691
|
+
return rideKeyName;
|
|
692
|
+
}
|
|
693
|
+
isClickV2() {
|
|
694
|
+
return this.deviceType === 'click-v2-left' || this.deviceType === 'click-v2-right';
|
|
695
|
+
}
|
|
697
696
|
getManufacturerData() {
|
|
698
697
|
const data = this.peripheral?.getManufacturerData?.();
|
|
699
698
|
if (typeof data === 'string')
|
|
@@ -278,6 +278,7 @@ export default class KettlerRacerAdapter extends SerialIncyclistDevice {
|
|
|
278
278
|
return info.data;
|
|
279
279
|
}
|
|
280
280
|
catch (err) {
|
|
281
|
+
this.started = false;
|
|
281
282
|
try {
|
|
282
283
|
await this.reset();
|
|
283
284
|
}
|
|
@@ -288,6 +289,7 @@ export default class KettlerRacerAdapter extends SerialIncyclistDevice {
|
|
|
288
289
|
}
|
|
289
290
|
}, 5, 1000)
|
|
290
291
|
.then((data) => {
|
|
292
|
+
this.started = true;
|
|
291
293
|
this.startUpdatePull();
|
|
292
294
|
return true;
|
|
293
295
|
});
|
|
@@ -313,6 +315,7 @@ export default class KettlerRacerAdapter extends SerialIncyclistDevice {
|
|
|
313
315
|
}
|
|
314
316
|
stop() {
|
|
315
317
|
this.logEvent({ message: 'stop request' });
|
|
318
|
+
this.started = false;
|
|
316
319
|
return new Promise(async (resolve, reject) => {
|
|
317
320
|
try {
|
|
318
321
|
if (this.iv) {
|
|
@@ -13,7 +13,7 @@ type BleZwiftPlaySensorProps = {
|
|
|
13
13
|
logger?: EventLogger;
|
|
14
14
|
isTrainer?: boolean;
|
|
15
15
|
};
|
|
16
|
-
type DeviceType = 'left' | 'right' | 'click' | 'hub' | 'ride-left' | 'ride-right';
|
|
16
|
+
type DeviceType = 'left' | 'right' | 'click' | 'hub' | 'ride-left' | 'ride-right' | 'click-v2-left' | 'click-v2-right';
|
|
17
17
|
type PendingMeasurement = {
|
|
18
18
|
type: number;
|
|
19
19
|
buffer: Buffer;
|
|
@@ -87,6 +87,9 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
|
|
|
87
87
|
read(characteristic: string, ignoreErrors?: boolean): Promise<Buffer | null>;
|
|
88
88
|
pair(): Promise<boolean>;
|
|
89
89
|
reset(): void;
|
|
90
|
+
protected setDeviceTypeFromManufacturerData(manufacturerData: string | undefined): void;
|
|
91
|
+
protected getKeyName(rideKeyName: string): string;
|
|
92
|
+
protected isClickV2(): boolean;
|
|
90
93
|
getManufacturerData(): string;
|
|
91
94
|
protected getCrypto(): ICryptoBinding;
|
|
92
95
|
protected encryptedSupported(): boolean;
|