incyclist-devices 2.3.25 → 2.3.27

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.
@@ -43,14 +43,7 @@ class AntFEAdapter extends adapter_1.default {
43
43
  if (this.promiseStop)
44
44
  return;
45
45
  if (this.promiseSendUpdate) {
46
- let stack;
47
- try {
48
- throw new Error();
49
- }
50
- catch (err) {
51
- stack = err.stack;
52
- }
53
- this.logEvent({ message: 'send bike update skipped', device: this.getName(), request, reason: 'busy', stack });
46
+ this.logEvent({ message: 'send bike update skipped', device: this.getName(), request, reason: 'busy' });
54
47
  return;
55
48
  }
56
49
  let isReset = request.reset && Object.keys(request).length === 1;
@@ -257,8 +257,10 @@ class BleAdapter extends adpater_1.default {
257
257
  });
258
258
  }
259
259
  getStartLogProps(props) {
260
+ var _a;
261
+ const capabilities = (_a = this.props) === null || _a === void 0 ? void 0 : _a.capabilities;
260
262
  const { user, userWeight, bikeWeight, timeout, wheelDiameter, restart, scanOnly } = props !== null && props !== void 0 ? props : {};
261
- return { user, userWeight, bikeWeight, wheelDiameter, timeout, restart, scanOnly };
263
+ return { user, userWeight, bikeWeight, wheelDiameter, timeout, restart, scanOnly, capabilities };
262
264
  }
263
265
  startAdapter(startProps) {
264
266
  return __awaiter(this, void 0, void 0, function* () {
@@ -292,7 +294,8 @@ class BleAdapter extends adpater_1.default {
292
294
  }
293
295
  yield this.waitForInitialData(timeout);
294
296
  yield this.checkCapabilities();
295
- if (this.hasCapability(types_1.IncyclistCapability.Control))
297
+ const skipControl = this.props.capabilities && !this.props.capabilities.includes(types_1.IncyclistCapability.Control);
298
+ if (this.hasCapability(types_1.IncyclistCapability.Control) && !skipControl)
296
299
  yield this.initControl(startProps);
297
300
  this.stopped = false;
298
301
  this.started = true;
@@ -47,6 +47,8 @@ class BleFmAdapter extends adapter_1.default {
47
47
  getSupportedCyclingModes() {
48
48
  var _a;
49
49
  const modes = [power_meter_1.default];
50
+ if (this.props.capabilities && this.props.capabilities.indexOf(types_1.IncyclistCapability.Control) === -1)
51
+ return modes;
50
52
  const features = (_a = this.getSensor()) === null || _a === void 0 ? void 0 : _a.features;
51
53
  if (!features)
52
54
  return [power_meter_1.default, antble_smarttrainer_1.default, antble_erg_1.default];
@@ -58,6 +60,8 @@ class BleFmAdapter extends adapter_1.default {
58
60
  }
59
61
  getDefaultCyclingMode() {
60
62
  var _a;
63
+ if (this.props.capabilities && this.props.capabilities.indexOf(types_1.IncyclistCapability.Control) === -1)
64
+ return new power_meter_1.default(this);
61
65
  const features = (_a = this.getSensor()) === null || _a === void 0 ? void 0 : _a.features;
62
66
  if (!features)
63
67
  return new antble_smarttrainer_1.default(this);
@@ -267,16 +267,20 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
267
267
  }
268
268
  getFitnessMachineFeatures() {
269
269
  return __awaiter(this, void 0, void 0, function* () {
270
+ var _a;
270
271
  if (this._features)
271
272
  return this._features;
272
273
  try {
273
274
  const data = yield this.read('2acc');
274
275
  const buffer = data ? Buffer.from(data) : undefined;
276
+ const services = ((_a = this.peripheral) === null || _a === void 0 ? void 0 : _a.services) || [];
277
+ let power = services.some(s => (0, utils_1.matches)(s.uuid, '1818'));
278
+ let heartrate = services.some(s => (0, utils_1.matches)(s.uuid, '180d'));
275
279
  if (buffer) {
276
280
  const fitnessMachine = buffer.readUInt32LE(0);
277
281
  const targetSettings = buffer.readUInt32LE(4);
278
- const power = (fitnessMachine & consts_2.FitnessMachineFeatureFlag.PowerMeasurementSupported) !== 0;
279
- const heartrate = (fitnessMachine & consts_2.FitnessMachineFeatureFlag.HeartRateMeasurementSupported) !== 0;
282
+ power = power || (fitnessMachine & consts_2.FitnessMachineFeatureFlag.PowerMeasurementSupported) !== 0;
283
+ heartrate = heartrate || (fitnessMachine & consts_2.FitnessMachineFeatureFlag.HeartRateMeasurementSupported) !== 0;
280
284
  const cadence = (fitnessMachine & consts_2.FitnessMachineFeatureFlag.CadenceSupported) !== 0;
281
285
  const setSlope = (targetSettings & consts_2.TargetSettingFeatureFlag.IndoorBikeSimulationParametersSupported) !== 0
282
286
  || (targetSettings & consts_2.TargetSettingFeatureFlag.InclinationTargetSettingSupported) !== 0;
@@ -66,9 +66,14 @@ class DirectConnectInterface extends events_1.default {
66
66
  return peripheral_1.DirectConnectPeripheral.create(announcement);
67
67
  }
68
68
  createDeviceSetting(service) {
69
- const name = service.name;
70
- const protocol = this.getProtocol(service);
71
- return { interface: DirectConnectInterface.INTERFACE_NAME, name, protocol };
69
+ try {
70
+ const name = service.name;
71
+ const protocol = this.getProtocol(service);
72
+ return { interface: DirectConnectInterface.INTERFACE_NAME, name, protocol };
73
+ }
74
+ catch (_a) {
75
+ return null;
76
+ }
72
77
  }
73
78
  createPeripheralFromSettings(settings) {
74
79
  const info = this.getAll().find(a => a.service.name === settings.name);
@@ -228,7 +233,10 @@ class DirectConnectInterface extends events_1.default {
228
233
  });
229
234
  }
230
235
  emitDevice(service) {
231
- this.emit('device', this.createDeviceSetting(service), service);
236
+ const device = this.createDeviceSetting(service);
237
+ if (!device)
238
+ return;
239
+ this.emit('device', device, service);
232
240
  }
233
241
  buildDeviceSettings(matching = []) {
234
242
  return matching.map((name) => ({ interface: DirectConnectInterface.INTERFACE_NAME, name }));
@@ -1,6 +1,7 @@
1
1
  import { EventLogger } from "gd-eventlog";
2
2
  import { IncyclistInterface } from "./interface";
3
3
  import { User } from "./user";
4
+ import { IncyclistCapability } from "./capabilities";
4
5
  export declare enum INTERFACE {
5
6
  SERIAL = "serial",
6
7
  TCPIP = "tcpip",
@@ -15,6 +16,7 @@ export type DeviceProperties = {
15
16
  user?: User;
16
17
  userWeight?: number;
17
18
  bikeWeight?: number;
19
+ capabilities?: IncyclistCapability[];
18
20
  };
19
21
  export interface DeviceStartProperties extends DeviceProperties {
20
22
  timeout?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.3.25",
3
+ "version": "2.3.27",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",