incyclist-devices 2.3.1 → 2.3.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.
@@ -331,6 +331,7 @@ class AntInterface extends events_1.default {
331
331
  }
332
332
  startSensor(sensor, onDeviceData) {
333
333
  return __awaiter(this, void 0, void 0, function* () {
334
+ var _a;
334
335
  if (!this.isConnected()) {
335
336
  const connected = yield this.connect();
336
337
  if (!connected)
@@ -355,6 +356,7 @@ class AntInterface extends events_1.default {
355
356
  this.logEvent({ message: 'could not start sensor' });
356
357
  channel.off('data', onData);
357
358
  }
359
+ this.logEvent({ message: 'sensor started', channel: (_a = sensor.getChannel()) === null || _a === void 0 ? void 0 : _a.getChannelNo(), profile: sensor.getProfile(), deviceID: sensor.getDeviceID() });
358
360
  return started;
359
361
  }
360
362
  catch (err) {
@@ -363,7 +365,7 @@ class AntInterface extends events_1.default {
363
365
  try {
364
366
  yield channel.stopSensor(sensor);
365
367
  }
366
- catch (_a) { }
368
+ catch (_b) { }
367
369
  this.unblockChannel(channel);
368
370
  return false;
369
371
  }
@@ -383,7 +385,7 @@ class AntInterface extends events_1.default {
383
385
  return true;
384
386
  }
385
387
  const channel = sensor.getChannel();
386
- if (channel !== undefined) {
388
+ if (channel !== undefined && channel !== null) {
387
389
  try {
388
390
  if (!channel.flush) {
389
391
  this.logEvent({ message: 'old version of ant-channel detected' });
@@ -33,6 +33,7 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
33
33
  protected instanceId: number;
34
34
  protected connectedPeripherals: IBlePeripheral[];
35
35
  protected connectAttemptCnt: number;
36
+ protected emitted: BlePeripheralAnnouncement[];
36
37
  static getInstance(props?: InterfaceProps): BleInterface;
37
38
  protected constructor(props: InterfaceProps);
38
39
  setProps(props: InterfaceProps): void;
@@ -74,6 +75,7 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
74
75
  protected startScan(): Promise<unknown>;
75
76
  private emitCachedDevices;
76
77
  protected emitDevice(service: BlePeripheralAnnouncement): void;
78
+ protected alreadyEmitted(service: BlePeripheralAnnouncement): boolean;
77
79
  protected buildDeviceSettings(matching?: string[]): BleDeviceSettings[];
78
80
  protected addCompleting(service: BlePeripheralAnnouncement): void;
79
81
  protected addUnsupported(service: BlePeripheralAnnouncement): void;
@@ -51,6 +51,7 @@ class BleInterface extends events_1.default {
51
51
  this.matching = [];
52
52
  this.connectedPeripherals = [];
53
53
  this.connectAttemptCnt = 0;
54
+ this.emitted = [];
54
55
  this.instanceId = ++instanceCount;
55
56
  this.props = props;
56
57
  this.logEnabled = props.log || true;
@@ -426,6 +427,7 @@ class BleInterface extends events_1.default {
426
427
  }
427
428
  startScan() {
428
429
  this.logEvent({ message: 'scan started', scanning: this.isScanning() });
430
+ this.emitted = [];
429
431
  this.emitCachedDevices();
430
432
  return new Promise(() => {
431
433
  });
@@ -438,9 +440,16 @@ class BleInterface extends events_1.default {
438
440
  });
439
441
  }
440
442
  emitDevice(service) {
443
+ if (this.alreadyEmitted(service)) {
444
+ return;
445
+ }
441
446
  const settings = this.createDeviceSetting(service);
442
447
  this.logEvent({ message: 'device found', settings });
443
448
  this.emit('device', settings, service);
449
+ this.emitted.push(service);
450
+ }
451
+ alreadyEmitted(service) {
452
+ return this.emitted.find(s => s.name === service.name || s.peripheral.address === service.peripheral.address) !== undefined;
444
453
  }
445
454
  buildDeviceSettings(matching = []) {
446
455
  return matching.map((name) => {
@@ -79,7 +79,7 @@ class BlePeripheral {
79
79
  }
80
80
  onPeripheralDisconnect() {
81
81
  return __awaiter(this, void 0, void 0, function* () {
82
- this.logEvent({ message: 'disconnect' });
82
+ this.logEvent({ message: 'peripheral disconnected' });
83
83
  try {
84
84
  yield this.disconnect(true);
85
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.3.1",
3
+ "version": "2.3.4",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",