incyclist-services 1.3.14 → 1.3.15

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.
@@ -50,6 +50,7 @@ export declare class DeviceRideService extends EventEmitter {
50
50
  cancelStart(): Promise<boolean>;
51
51
  startRide(_props: any): void;
52
52
  stop(udid?: string): Promise<boolean>;
53
+ resetLimits(): Promise<void>;
53
54
  pause(): void;
54
55
  resume(): void;
55
56
  protected verifySelected(selectedDevices: any, capability: IncyclistCapability): void;
@@ -60,6 +61,7 @@ export declare class DeviceRideService extends EventEmitter {
60
61
  sendUpdate(request: UpdateRequest): Promise<void>;
61
62
  getCyclingMode(udid?: string): CyclingMode;
62
63
  resetCyclingMode(sendInit?: boolean): Promise<void>;
64
+ enforceERG(): Promise<void>;
63
65
  onCyclingModeChanged(udid: string, mode: string, settings: any): Promise<void>;
64
66
  onDeviceDeleted(settings: IncyclistDeviceSettings): void;
65
67
  enforceSimulator(enforced?: boolean): void;
@@ -727,6 +727,17 @@ class DeviceRideService extends events_1.default {
727
727
  return true;
728
728
  });
729
729
  }
730
+ resetLimits() {
731
+ return __awaiter(this, void 0, void 0, function* () {
732
+ var _a;
733
+ try {
734
+ const mode = this.getCyclingMode();
735
+ const resetRequest = (_a = mode === null || mode === void 0 ? void 0 : mode.getBikeInitRequest()) !== null && _a !== void 0 ? _a : {};
736
+ yield this.sendUpdate(Object.assign(Object.assign({}, resetRequest), { slope: 0, forced: true }));
737
+ }
738
+ catch (_b) { }
739
+ });
740
+ }
730
741
  pause() {
731
742
  const adapters = this.getAdapterList();
732
743
  adapters === null || adapters === void 0 ? void 0 : adapters.forEach(ai => {
@@ -897,6 +908,30 @@ class DeviceRideService extends events_1.default {
897
908
  }
898
909
  });
899
910
  }
911
+ enforceERG() {
912
+ return __awaiter(this, void 0, void 0, function* () {
913
+ try {
914
+ const adapters = this.getAdapterList();
915
+ const adapterInfo = adapters === null || adapters === void 0 ? void 0 : adapters.find(ai => ai.adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Control));
916
+ if (!(adapterInfo === null || adapterInfo === void 0 ? void 0 : adapterInfo.adapter))
917
+ return;
918
+ const { udid, adapter } = adapterInfo;
919
+ if (adapter.getCyclingMode().getModeProperty('eppSupport'))
920
+ return;
921
+ const modes = adapter.getSupportedCyclingModes().filter(C => C.supportsERGMode());
922
+ if (modes.length > 0) {
923
+ const mode = new modes[0](adapter);
924
+ const modeInfo = this.configurationService.getModeSettings(udid, mode.getName());
925
+ const settings = modeInfo.settings;
926
+ const device = adapter;
927
+ device.setCyclingMode(mode, settings);
928
+ }
929
+ }
930
+ catch (err) {
931
+ this.logEvent({ message: 'error', error: err.message, fn: 'enforceERG' });
932
+ }
933
+ });
934
+ }
900
935
  onCyclingModeChanged(udid, mode, settings) {
901
936
  return __awaiter(this, void 0, void 0, function* () {
902
937
  var _a;
@@ -21,6 +21,7 @@ export declare class WorkoutRide extends IncyclistService {
21
21
  protected currentLimits: ActiveWorkoutLimit;
22
22
  protected updateInterval: NodeJS.Timeout;
23
23
  protected currentStep: StepDefinition;
24
+ protected isFreeRide: boolean;
24
25
  constructor();
25
26
  init(): Observer;
26
27
  start(paused?: boolean): Workout;
@@ -34,10 +35,13 @@ export declare class WorkoutRide extends IncyclistService {
34
35
  getDashboardDisplayProperties(): WorkoutDisplayProperties;
35
36
  getCurrentLimits(): ActiveWorkoutLimit;
36
37
  inUse(): boolean;
38
+ appliesLimits(): boolean;
37
39
  isActive(): boolean;
38
40
  getWorkout(): Workout;
39
41
  getObserver(): Observer;
40
42
  protected update(startIfInitialized?: boolean): void;
43
+ protected startFreeRide(): Promise<void>;
44
+ protected stopFreeRide(): Promise<void>;
41
45
  protected resetLimits(): Promise<void>;
42
46
  protected resetTimes(): void;
43
47
  protected setCurrentLimits(trainingTime?: number): void;
@@ -68,6 +68,7 @@ let WorkoutRide = (() => {
68
68
  constructor() {
69
69
  super('WorkoutRide');
70
70
  this.state = 'idle';
71
+ this.isFreeRide = true;
71
72
  }
72
73
  init() {
73
74
  var _a, _b;
@@ -282,6 +283,9 @@ let WorkoutRide = (() => {
282
283
  inUse() {
283
284
  return this.state !== 'idle' && this.state !== 'completed';
284
285
  }
286
+ appliesLimits() {
287
+ return this.inUse() && !this.isFreeRide;
288
+ }
285
289
  isActive() {
286
290
  return this.state === 'active';
287
291
  }
@@ -315,6 +319,12 @@ let WorkoutRide = (() => {
315
319
  const prevStep = this.currentStep;
316
320
  this.setCurrentLimits(time);
317
321
  if (this.currentStep !== prevStep) {
322
+ if (!this.currentStep.power && prevStep.power) {
323
+ this.startFreeRide();
324
+ }
325
+ else if (this.currentStep.power && !prevStep.power) {
326
+ this.stopFreeRide();
327
+ }
318
328
  this.emit('step-changed', this.getDashboardDisplayProperties());
319
329
  }
320
330
  else if (Math.round(time) !== prevTime) {
@@ -325,16 +335,31 @@ let WorkoutRide = (() => {
325
335
  this.logError(err, 'update');
326
336
  }
327
337
  }
338
+ startFreeRide() {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ if (this.settings.useErgMode) {
341
+ (0, devices_1.useDeviceRide)().resetCyclingMode(false);
342
+ }
343
+ this.resetLimits();
344
+ });
345
+ }
346
+ stopFreeRide() {
347
+ return __awaiter(this, void 0, void 0, function* () {
348
+ if (this.settings.useErgMode) {
349
+ (0, devices_1.useDeviceRide)().enforceERG();
350
+ }
351
+ this.resetLimits();
352
+ });
353
+ }
328
354
  resetLimits() {
329
355
  return __awaiter(this, void 0, void 0, function* () {
330
356
  const rideService = (0, devices_1.useDeviceRide)();
331
- rideService.resetCyclingMode();
332
357
  const mode = rideService.getCyclingMode();
333
- const data = rideService.getData();
334
358
  const isERG = mode ? mode.constructor.supportsERGMode() : false;
335
359
  if (!this.currentLimits || !mode)
336
360
  return;
337
361
  yield rideService.waitForUpdateFinish();
362
+ const data = rideService.getData();
338
363
  if (isERG) {
339
364
  rideService.sendUpdate({ targetPower: data.power });
340
365
  }
@@ -374,6 +399,7 @@ let WorkoutRide = (() => {
374
399
  request.maxHrm = ((_d = limits.hrm) === null || _d === void 0 ? void 0 : _d.max) ? Math.round(limits.hrm.max) : undefined;
375
400
  this.currentLimits = Object.assign(Object.assign({}, request), { duration: limits.duration, remaining: limits.remaining });
376
401
  }
402
+ this.isFreeRide = limits.power === undefined || limits.power === null;
377
403
  this.logger.logEvent(Object.assign(Object.assign({ message: 'workout requests' }, this.currentLimits), { ftp }));
378
404
  this.emit('request-update', this.currentLimits);
379
405
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.3.14",
3
+ "version": "1.3.15",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "axios": "^1.6.1",
46
- "incyclist-devices": "^2.2.2",
46
+ "incyclist-devices": "^2.2.3",
47
47
  "promise.any": "^2.0.6",
48
48
  "tcx-builder": "^1.1.1",
49
49
  "uuid": "^9.0.0",