incyclist-services 1.0.23 → 1.0.25

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.
@@ -36,7 +36,9 @@ export declare class DeviceConfigurationService extends EventEmitter {
36
36
  legacy?: boolean;
37
37
  }): void;
38
38
  unselect(capability: ExtendedIncyclistCapability): void;
39
- add(deviceSettings: IncyclistDeviceSettings, legacyMode?: boolean): void;
39
+ add(deviceSettings: IncyclistDeviceSettings, props?: {
40
+ legacy?: boolean;
41
+ }): string;
40
42
  delete(udid: string, capability?: ExtendedIncyclistCapability, forceSingle?: boolean): void;
41
43
  protected deleteFromDeviceList(udid: string): void;
42
44
  protected addToCapability(udid: string, capability: ExtendedIncyclistCapability): void;
@@ -60,6 +62,7 @@ export declare class DeviceConfigurationService extends EventEmitter {
60
62
  disableInterface(ifName: string): void;
61
63
  setInterfaceSettings(ifName: any, settings: InterfaceSetting): void;
62
64
  emitInterfaceChanged(ifName: string): void;
65
+ emitDeviceDeleted(settings: IncyclistDeviceSettings): void;
63
66
  }
64
67
  export declare const useDeviceConfiguration: () => DeviceConfigurationService;
65
68
  export {};
@@ -373,10 +373,11 @@ class DeviceConfigurationService extends events_1.default {
373
373
  this.emitCapabiltyChanged(settings.capability);
374
374
  }
375
375
  }
376
- add(deviceSettings, legacyMode = false) {
376
+ add(deviceSettings, props) {
377
377
  var _a, _b;
378
378
  let udid = this.getUdid(deviceSettings);
379
- this.logEvent({ message: 'add device', udid, deviceSettings, legacyMode });
379
+ const { legacy = false } = props || {};
380
+ this.logEvent({ message: 'add device', udid, deviceSettings, legacy });
380
381
  const deviceAlreadyExists = udid !== undefined;
381
382
  let adapter;
382
383
  if (deviceAlreadyExists) {
@@ -401,7 +402,7 @@ class DeviceConfigurationService extends events_1.default {
401
402
  return;
402
403
  const isBike = adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Control);
403
404
  const isPower = adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Power);
404
- if (legacyMode) {
405
+ if (legacy) {
405
406
  const isBikeCap = c.capability === 'bike';
406
407
  const isControlCap = c.capability === incyclist_devices_1.IncyclistCapability.Control;
407
408
  const isHrmCap = c.capability === incyclist_devices_1.IncyclistCapability.HeartRate;
@@ -428,6 +429,7 @@ class DeviceConfigurationService extends events_1.default {
428
429
  });
429
430
  this.updateUserSettings();
430
431
  this.emitCapabiltyChanged();
432
+ return udid;
431
433
  }
432
434
  delete(udid, capability, forceSingle = false) {
433
435
  var _a;
@@ -474,6 +476,7 @@ class DeviceConfigurationService extends events_1.default {
474
476
  this.emitCapabiltyChanged();
475
477
  this.updateUserSettings();
476
478
  }
479
+ this.emitDeviceDeleted(deviceSettings);
477
480
  }
478
481
  deleteFromDeviceList(udid) {
479
482
  const { devices = [] } = this.settings || {};
@@ -724,6 +727,9 @@ class DeviceConfigurationService extends events_1.default {
724
727
  this.emit('interface-changed', ifName, setting, this.settings.interfaces);
725
728
  }
726
729
  }
730
+ emitDeviceDeleted(settings) {
731
+ this.emit('device-deleted', settings);
732
+ }
727
733
  }
728
734
  exports.DeviceConfigurationService = DeviceConfigurationService;
729
735
  const useDeviceConfiguration = () => DeviceConfigurationService.getInstance();
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import EventEmitter from "events";
3
- import { DeviceData, DeviceSettings } from "incyclist-devices";
3
+ import { DeviceData, DeviceSettings, ControllableDeviceAdapter } from "incyclist-devices";
4
4
  import { DeviceAccessService } from "../access/service";
5
- import { AdapterInfo, DeviceConfigurationService } from "../configuration";
5
+ import { AdapterInfo, DeviceConfigurationService, IncyclistDeviceSettings } from "../configuration";
6
6
  import CyclingMode, { UpdateRequest } from "incyclist-devices/lib/modes/cycling-mode";
7
7
  import { AdapterRideInfo, PreparedRoute, RideServiceCheckFilter, RideServiceDeviceProperties } from "./model";
8
8
  import { UserSettingsService } from "../../settings";
@@ -37,6 +37,7 @@ export declare class DeviceRideService extends EventEmitter {
37
37
  protected waitForPreviousStartToFinish(): Promise<boolean>;
38
38
  startCheck(filter: RideServiceCheckFilter): Promise<void>;
39
39
  protected getAdapters(filter: RideServiceCheckFilter): AdapterRideInfo[];
40
+ setSerialPortInUse(adapter: ControllableDeviceAdapter): void;
40
41
  protected startAdapters(adapters: AdapterRideInfo[], startType: 'start' | 'check', props?: RideServiceDeviceProperties): Promise<boolean>;
41
42
  start(props: RideServiceDeviceProperties): Promise<boolean>;
42
43
  cancelStart(): Promise<boolean>;
@@ -48,6 +49,7 @@ export declare class DeviceRideService extends EventEmitter {
48
49
  sendUpdate(request: UpdateRequest): void;
49
50
  getCyclingMode(udid?: string): CyclingMode;
50
51
  onCyclingModeChanged(udid: string, mode: string, settings: any): Promise<void>;
52
+ onDeviceDeleted(settings: IncyclistDeviceSettings): void;
51
53
  enforceSimulator(enforced?: boolean): void;
52
54
  }
53
55
  export declare const useDeviceRide: () => DeviceRideService;
@@ -64,7 +64,9 @@ class DeviceRideService extends events_1.default {
64
64
  }
65
65
  this.adapters = (_a = this.configurationService.getAdapters()) === null || _a === void 0 ? void 0 : _a.map(ai => Object.assign({}, Object.assign(Object.assign({}, ai), { isStarted: false })));
66
66
  const handleModeChange = this.onCyclingModeChanged.bind(this);
67
+ const handleDeviceDeleted = this.onDeviceDeleted.bind(this);
67
68
  this.configurationService.on('mode-changed', handleModeChange);
69
+ this.configurationService.on('device-deleted', handleDeviceDeleted);
68
70
  this.userSettings = (0, settings_1.useUserSettings)();
69
71
  });
70
72
  }
@@ -326,6 +328,13 @@ class DeviceRideService extends events_1.default {
326
328
  }
327
329
  return adapters || [];
328
330
  }
331
+ setSerialPortInUse(adapter) {
332
+ if (adapter.getInterface() === 'serial' || adapter.getInterface() === 'tcpip') {
333
+ const device = adapter;
334
+ const serial = device.getSerialInterface();
335
+ serial.setInUse(device.getPort());
336
+ }
337
+ }
329
338
  startAdapters(adapters, startType, props) {
330
339
  return __awaiter(this, void 0, void 0, function* () {
331
340
  const { forceErgMode, startPos, realityFactor, rideMode, route } = props || {};
@@ -386,6 +395,8 @@ class DeviceRideService extends events_1.default {
386
395
  yield ai.adapter.pause().catch(console.log);
387
396
  ai.adapter.off('data', this.deviceDataHandler);
388
397
  }
398
+ if (ai.adapter.isControllable())
399
+ this.setSerialPortInUse(ai.adapter);
389
400
  return success;
390
401
  }))
391
402
  .catch(err => {
@@ -443,6 +454,10 @@ class DeviceRideService extends events_1.default {
443
454
  }
444
455
  stop(udid) {
445
456
  return __awaiter(this, void 0, void 0, function* () {
457
+ if (!udid)
458
+ this.logEvent({ message: 'stop devices' });
459
+ else
460
+ this.logEvent({ message: 'stop device', udid });
446
461
  const adapters = this.getAdapterList();
447
462
  this.emit('stop-ride');
448
463
  const promises = adapters === null || adapters === void 0 ? void 0 : adapters.filter(ai => udid ? ai.udid === udid : true).map(ai => {
@@ -543,6 +558,13 @@ class DeviceRideService extends events_1.default {
543
558
  }
544
559
  });
545
560
  }
561
+ onDeviceDeleted(settings) {
562
+ if (settings.interface === 'serial' || settings.interface === 'tcpip') {
563
+ const device = incyclist_devices_1.AdapterFactory.create(settings);
564
+ const serial = device.getSerialInterface();
565
+ serial.releaseInUse(device.getPort());
566
+ }
567
+ }
546
568
  enforceSimulator(enforced = true) {
547
569
  this.simulatorEnforced = enforced;
548
570
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.24"
6
6
  },
@@ -37,7 +37,7 @@
37
37
  "lib": "./src"
38
38
  },
39
39
  "dependencies": {
40
- "incyclist-devices": "^2.0.29",
40
+ "incyclist-devices": "^2.0.35",
41
41
  "uuid": "^9.0.0"
42
42
  }
43
43
  }