incyclist-devices 2.4.9 → 2.4.10

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.
@@ -19,6 +19,7 @@ export default class IncyclistDevice<P extends DeviceProperties> extends EventEm
19
19
  protected static controllers: ControllerConfig;
20
20
  protected user: User;
21
21
  protected data: IncyclistAdapterData;
22
+ protected debugLogEnabled: boolean;
22
23
  constructor(settings: DeviceSettings, props?: P);
23
24
  supportsVirtualShifting(): boolean;
24
25
  getLogger(): EventLogger;
@@ -73,5 +74,6 @@ export default class IncyclistDevice<P extends DeviceProperties> extends EventEm
73
74
  onData(callback: OnDeviceDataCallback): void;
74
75
  onScanStart(): void;
75
76
  onScanStop(): void;
77
+ protected initDebugLog(): void;
76
78
  }
77
79
  export type IncyclistDeviceAdapter = IncyclistDevice<DeviceProperties>;
@@ -31,6 +31,7 @@ class IncyclistDevice extends events_1.default {
31
31
  this.user = {};
32
32
  this.data = {};
33
33
  this.cyclingMode = this.getDefaultCyclingMode();
34
+ this.debugLogEnabled = false;
34
35
  }
35
36
  supportsVirtualShifting() {
36
37
  return false;
@@ -46,11 +47,9 @@ class IncyclistDevice extends events_1.default {
46
47
  logEvent(event) {
47
48
  if (!this.logger || this.paused)
48
49
  return;
50
+ if (this.isDebugEnabled() && !this.debugLogEnabled)
51
+ this.initDebugLog();
49
52
  this.logger.logEvent(event);
50
- if (this.isDebugEnabled()) {
51
- const logText = `~~~ ${this.getInterface()}: ${this.logger.getName()}`;
52
- console.log(logText, event);
53
- }
54
53
  }
55
54
  getName() {
56
55
  return this.settings.name;
@@ -298,6 +297,26 @@ class IncyclistDevice extends events_1.default {
298
297
  onScanStop() {
299
298
  this.scanning = false;
300
299
  }
300
+ initDebugLog() {
301
+ if (this.debugLogEnabled) {
302
+ return;
303
+ }
304
+ if (this.isDebugEnabled() && this.logger) {
305
+ const logText = `~~~ ${this.getInterface()}: ${this.logger.getName()}`;
306
+ const logEvent = this.logger.logEvent.bind(this.logger);
307
+ this.logger.logEvent = (event) => {
308
+ try {
309
+ logEvent(event);
310
+ }
311
+ catch (_a) { }
312
+ try {
313
+ console.log(logText, event);
314
+ }
315
+ catch (_b) { }
316
+ };
317
+ this.debugLogEnabled = true;
318
+ }
319
+ }
301
320
  }
302
321
  IncyclistDevice.controllers = {};
303
322
  exports.default = IncyclistDevice;
@@ -145,8 +145,10 @@ class BleFmAdapter extends adapter_1.default {
145
145
  initVirtualShifting() {
146
146
  return __awaiter(this, void 0, void 0, function* () {
147
147
  var _a;
148
+ this.logEvent({ message: 'init virtual shifting', hasSensor: this.zwiftPlay !== undefined });
148
149
  try {
149
- this.zwiftPlay = (_a = this.zwiftPlay) !== null && _a !== void 0 ? _a : new play_1.BleZwiftPlaySensor(this.device);
150
+ this.zwiftPlay = (_a = this.zwiftPlay) !== null && _a !== void 0 ? _a : new play_1.BleZwiftPlaySensor(this.device, { logger: this.logger, isTrainer: true });
151
+ this.zwiftPlay.initHubService(false);
150
152
  }
151
153
  catch (err) {
152
154
  this.logEvent({ message: 'could not init virtual shifting', reason: err.message });
@@ -1,3 +1,4 @@
1
+ import { EventLogger } from "gd-eventlog";
1
2
  import { LegacyProfile } from "../../../antv2/types";
2
3
  import { HubCommand, HubRequest, SimulationParam } from "../../../proto/zwift_hub";
3
4
  import { TBleSensor } from "../../base/sensor";
@@ -7,7 +8,11 @@ type ButtonState = {
7
8
  pressed: boolean;
8
9
  timestamp: number;
9
10
  };
10
- type DeviceType = 'left' | 'right' | 'click';
11
+ type BleZwiftPlaySensorProps = {
12
+ logger?: EventLogger;
13
+ isTrainer?: boolean;
14
+ };
15
+ type DeviceType = 'left' | 'right' | 'click' | 'hub';
11
16
  export declare class BleZwiftPlaySensor extends TBleSensor {
12
17
  static readonly profile: LegacyProfile;
13
18
  static readonly protocol: BleProtocol;
@@ -15,7 +20,7 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
15
20
  static readonly characteristics: any[];
16
21
  static readonly detectionPriority = 1;
17
22
  protected emitter: EventEmitter;
18
- protected paired: boolean;
23
+ protected isHubPairConfirmed: boolean;
19
24
  protected encrypted: boolean;
20
25
  protected deviceKey: Buffer;
21
26
  protected prevClickMessage: string;
@@ -30,7 +35,9 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
30
35
  protected isHubServicePaired: boolean;
31
36
  protected isHubServiceSubscribed: boolean;
32
37
  protected initHubServicePromise: Promise<boolean>;
33
- constructor(peripheral: IBlePeripheral | TBleSensor, props?: any);
38
+ protected pairPromise: Promise<boolean>;
39
+ protected subscribePromise: Promise<boolean>;
40
+ constructor(peripheral: IBlePeripheral | TBleSensor, props?: BleZwiftPlaySensorProps);
34
41
  reconnectSensor(): Promise<void>;
35
42
  stopSensor(): Promise<boolean>;
36
43
  protected getRequiredCharacteristics(): Array<string>;
@@ -17,7 +17,12 @@ const crypto_1 = require("crypto");
17
17
  const events_1 = require("events");
18
18
  class BleZwiftPlaySensor extends sensor_1.TBleSensor {
19
19
  constructor(peripheral, props) {
20
- if (peripheral &&
20
+ if ((props === null || props === void 0 ? void 0 : props.isTrainer) && peripheral) {
21
+ const sensor = peripheral;
22
+ super(sensor.getPeripheral(), props);
23
+ this.isFM = true;
24
+ }
25
+ else if (peripheral &&
21
26
  'startSensor' in peripheral && typeof peripheral.startSensor === 'function' &&
22
27
  'getPeripheral' in peripheral && typeof peripheral.getPeripheral === 'function') {
23
28
  super(peripheral.getPeripheral(), props);
@@ -70,28 +75,35 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
70
75
  setSimulationData(data) {
71
76
  return __awaiter(this, void 0, void 0, function* () {
72
77
  var _a, _b, _c, _d;
73
- if (!this.isHubServiceActive) {
74
- yield this.initHubService(false);
78
+ try {
79
+ if (!this.isHubServiceActive) {
80
+ yield this.initHubService(false);
81
+ }
82
+ if (!this.isHubServiceActive || !this.isHubPairConfirmed)
83
+ return;
84
+ const crrx100000 = Math.round((_a = data === null || data === void 0 ? void 0 : data.crrx100000) !== null && _a !== void 0 ? _a : 400);
85
+ const cWax10000 = Math.round((_b = data === null || data === void 0 ? void 0 : data.cWax10000) !== null && _b !== void 0 ? _b : 5100);
86
+ const windx100 = Math.round((_c = data === null || data === void 0 ? void 0 : data.windx100) !== null && _c !== void 0 ? _c : 0);
87
+ let inclineX100 = Math.round((_d = data === null || data === void 0 ? void 0 : data.inclineX100) !== null && _d !== void 0 ? _d : 1);
88
+ if (inclineX100 === 0 || Number.isNaN(inclineX100))
89
+ inclineX100 = 1;
90
+ const simulation = { inclineX100, crrx100000, cWax10000, windx100 };
91
+ yield this.sendHubCommand({ simulation });
92
+ yield this.requestDataUpdate(512);
93
+ }
94
+ catch (err) {
95
+ this.logger.logEvent({ message: "error", fn: 'setSimulationData', data, error: err.message, stack: err.stack });
75
96
  }
76
- const crrx100000 = Math.round((_a = data === null || data === void 0 ? void 0 : data.crrx100000) !== null && _a !== void 0 ? _a : 400);
77
- const cWax10000 = Math.round((_b = data === null || data === void 0 ? void 0 : data.cWax10000) !== null && _b !== void 0 ? _b : 5100);
78
- const windx100 = Math.round((_c = data === null || data === void 0 ? void 0 : data.windx100) !== null && _c !== void 0 ? _c : 0);
79
- let inclineX100 = Math.round((_d = data === null || data === void 0 ? void 0 : data.inclineX100) !== null && _d !== void 0 ? _d : 1);
80
- if (inclineX100 === 0 || Number.isNaN(inclineX100))
81
- inclineX100 = 1;
82
- const simulation = { inclineX100, crrx100000, cWax10000, windx100 };
83
- console.log('# set simulation data', simulation);
84
- yield this.sendHubCommand({ simulation });
85
- yield this.requestDataUpdate(512);
86
97
  });
87
98
  }
88
99
  setGearRatio(gearRatio) {
89
100
  return __awaiter(this, void 0, void 0, function* () {
90
101
  try {
91
- console.log('# set gear ratio', gearRatio);
92
102
  if (!this.isHubServiceActive) {
93
103
  yield this.initHubService();
94
104
  }
105
+ if (!this.isHubServiceActive || !this.isHubPairConfirmed)
106
+ return;
95
107
  const gearRatioX10000 = Math.round(gearRatio * 10000);
96
108
  const bikeWeightx100 = 10 * 100;
97
109
  const riderWeightx100 = 75 * 100;
@@ -102,7 +114,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
102
114
  yield this.requestDataUpdate(512);
103
115
  }
104
116
  catch (err) {
105
- console.log('# set gear ratio failed', err);
117
+ this.logger.logEvent({ message: "error", fn: 'setGearRatio', gearRatio, error: err.message, stack: err.stack });
106
118
  }
107
119
  return gearRatio;
108
120
  });
@@ -115,6 +127,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
115
127
  }
116
128
  onMeasurement(d) {
117
129
  const data = Buffer.from(d);
130
+ this.logEvent({ message: 'got hub notification', raw: data.toString('hex') });
118
131
  if ((data === null || data === void 0 ? void 0 : data.length) < 1) {
119
132
  console.log('Invalid click measurement data', data.toString('hex'));
120
133
  return false;
@@ -144,22 +157,35 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
144
157
  }
145
158
  initHubService() {
146
159
  return __awaiter(this, arguments, void 0, function* (setSimulation = true) {
160
+ var _a;
147
161
  if (!this.isHubServiceActive && this.initHubServicePromise !== undefined) {
148
162
  yield this.initHubServicePromise;
149
163
  }
150
164
  if (this.isHubServiceActive)
151
165
  return true;
152
- this.logEvent({ message: 'init hub service', paired: this.paired, subscribed: this.isHubServiceSubscribed });
153
- console.log('# init Hub Service');
166
+ this.logEvent({ message: 'init hub service', paired: this.isHubPairConfirmed, subscribed: this.isHubServiceSubscribed });
154
167
  if (!this.isHubServicePaired) {
155
- yield this.pair();
168
+ this.logEvent({ message: 'pair hub service' });
169
+ this.pairPromise = this.pair();
170
+ const paired = yield this.pairPromise;
171
+ this.pairPromise = undefined;
172
+ if (!paired)
173
+ return false;
156
174
  }
157
175
  if (!this.isHubServiceSubscribed) {
158
- yield this.subscribe();
159
- this.isHubServiceSubscribed = true;
176
+ this.logEvent({ message: 'subscribe to hub service characteristics' });
177
+ this.subscribePromise = (_a = this.subscribePromise) !== null && _a !== void 0 ? _a : this.subscribe();
178
+ const subscribed = yield this.subscribePromise;
179
+ this.subscribePromise = undefined;
180
+ this.isHubServiceSubscribed = subscribed;
181
+ if (!subscribed)
182
+ return false;
183
+ this.logEvent({ message: 'subscribed to hub service characteristics' });
160
184
  }
161
185
  this.initHubServicePromise = new Promise((done) => {
186
+ this.logEvent({ message: 'send hub init message' });
162
187
  let timeout = setTimeout(() => {
188
+ this.logEvent({ message: 'could not init hub service', reason: 'timeout' });
163
189
  done(false);
164
190
  }, 2000);
165
191
  this.once('hub-riding-data', () => {
@@ -168,8 +194,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
168
194
  timeout = undefined;
169
195
  }
170
196
  this.isHubServiceActive = true;
171
- console.log('# init hub service completed');
172
- this.logEvent({ message: 'init hub service done', paired: this.paired, subscribed: this.isHubServiceSubscribed });
197
+ this.logEvent({ message: 'init hub service done', paired: this.isHubServicePaired, confirmed: this.isHubPairConfirmed, subscribed: this.isHubServiceSubscribed });
173
198
  if (setSimulation) {
174
199
  this.logEvent({ message: 'hub: send initial simulation data' });
175
200
  this.setSimulationData().then(() => {
@@ -189,7 +214,6 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
189
214
  clearTimeout(timeout);
190
215
  timeout = undefined;
191
216
  }
192
- console.log('# init hub service timeout');
193
217
  done(false);
194
218
  this.logEvent({ message: 'could not init hub service', reason: err.message });
195
219
  });
@@ -200,7 +224,6 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
200
224
  sendHubRequest(request) {
201
225
  return __awaiter(this, void 0, void 0, function* () {
202
226
  const message = Buffer.from(zwift_hub_1.HubRequest.toBinary(request));
203
- console.log('# sending hub request', request, message);
204
227
  this.logEvent({ mesage: 'send zwift hub request', request });
205
228
  return yield this.sendPlayCommand(0x00, message);
206
229
  });
@@ -208,7 +231,6 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
208
231
  sendHubCommand(command) {
209
232
  return __awaiter(this, void 0, void 0, function* () {
210
233
  const message = Buffer.from(zwift_hub_1.HubCommand.toBinary(command));
211
- console.log('# sending hub command', command, message);
212
234
  this.logEvent({ mesage: 'send zwift hub command', command });
213
235
  return yield this.sendPlayCommand(0x04, message);
214
236
  });
@@ -218,7 +240,6 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
218
240
  this.tsLastRidingData = Date.now();
219
241
  const data = zwift_hub_1.HubRidingData.fromBinary(m);
220
242
  this.emit('hub-riding-data', data);
221
- console.log('#riding data', data);
222
243
  this.logEvent({ message: 'riding data received', power: data.power, cadence: data.cadence, Speed: data.speedX100 / 100, heartrate: data.hR, unknown1: data.unknown1, unknown2: data.unknown2 });
223
244
  }
224
245
  catch (err) {
@@ -231,13 +252,11 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
231
252
  const { messageType, payload } = envelope;
232
253
  if (messageType < 16) {
233
254
  const deviceInfo = zwift_hub_1.DeviceInformationContent.fromBinary(payload);
234
- console.log('# deviceInfo', deviceInfo);
235
255
  this.emit('hub-device-info', deviceInfo);
236
256
  this.logEvent({ message: 'hub device info update', deviceInfo });
237
257
  }
238
258
  else if (messageType >= 512 && messageType < 526) {
239
259
  const si = zwift_hub_1.DeviceSettings.fromBinary(payload);
240
- console.log('# settings', si === null || si === void 0 ? void 0 : si.subContent);
241
260
  this.emit('hub-settings', si === null || si === void 0 ? void 0 : si.subContent);
242
261
  this.logEvent({ message: 'hub settings update', settings: si === null || si === void 0 ? void 0 : si.subContent });
243
262
  }
@@ -287,11 +306,11 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
287
306
  }
288
307
  onPingMessage(message) {
289
308
  const idle = zwift_hub_1.Idle.fromBinary(message);
290
- console.log('# ping message', idle);
291
- this.emit('data', { deviceType: this.deviceType, paired: this.paired, alive: true, ts: Date.now() });
309
+ this.emit('data', { deviceType: this.deviceType, paired: this.isHubPairConfirmed, alive: true, ts: Date.now() });
292
310
  }
293
311
  onResponse(d) {
294
312
  const data = Buffer.from(d);
313
+ this.logEvent({ message: 'got hub message', raw: data.toString('hex'), str: data.toString() });
295
314
  if ((data === null || data === void 0 ? void 0 : data.length) < 1) {
296
315
  console.log('Invalid response data', data.toString('hex'));
297
316
  return false;
@@ -303,9 +322,9 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
303
322
  }
304
323
  else {
305
324
  const len = data.length;
306
- if (len === 6 && data.toString() === 'RideOn') {
325
+ if (len == 6 && data.toString() === 'RideOn') {
307
326
  this.encrypted = false;
308
- this.paired = true;
327
+ this.isHubPairConfirmed = true;
309
328
  this.emitter.emit('paired');
310
329
  try {
311
330
  this.emit('data', { deviceType: this.deviceType, paired: true, ts: Date.now() });
@@ -318,7 +337,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
318
337
  const message = Buffer.from(data.subarray(6, 2)).toString('hex');
319
338
  if (message === '0900') {
320
339
  this.encrypted = true;
321
- this.paired = true;
340
+ this.isHubPairConfirmed = true;
322
341
  this.deviceKey = data.subarray(8);
323
342
  this.emitter.emit('paired');
324
343
  try {
@@ -332,6 +351,17 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
332
351
  this.logEvent({ message: 'Pairing failed! ', reason: 'unknown message', raw: message });
333
352
  }
334
353
  }
354
+ else if (Buffer.from(data.subarray(0, 6)).toString() === 'RideOn') {
355
+ this.encrypted = false;
356
+ this.isHubPairConfirmed = true;
357
+ this.emitter.emit('paired');
358
+ try {
359
+ this.emit('data', { deviceType: this.deviceType, paired: true, ts: Date.now() });
360
+ }
361
+ catch (err) {
362
+ this.logEvent({ message: 'error', fn: 'onPairResponse', error: err.message, stack: err.stack });
363
+ }
364
+ }
335
365
  return true;
336
366
  }
337
367
  }
@@ -352,12 +382,22 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
352
382
  }
353
383
  pair() {
354
384
  return __awaiter(this, void 0, void 0, function* () {
355
- var _a, _b;
385
+ var _a, _b, _c;
356
386
  if (this.isHubServicePaired)
357
387
  return true;
388
+ if (this.pairPromise !== undefined) {
389
+ const paired = yield this.pairPromise;
390
+ this.pairPromise = undefined;
391
+ if (paired)
392
+ return;
393
+ }
358
394
  let manufacturerData;
359
395
  try {
360
- if (this.peripheral.getManufacturerData) {
396
+ if (this.isFM) {
397
+ this.deviceType = 'hub';
398
+ this.encrypted = false;
399
+ }
400
+ else if (this.peripheral.getManufacturerData) {
361
401
  manufacturerData = this.getManufacturerData();
362
402
  if (manufacturerData === null || manufacturerData === void 0 ? void 0 : manufacturerData.startsWith('4a09')) {
363
403
  const typeVal = Number('0x' + manufacturerData.substring(2, 4));
@@ -373,23 +413,29 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
373
413
  }
374
414
  }
375
415
  }
376
- if (!this.encryptedSupported()) {
416
+ if (!this.deviceType && !this.encryptedSupported()) {
377
417
  this.deviceType = 'click';
378
418
  this.encrypted = false;
379
419
  }
420
+ this.deviceType = (_a = this.deviceType) !== null && _a !== void 0 ? _a : 'click';
380
421
  this.logEvent({ message: 'Play protocol pairing info', deviceType: this.deviceType, encrypted: this.encrypted, manufacturerData });
381
422
  let message;
382
- if (!this.encrypted) {
383
- message = this.isFM ? Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x01])]) : Buffer.from('RideOn');
423
+ if (this.isFM) {
424
+ message = Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x01])]);
384
425
  }
385
- else {
426
+ else if (this.encrypted) {
386
427
  const { publicKey, privateKey } = this.createKeyPair();
387
- this.privateKey = (_a = this.privateKey) !== null && _a !== void 0 ? _a : Buffer.from(privateKey);
388
- this.publicKey = (_b = this.publicKey) !== null && _b !== void 0 ? _b : Buffer.from(publicKey);
428
+ this.privateKey = (_b = this.privateKey) !== null && _b !== void 0 ? _b : Buffer.from(privateKey);
429
+ this.publicKey = (_c = this.publicKey) !== null && _c !== void 0 ? _c : Buffer.from(publicKey);
389
430
  message = Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x03]), this.publicKey]);
390
431
  }
432
+ else {
433
+ message = Buffer.from('RideOn');
434
+ }
435
+ this.logEvent({ message: `send rideOn` });
391
436
  yield this.write((0, utils_1.fullUUID)('00000003-19ca-4651-86e5-fa29dcdd09d1'), message, { withoutResponse: true });
392
437
  this.isHubServicePaired = true;
438
+ this.logEvent({ message: 'pairing done', deviceType: this.deviceType, encrypted: this.encrypted, manufacturerData });
393
439
  return true;
394
440
  }
395
441
  catch (err) {
@@ -412,7 +458,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
412
458
  });
413
459
  }
414
460
  setInitialState() {
415
- this.paired = false;
461
+ this.isHubPairConfirmed = false;
416
462
  this.encrypted = false;
417
463
  this.deviceKey = null;
418
464
  this.isHubServicePaired = false;
@@ -40,6 +40,7 @@ const types_1 = require("./types");
40
40
  const power_base_1 = __importDefault(require("./power-base"));
41
41
  const calculations_1 = __importStar(require("../utils/calculations"));
42
42
  const features_1 = require("../features");
43
+ const utils_1 = require("../utils/utils");
43
44
  const MIN_POWER = 25;
44
45
  class SmartTrainerCyclingMode extends power_base_1.default {
45
46
  constructor(adapter, props) {
@@ -54,7 +55,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
54
55
  getBikeInitRequest() {
55
56
  const virtshiftMode = this.getVirtualShiftMode();
56
57
  if (virtshiftMode === 'Adapter') {
57
- this.gear = this.getSetting('startGear');
58
+ this.gear = (0, utils_1.intVal)(this.getSetting('startGear'));
58
59
  const gearRatio = this.gearRatios[this.gear - 1];
59
60
  return { slope: 0, gearRatio };
60
61
  }
@@ -254,6 +255,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
254
255
  }
255
256
  }
256
257
  checkGearChange(request, newRequest = {}) {
258
+ var _a, _b;
257
259
  const virtshiftMode = this.getVirtualShiftMode();
258
260
  switch (virtshiftMode) {
259
261
  case 'SlopeDelta':
@@ -267,11 +269,11 @@ class SmartTrainerCyclingMode extends power_base_1.default {
267
269
  if (request.gearDelta !== undefined) {
268
270
  const oldGear = this.gear;
269
271
  if (this.gear === undefined) {
270
- const initialGear = Number(this.getSetting('startGear'));
271
- this.gear = initialGear + Number(request.gearDelta);
272
+ const initialGear = (0, utils_1.intVal)(this.getSetting('startGear'));
273
+ this.gear = initialGear + ((_a = (0, utils_1.intVal)(request.gearDelta)) !== null && _a !== void 0 ? _a : 0);
272
274
  }
273
275
  else {
274
- this.gear += Number(request.gearDelta);
276
+ this.gear += ((_b = (0, utils_1.intVal)(request.gearDelta)) !== null && _b !== void 0 ? _b : 0);
275
277
  }
276
278
  if (this.gear < 1) {
277
279
  this.gear = 1;
@@ -290,6 +292,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
290
292
  break;
291
293
  case 'Adapter':
292
294
  if (request.gearRatio !== undefined) {
295
+ const oldGear = this.gear;
293
296
  newRequest.gearRatio = request.gearRatio;
294
297
  if (this.gear === undefined) {
295
298
  const requestedRatio = request.gearRatio;
@@ -303,11 +306,13 @@ class SmartTrainerCyclingMode extends power_base_1.default {
303
306
  }
304
307
  }
305
308
  this.gear = closestIndex + 1;
309
+ this.logger.logEvent({ message: 'gear changed', gear: this.gear, gearRatio: newRequest.gearRatio, oldGear });
306
310
  }
307
311
  }
308
312
  else if (request.gearDelta !== undefined) {
313
+ const oldGear = this.gear;
309
314
  if (this.gear === undefined) {
310
- const initialGear = Number(this.getSetting('startGear'));
315
+ const initialGear = (0, utils_1.intVal)(this.getSetting('startGear'));
311
316
  this.gear = initialGear + request.gearDelta;
312
317
  }
313
318
  else {
@@ -321,13 +326,15 @@ class SmartTrainerCyclingMode extends power_base_1.default {
321
326
  }
322
327
  delete request.gearDelta;
323
328
  newRequest.gearRatio = this.gearRatios[this.gear];
329
+ this.logger.logEvent({ message: 'gear changed', gear: this.gear, gearRatio: newRequest.gearRatio, oldGear });
324
330
  }
325
331
  else {
326
332
  if (this.gear === undefined) {
327
- const initialGear = Number(this.getSetting('startGear'));
333
+ const initialGear = (0, utils_1.intVal)(this.getSetting('startGear'));
328
334
  this.gear = initialGear + request.gearDelta;
329
335
  }
330
336
  newRequest.gearRatio = this.gearRatios[this.gear];
337
+ this.logger.logEvent({ message: 'gear initialized', gear: this.gear, gearRatio: newRequest.gearRatio });
331
338
  }
332
339
  break;
333
340
  case 'Disabled':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.4.9",
3
+ "version": "2.4.10",
4
4
  "dependencies": {
5
5
  "@protobuf-ts/runtime": "^2.11.1",
6
6
  "@serialport/bindings-interface": "^1.2.2",