incyclist-devices 2.4.2 → 2.4.4

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.
@@ -356,6 +356,10 @@ class BleAdapter extends adpater_1.default {
356
356
  }
357
357
  onDisconnectDone() {
358
358
  return __awaiter(this, void 0, void 0, function* () {
359
+ try {
360
+ this.getBle().removeAllListeners('disconnect-done');
361
+ }
362
+ catch (_a) { }
359
363
  this.logEvent({ message: 'disconnecting device', device: this.getName(), interface: this.getInterface() });
360
364
  if (this.isStarting()) {
361
365
  yield this.startTask.stop();
@@ -365,6 +369,7 @@ class BleAdapter extends adpater_1.default {
365
369
  const sensor = this.getSensor();
366
370
  try {
367
371
  stopped = yield sensor.stopSensor();
372
+ this.logEvent({ message: 'disconnecting device completed', device: this.getName(), interface: this.getInterface() });
368
373
  }
369
374
  catch (err) {
370
375
  reason = err.message;
@@ -52,6 +52,11 @@ class BlePeripheral {
52
52
  }
53
53
  this.connectPromise = new Promise((done) => {
54
54
  const peripheral = this.getPeripheral();
55
+ this.connected = false;
56
+ this.ble.unregisterConnected(peripheral.id);
57
+ if (!this.ble.isConnected()) {
58
+ return done();
59
+ }
55
60
  this.logEvent({ message: 'connect peripheral', address: peripheral.address });
56
61
  peripheral.connectAsync().then(() => {
57
62
  this.ble.registerConnected(this, peripheral.id);
@@ -92,6 +97,9 @@ class BlePeripheral {
92
97
  }
93
98
  peripheral.removeAllListeners();
94
99
  }
100
+ else {
101
+ delete this.onDisconnectHandler;
102
+ }
95
103
  this.ble.unregisterConnected(peripheral.id);
96
104
  this.connected = false;
97
105
  this.disconnecting = false;
@@ -117,6 +117,7 @@ class TBleSensor extends events_1.default {
117
117
  }
118
118
  reconnectSensor() {
119
119
  return __awaiter(this, void 0, void 0, function* () {
120
+ this.logEvent({ message: 'reconnect sensor' });
120
121
  let connected = false;
121
122
  let subscribed = false;
122
123
  let success = false;
@@ -396,13 +396,14 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
396
396
  }
397
397
  writeFtmsMessage(requestedOpCode, data, props) {
398
398
  return __awaiter(this, void 0, void 0, function* () {
399
+ var _a;
399
400
  try {
400
401
  this.logEvent({ message: 'fmts:write', device: this.getName(), data: data.toString('hex') });
401
402
  let res;
402
403
  let tsStart = Date.now();
403
404
  if (props === null || props === void 0 ? void 0 : props.timeout) {
404
405
  res = yield new task_1.InteruptableTask(this.write(consts_1.FTMS_CP, data, props), {
405
- timeout: 800,
406
+ timeout: (_a = props.timeout) !== null && _a !== void 0 ? _a : 800,
406
407
  errorOnTimeout: true
407
408
  }).run();
408
409
  }
@@ -89,14 +89,14 @@ class SmartTrainerCyclingMode extends power_base_1.default {
89
89
  config.properties.push(virtshift);
90
90
  }
91
91
  if (!virtshift && virtShiftEnabled && this.adapter.supportsVirtualShifting()) {
92
- virtshift.default = 'Enabled';
93
- virtshift.options = [
92
+ const options = [
94
93
  'Disabled',
95
94
  { key: 'Incyclist', display: 'App only (beta)' },
96
95
  { key: 'Mixed', display: 'App + Bike' },
97
96
  { key: 'SmartTrainer', display: 'SmartTreiner (beta)' }
98
97
  ];
99
- virtshift.default = 'SmartTrainer';
98
+ virtshift = { key: 'virtshift', name: 'Virtual Shifting', description: 'Enable virtual shifting', type: types_1.CyclingModeProperyType.SingleSelect, options, default: 'SmartTrainer' };
99
+ config.properties.push(virtshift);
100
100
  }
101
101
  if (virtshift && !startGear) {
102
102
  startGear = { key: 'startGear', name: 'Initial Gear', description: 'Initial Gear', type: types_1.CyclingModeProperyType.Integer, default: 12, min: 1, max: 24, condition: (s) => (s === null || s === void 0 ? void 0 : s.virtshift) === 'Incyclist' || (s === null || s === void 0 ? void 0 : s.virtshift) === 'SmartTrainer' };
@@ -358,24 +358,29 @@ class SmartTrainerCyclingMode extends power_base_1.default {
358
358
  }
359
359
  }
360
360
  getVirtualShiftMode() {
361
- if (!this.getFeatureToogle().has('VirtualShifting')) {
362
- return 'Disabled';
363
- }
364
- const virtshiftMode = this.getSetting('virtshift');
365
- if (virtshiftMode === 'Disabled') {
366
- return 'Disabled';
367
- }
368
- else if (virtshiftMode === 'Incyclist') {
369
- return 'Simulated';
370
- }
371
- else if (virtshiftMode === 'SmartTrainer') {
372
- return 'Adapter';
373
- }
374
- else if (virtshiftMode === 'Mixed') {
375
- return 'SlopeDelta';
361
+ try {
362
+ if (!this.getFeatureToogle().has('VirtualShifting')) {
363
+ return 'Disabled';
364
+ }
365
+ const virtshiftMode = this.getSetting('virtshift');
366
+ if (virtshiftMode === 'Disabled') {
367
+ return 'Disabled';
368
+ }
369
+ else if (virtshiftMode === 'Incyclist') {
370
+ return 'Simulated';
371
+ }
372
+ else if (virtshiftMode === 'SmartTrainer') {
373
+ return 'Adapter';
374
+ }
375
+ else if (virtshiftMode === 'Mixed') {
376
+ return 'SlopeDelta';
377
+ }
378
+ else if (virtshiftMode === 'Enabled') {
379
+ return this.adapter.supportsVirtualShifting() ? 'Adapter' : 'Simulated';
380
+ }
376
381
  }
377
- else if (virtshiftMode === 'Enabled') {
378
- return this.adapter.supportsVirtualShifting() ? 'Adapter' : 'Simulated';
382
+ catch (err) {
383
+ this.logger.logEvent({ message: 'error', fn: 'getVirtualShiftMode', error: err.message, stack: err.stack });
379
384
  }
380
385
  return 'Disabled';
381
386
  }
@@ -59,7 +59,7 @@ class Simulator extends adpater_1.default {
59
59
  this.setBikeProps(props);
60
60
  return new Promise((resolve) => {
61
61
  if (!this.isBot)
62
- this.logEvent({ message: 'starting device', device: this.getName(), props });
62
+ this.logEvent({ message: 'starting device', device: this.getName() });
63
63
  if (this.started) {
64
64
  return resolve(true);
65
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "dependencies": {
5
5
  "@protobuf-ts/runtime": "^2.11.1",
6
6
  "@serialport/bindings-interface": "^1.2.2",