incyclist-devices 2.2.8 → 2.2.9
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.
|
@@ -438,8 +438,10 @@ class AntAdapter extends adpater_1.default {
|
|
|
438
438
|
stop() {
|
|
439
439
|
return __awaiter(this, void 0, void 0, function* () {
|
|
440
440
|
let stopped;
|
|
441
|
-
this.logger.logEvent({ message: 'stopping device', device: this.getName() });
|
|
442
441
|
this.internalEmitter.emit('stop');
|
|
442
|
+
if (this.stopped)
|
|
443
|
+
return;
|
|
444
|
+
this.logger.logEvent({ message: 'stopping device', device: this.getName() });
|
|
443
445
|
this.promiseWaitForData = null;
|
|
444
446
|
if (this.startStatus) {
|
|
445
447
|
this.startStatus.interrupted = true;
|
|
@@ -45,6 +45,8 @@ export default class AntInterface extends EventEmitter implements IncyclistInter
|
|
|
45
45
|
scannerWaitForConnection(): Promise<void>;
|
|
46
46
|
scan(props?: AntScanProps): Promise<AntDeviceSettings[]>;
|
|
47
47
|
isScanning(): boolean;
|
|
48
|
+
protected stopAllSensors(sensors: Array<ISensor>): Promise<void>;
|
|
49
|
+
protected stopDevices(detected: AntDeviceSettings[]): Promise<void>;
|
|
48
50
|
stopScan(): Promise<boolean>;
|
|
49
51
|
startSensor(sensor: ISensor, onDeviceData: (data: any) => void): Promise<boolean>;
|
|
50
52
|
private blockChannel;
|
|
@@ -16,6 +16,7 @@ const events_1 = __importDefault(require("events"));
|
|
|
16
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
17
|
const sensor_factory_1 = __importDefault(require("../factories/sensor-factory"));
|
|
18
18
|
const utils_1 = require("../../utils/utils");
|
|
19
|
+
const incyclist_devices_1 = require("incyclist-devices");
|
|
19
20
|
class AntInterface extends events_1.default {
|
|
20
21
|
static getInstance(props = {}) {
|
|
21
22
|
if (AntInterface._instance === undefined)
|
|
@@ -237,6 +238,8 @@ class AntInterface extends events_1.default {
|
|
|
237
238
|
this.activeScan.emitter.on('stop', () => __awaiter(this, void 0, void 0, function* () {
|
|
238
239
|
this.activeScan.emitter.removeAllListeners();
|
|
239
240
|
this.emit('stop-scan');
|
|
241
|
+
yield this.stopDevices(detected);
|
|
242
|
+
yield this.stopAllSensors(sensors);
|
|
240
243
|
const stopped = yield this.activeScan.channel.stopScanner();
|
|
241
244
|
this.logEvent({ message: 'scan stopped' });
|
|
242
245
|
removeListeners(channel);
|
|
@@ -276,6 +279,38 @@ class AntInterface extends events_1.default {
|
|
|
276
279
|
isScanning() {
|
|
277
280
|
return this.scanPromise !== undefined && this.scanPromise !== null;
|
|
278
281
|
}
|
|
282
|
+
stopAllSensors(sensors) {
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
this.logger.logEvent({ message: 'stopping all sensors ' });
|
|
285
|
+
let promises = [];
|
|
286
|
+
sensors.forEach((sensor) => {
|
|
287
|
+
promises.push(this.stopSensor(sensor).catch(err => {
|
|
288
|
+
var _a;
|
|
289
|
+
this.logger.logEvent({ message: 'could not stop sensor', error: err.message, channel: (_a = sensor.getChannel()) === null || _a === void 0 ? void 0 : _a.getChannelNo(), stack: err.stack });
|
|
290
|
+
}));
|
|
291
|
+
});
|
|
292
|
+
if (promises.length > 0) {
|
|
293
|
+
yield Promise.allSettled(promises);
|
|
294
|
+
}
|
|
295
|
+
this.logger.logEvent({ message: 'sensors stopped' });
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
stopDevices(detected) {
|
|
299
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
this.logger.logEvent({ message: 'stopping devices' });
|
|
301
|
+
let promises = [];
|
|
302
|
+
detected.forEach((settings) => {
|
|
303
|
+
const adapter = incyclist_devices_1.AdapterFactory.create(settings);
|
|
304
|
+
promises.push(adapter.stop().catch(err => {
|
|
305
|
+
this.logger.logEvent({ message: 'could not stop device', error: err.message, deviceID: settings.deviceID, stack: err.stack });
|
|
306
|
+
}));
|
|
307
|
+
});
|
|
308
|
+
if (promises.length > 0) {
|
|
309
|
+
yield Promise.allSettled(promises);
|
|
310
|
+
}
|
|
311
|
+
this.logger.logEvent({ message: 'devices stopped' });
|
|
312
|
+
});
|
|
313
|
+
}
|
|
279
314
|
stopScan() {
|
|
280
315
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281
316
|
this.logEvent({ message: 'stopping scan ..' });
|
|
@@ -348,7 +383,7 @@ class AntInterface extends events_1.default {
|
|
|
348
383
|
return true;
|
|
349
384
|
}
|
|
350
385
|
const channel = sensor.getChannel();
|
|
351
|
-
if (channel) {
|
|
386
|
+
if (channel !== undefined) {
|
|
352
387
|
try {
|
|
353
388
|
if (!channel.flush) {
|
|
354
389
|
this.logEvent({ message: 'old version of ant-channel detected' });
|
|
@@ -371,8 +406,7 @@ class AntInterface extends events_1.default {
|
|
|
371
406
|
}
|
|
372
407
|
}
|
|
373
408
|
else {
|
|
374
|
-
|
|
375
|
-
return false;
|
|
409
|
+
return true;
|
|
376
410
|
}
|
|
377
411
|
});
|
|
378
412
|
}
|