incyclist-devices 2.4.6-beta.3 → 2.4.6

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.
@@ -208,9 +208,9 @@ class AntAdapter extends adpater_1.default {
208
208
  });
209
209
  }
210
210
  getID() {
211
- var _a;
212
- const id = this.deviceData.DeviceID || ((_a = this.sensor) === null || _a === void 0 ? void 0 : _a.getDeviceID());
213
- return id.toString();
211
+ var _a, _b, _c;
212
+ const id = (_b = (_a = this.deviceData) === null || _a === void 0 ? void 0 : _a.DeviceID) !== null && _b !== void 0 ? _b : (_c = this.sensor) === null || _c === void 0 ? void 0 : _c.getDeviceID();
213
+ return id === null || id === void 0 ? void 0 : id.toString();
214
214
  }
215
215
  getName() {
216
216
  if (this.settings.name)
@@ -39,7 +39,7 @@ class AntFEAdapter extends adapter_1.default {
39
39
  }
40
40
  getDefaultCyclingMode() {
41
41
  if (this.props.capabilities && this.props.capabilities.indexOf(types_1.IncyclistCapability.Control) === -1)
42
- return new power_meter_1.default(this);
42
+ return this.createMode(power_meter_1.default);
43
43
  return super.getDefaultCyclingMode();
44
44
  }
45
45
  sendUpdate(request) {
@@ -14,6 +14,7 @@ export default class IncyclistDevice<P extends DeviceProperties> extends EventEm
14
14
  scanning: boolean;
15
15
  protected props: P;
16
16
  protected cyclingMode: ICyclingMode;
17
+ protected modes: Record<string, ICyclingMode>;
17
18
  protected logger: EventLogger;
18
19
  protected static controllers: ControllerConfig;
19
20
  protected user: User;
@@ -49,6 +50,7 @@ export default class IncyclistDevice<P extends DeviceProperties> extends EventEm
49
50
  setMaxUpdateFrequency(value: number): void;
50
51
  update(): void;
51
52
  setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
53
+ createMode(ModeClass: typeof CyclingMode): ICyclingMode;
52
54
  protected createOrGetMode(mode: string | ICyclingMode): ICyclingMode;
53
55
  getSupportedCyclingModes(): Array<typeof CyclingMode>;
54
56
  getCyclingMode(): ICyclingMode;
@@ -19,6 +19,7 @@ const utils_1 = require("../utils/utils");
19
19
  class IncyclistDevice extends events_1.default {
20
20
  constructor(settings, props) {
21
21
  super();
22
+ this.modes = {};
22
23
  this.onDataFn = undefined;
23
24
  this.settings = settings;
24
25
  this.props = props || {};
@@ -146,22 +147,32 @@ class IncyclistDevice extends events_1.default {
146
147
  this.cyclingMode = selectedMode;
147
148
  this.cyclingMode.setSettings(settings);
148
149
  }
150
+ createMode(ModeClass) {
151
+ try {
152
+ const mode = new ModeClass(null);
153
+ return this.createOrGetMode(mode.getName());
154
+ }
155
+ catch (err) {
156
+ this.logEvent({ message: 'error', error: err.message, stack: err.stack, mode: ModeClass === null || ModeClass === void 0 ? void 0 : ModeClass.name });
157
+ }
158
+ }
149
159
  createOrGetMode(mode) {
150
- var _a, _b;
160
+ var _a, _b, _c;
151
161
  if (typeof mode === 'string') {
152
162
  if (mode === ((_a = this.getCyclingMode()) === null || _a === void 0 ? void 0 : _a.getName())) {
153
163
  return this.cyclingMode;
154
164
  }
155
165
  const supported = this.getSupportedCyclingModes();
156
- const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
166
+ const CyclingModeClass = supported.find(M => { const m = new M(null); return m.getName() === mode; });
157
167
  if (CyclingModeClass) {
158
- return new CyclingModeClass(this);
168
+ this.modes[mode] = (_b = this.modes[mode]) !== null && _b !== void 0 ? _b : new CyclingModeClass(this);
169
+ return this.modes[mode];
159
170
  }
160
171
  else {
161
172
  return this.getDefaultCyclingMode();
162
173
  }
163
174
  }
164
- if (mode.getName() === ((_b = this.cyclingMode) === null || _b === void 0 ? void 0 : _b.getName())) {
175
+ if (mode.getName() === ((_c = this.cyclingMode) === null || _c === void 0 ? void 0 : _c.getName())) {
165
176
  return this.cyclingMode;
166
177
  }
167
178
  return mode;
@@ -182,7 +193,7 @@ class IncyclistDevice extends events_1.default {
182
193
  const config = this.getControllerInfo();
183
194
  const C = config.default;
184
195
  try {
185
- return new C(this);
196
+ return this.createMode(C);
186
197
  }
187
198
  catch (err) {
188
199
  this.logEvent({ message: 'error', error: err.message, fn: 'getDefaultCyclingMode', stack: err.stack });
@@ -29,6 +29,7 @@ export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessM
29
29
  protected setConstants(): void;
30
30
  protected establishControl(): Promise<boolean>;
31
31
  protected sendInitialRequest(): Promise<void>;
32
+ protected updateCyclingModeConfig(): void;
32
33
  protected checkCapabilities(): Promise<void>;
33
34
  protected updateCapabilitiesFromFeatures(features: IndoorBikeFeatures): void;
34
35
  sendUpdate(request: any, enforced?: boolean): Promise<UpdateRequest | void>;
@@ -21,11 +21,9 @@ const adapter_1 = __importDefault(require("../base/adapter"));
21
21
  const consts_1 = require("./consts");
22
22
  const types_1 = require("../../types");
23
23
  const utils_1 = require("../../utils/utils");
24
- const utils_2 = require("../utils");
25
24
  const play_1 = require("../zwift/play");
26
25
  const features_1 = require("../../features");
27
26
  const fm_resistance_1 = __importDefault(require("../../modes/fm-resistance"));
28
- const ZWIFT_PLAY_UUID = '0000000119ca465186e5fa29dcdd09d1';
29
27
  class BleFmAdapter extends adapter_1.default {
30
28
  constructor(settings, props) {
31
29
  super(settings, props);
@@ -53,7 +51,7 @@ class BleFmAdapter extends adapter_1.default {
53
51
  var _a, _b;
54
52
  if (!this.getFeatureToggle().has('VirtualShifting'))
55
53
  return false;
56
- return (_b = (_a = this.device) === null || _a === void 0 ? void 0 : _a.getSupportedServiceUUids()) === null || _b === void 0 ? void 0 : _b.some(s => (0, utils_2.matches)(s, ZWIFT_PLAY_UUID));
54
+ return (_b = (_a = this.device) === null || _a === void 0 ? void 0 : _a.supportsVirtualShifting()) !== null && _b !== void 0 ? _b : false;
57
55
  }
58
56
  getSupportedCyclingModes() {
59
57
  var _a, _b;
@@ -75,18 +73,20 @@ class BleFmAdapter extends adapter_1.default {
75
73
  getDefaultCyclingMode() {
76
74
  var _a, _b;
77
75
  if (((_a = this.props) === null || _a === void 0 ? void 0 : _a.capabilities) && this.props.capabilities.indexOf(types_1.IncyclistCapability.Control) === -1)
78
- return new power_meter_1.default(this);
76
+ return this.createMode(power_meter_1.default);
79
77
  const features = (_b = this.getSensor()) === null || _b === void 0 ? void 0 : _b.features;
80
- if (!features)
81
- return new antble_smarttrainer_1.default(this);
82
- if (features.setSlope === undefined || features.setSlope)
83
- return new antble_smarttrainer_1.default(this);
78
+ if (!features) {
79
+ return this.createMode(antble_smarttrainer_1.default);
80
+ }
81
+ if (features.setSlope === undefined || features.setSlope) {
82
+ return this.createMode(antble_smarttrainer_1.default);
83
+ }
84
84
  if (features.setPower === undefined || features.setPower)
85
- return new antble_erg_1.default(this);
85
+ return this.createMode(antble_erg_1.default);
86
86
  if (features.setResistance) {
87
- return new fm_resistance_1.default(this);
87
+ return this.createMode(fm_resistance_1.default);
88
88
  }
89
- return new power_meter_1.default(this);
89
+ return this.createMode(power_meter_1.default);
90
90
  }
91
91
  mapData(deviceData) {
92
92
  var _a, _b, _c, _d, _e;
@@ -223,6 +223,14 @@ class BleFmAdapter extends adapter_1.default {
223
223
  yield this.sendUpdate(startRequest, true);
224
224
  });
225
225
  }
226
+ updateCyclingModeConfig() {
227
+ const modes = this.getSupportedCyclingModes();
228
+ modes.forEach(ModeClass => {
229
+ const mode = this.createMode(ModeClass);
230
+ mode.resetConfig();
231
+ mode.getConfig();
232
+ });
233
+ }
226
234
  checkCapabilities() {
227
235
  return __awaiter(this, void 0, void 0, function* () {
228
236
  const before = this.capabilities.join(',');
@@ -242,6 +250,7 @@ class BleFmAdapter extends adapter_1.default {
242
250
  if (before !== after) {
243
251
  this.logEvent({ message: 'device capabilities updated', name: this.getSettings().name, interface: this.getSettings().interface, capabilities: this.capabilities });
244
252
  this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
253
+ this.updateCyclingModeConfig();
245
254
  }
246
255
  });
247
256
  }
@@ -97,3 +97,4 @@ export declare const TargetSettingFeatureFlag: {
97
97
  SpinDownControlSupported: number;
98
98
  TargetedCadenceConfigurationSupported: number;
99
99
  };
100
+ export declare const ZWIFT_PLAY_UUID = "0000000119ca465186e5fa29dcdd09d1";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TargetSettingFeatureFlag = exports.FitnessMachineFeatureFlag = exports.IndoorBikeDataFlag = exports.cRR = exports.cwABike = void 0;
3
+ exports.ZWIFT_PLAY_UUID = exports.TargetSettingFeatureFlag = exports.FitnessMachineFeatureFlag = exports.IndoorBikeDataFlag = exports.cRR = exports.cwABike = void 0;
4
4
  exports.cwABike = {
5
5
  race: 0.35,
6
6
  triathlon: 0.29,
@@ -61,3 +61,4 @@ exports.TargetSettingFeatureFlag = {
61
61
  SpinDownControlSupported: bit(15),
62
62
  TargetedCadenceConfigurationSupported: bit(16)
63
63
  };
64
+ exports.ZWIFT_PLAY_UUID = '0000000119ca465186e5fa29dcdd09d1';
@@ -36,6 +36,7 @@ export default class BleFitnessMachineDevice extends TBleSensor {
36
36
  protected parseIndoorBikeData(_data: Uint8Array): IndoorBikeData;
37
37
  protected parseFitnessMachineStatus(_data: Uint8Array): IndoorBikeData;
38
38
  getFitnessMachineFeatures(): Promise<IndoorBikeFeatures | undefined>;
39
+ supportsVirtualShifting(): boolean;
39
40
  protected buildFitnessMachineInfo(fitnessMachine: number): string[];
40
41
  protected buildTargetSettingsInfo(targetSettings: number): string[];
41
42
  protected writeFtmsMessage(requestedOpCode: any, data: any, props?: BleWriteProps): Promise<number>;
@@ -332,6 +332,10 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
332
332
  }
333
333
  });
334
334
  }
335
+ supportsVirtualShifting() {
336
+ var _a;
337
+ return (_a = this.getSupportedServiceUUids()) === null || _a === void 0 ? void 0 : _a.some(s => (0, utils_1.matches)(s, consts_2.ZWIFT_PLAY_UUID));
338
+ }
335
339
  buildFitnessMachineInfo(fitnessMachine) {
336
340
  const info = [];
337
341
  const check = (flag, name) => {
@@ -387,6 +391,9 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
387
391
  check(consts_2.TargetSettingFeatureFlag.WheelCircumferenceConfigurationSupported, 'wheelCircumference');
388
392
  check(consts_2.TargetSettingFeatureFlag.SpinDownControlSupported, 'spindown');
389
393
  check(consts_2.TargetSettingFeatureFlag.TargetedCadenceConfigurationSupported, 'cadence');
394
+ if (this.supportsVirtualShifting) {
395
+ info.push('virtualShifting');
396
+ }
390
397
  }
391
398
  catch (err) {
392
399
  this.logEvent({ message: 'could not read TargetSettingsInfo', error: err.message, stack: err.stack, device: this.getName() });
@@ -40,6 +40,7 @@ export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase i
40
40
  constructor(adapter: IAdapter, props?: any);
41
41
  getBikeInitRequest(): UpdateRequest;
42
42
  checkForResetOrEmpty(request: UpdateRequest): UpdateRequest | undefined;
43
+ resetConfig(): void;
43
44
  getConfig(): CyclingModeConfig;
44
45
  protected checkSlopeNoShiftig(request: UpdateRequest, newRequest?: UpdateRequest): void;
45
46
  protected checkSlopeWithAdapterShifting(request: UpdateRequest, newRequest?: UpdateRequest): void;
@@ -70,12 +70,24 @@ class SmartTrainerCyclingMode extends power_base_1.default {
70
70
  return this.prevRequest;
71
71
  }
72
72
  }
73
+ resetConfig() {
74
+ const config = this.getConfig();
75
+ const virtshiftIdx = config.properties.findIndex(p => p.key === 'virtshift');
76
+ if (virtshiftIdx !== -1) {
77
+ config.properties.splice(virtshiftIdx, 1);
78
+ }
79
+ let startGearIdx = config.properties.findIndex(p => p.key === 'startGear');
80
+ if (startGearIdx !== -1) {
81
+ config.properties.splice(startGearIdx, 1);
82
+ }
83
+ }
73
84
  getConfig() {
85
+ var _a, _b;
74
86
  const config = super.getConfig();
75
87
  const virtShiftEnabled = this.getFeatureToogle().has('VirtualShifting');
76
88
  let virtshift = config.properties.find(p => p.key === 'virtshift');
77
89
  let startGear = config.properties.find(p => p.key === 'startGear');
78
- if (!virtshift && !this.adapter.supportsVirtualShifting()) {
90
+ if (!virtshift && !((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.supportsVirtualShifting())) {
79
91
  const options = virtShiftEnabled ? [
80
92
  'Disabled',
81
93
  { key: 'Incyclist', display: 'App only (beta)' },
@@ -88,7 +100,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
88
100
  virtshift = { key: 'virtshift', name: 'Virtual Shifting', description: 'Enable virtual shifting', type: types_1.CyclingModeProperyType.SingleSelect, options, default: 'Disabled' };
89
101
  config.properties.push(virtshift);
90
102
  }
91
- if (!virtshift && virtShiftEnabled && this.adapter.supportsVirtualShifting()) {
103
+ if (!virtshift && virtShiftEnabled && ((_b = this.adapter) === null || _b === void 0 ? void 0 : _b.supportsVirtualShifting())) {
92
104
  const options = [
93
105
  'Disabled',
94
106
  { key: 'Incyclist', display: 'App only (beta)' },
@@ -193,7 +205,6 @@ class SmartTrainerCyclingMode extends power_base_1.default {
193
205
  return;
194
206
  }
195
207
  if (request.targetPower !== undefined || request.targetPowerDelta !== undefined || request.gearDelta !== undefined || request.gearRatio !== undefined) {
196
- console.log('# cadence change ignored due to other power/gear request', request);
197
208
  return;
198
209
  }
199
210
  if (this.data.pedalRpm !== this.prevData.pedalRpm) {
@@ -227,7 +238,8 @@ class SmartTrainerCyclingMode extends power_base_1.default {
227
238
  this.logger.logEvent({ message: 'set simulated power (gear change)', target: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope, prevTarget: this.prevSimPower, actualPower: prevPower, newPower });
228
239
  }
229
240
  else if (changed === 'slope' || changed === 'cadence') {
230
- this.simPower = prev + delta / 3;
241
+ const adjustTime = this.simSlope < 0 ? 5 : 3;
242
+ this.simPower = prev + delta / adjustTime;
231
243
  this.logger.logEvent({ message: `set simulated power (${changed} change)`, target: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope, prevTarget: this.prevSimPower, actualPower: prevPower, newPower });
232
244
  }
233
245
  else {
@@ -343,6 +355,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
343
355
  }
344
356
  }
345
357
  getVirtualShiftMode() {
358
+ var _a;
346
359
  try {
347
360
  if (!this.getFeatureToogle().has('VirtualShifting')) {
348
361
  return 'Disabled';
@@ -361,7 +374,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
361
374
  return 'SlopeDelta';
362
375
  }
363
376
  else if (virtshiftMode === 'Enabled') {
364
- return this.adapter.supportsVirtualShifting() ? 'Adapter' : 'Simulated';
377
+ return ((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.supportsVirtualShifting()) ? 'Adapter' : 'Simulated';
365
378
  }
366
379
  }
367
380
  catch (err) {
@@ -53,6 +53,8 @@ export default interface ICyclingMode {
53
53
  setModeProperty(name: string, value: any): void;
54
54
  getModeProperty(name: string): any;
55
55
  getData(): Partial<IncyclistBikeData>;
56
+ resetConfig(): void;
57
+ getConfig(): CyclingModeConfig;
56
58
  }
57
59
  export type CyclingModeConfig = {
58
60
  isERG?: boolean;
@@ -82,6 +84,7 @@ export declare class CyclingMode implements ICyclingMode {
82
84
  isERG(): boolean;
83
85
  isSIM(): boolean;
84
86
  isResistance(): boolean;
87
+ resetConfig(): void;
85
88
  getData(): Partial<IncyclistBikeData>;
86
89
  confirmed(request: UpdateRequest): void;
87
90
  }
@@ -64,6 +64,7 @@ class CyclingMode {
64
64
  isResistance() {
65
65
  return this.getConfig().isResistance;
66
66
  }
67
+ resetConfig() { }
67
68
  getData() {
68
69
  return {};
69
70
  }
@@ -52,7 +52,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
52
52
  }
53
53
  getDefaultCyclingMode() {
54
54
  if (this.props.capabilities && this.props.capabilities.indexOf(types_1.IncyclistCapability.Control) === -1)
55
- return new daum_power_1.default(this);
55
+ return this.createMode(daum_power_1.default);
56
56
  return super.getDefaultCyclingMode();
57
57
  }
58
58
  sendInitCommands() {
@@ -19,7 +19,6 @@ const daum_classic_standard_1 = __importDefault(require("../../../modes/daum-cla
19
19
  const comms_1 = __importDefault(require("./comms"));
20
20
  const serial_interface_1 = __importDefault(require("../../base/serial-interface"));
21
21
  const daum_erg_1 = __importDefault(require("../../../modes/daum-erg"));
22
- const daum_smarttrainer_1 = __importDefault(require("../../../modes/daum-smarttrainer"));
23
22
  const daum_power_1 = __importDefault(require("../../../modes/daum-power"));
24
23
  const consts_1 = require("./consts");
25
24
  class DaumClassicAdapter extends DaumAdapter_1.default {
@@ -191,7 +190,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
191
190
  }
192
191
  DaumClassicAdapter.NAME = consts_1.PROTOCOL_NAME;
193
192
  DaumClassicAdapter.controllers = {
194
- modes: [daum_erg_1.default, daum_smarttrainer_1.default, daum_power_1.default, daum_classic_standard_1.default],
193
+ modes: [daum_erg_1.default, daum_power_1.default, daum_classic_standard_1.default],
195
194
  default: daum_classic_standard_1.default
196
195
  };
197
196
  exports.default = DaumClassicAdapter;
@@ -21,7 +21,6 @@ const types_1 = require("../../types");
21
21
  const types_2 = require("../../../types");
22
22
  const daum_premium_standard_1 = __importDefault(require("../../../modes/daum-premium-standard"));
23
23
  const daum_erg_1 = __importDefault(require("../../../modes/daum-erg"));
24
- const daum_smarttrainer_1 = __importDefault(require("../../../modes/daum-smarttrainer"));
25
24
  const daum_power_1 = __importDefault(require("../../../modes/daum-power"));
26
25
  const PROTOCOL_NAME = "Daum Premium";
27
26
  const DAUM_PREMIUM_DEFAULT_PORT = 51955;
@@ -233,7 +232,7 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
233
232
  }
234
233
  DaumPremiumAdapter.NAME = PROTOCOL_NAME;
235
234
  DaumPremiumAdapter.controllers = {
236
- modes: [daum_erg_1.default, daum_smarttrainer_1.default, daum_power_1.default, daum_premium_standard_1.default],
235
+ modes: [daum_erg_1.default, daum_power_1.default, daum_premium_standard_1.default],
237
236
  default: daum_erg_1.default
238
237
  };
239
238
  exports.default = DaumPremiumAdapter;
@@ -50,5 +50,6 @@ export interface IAdapter extends EventEmitter, IBike, ISensor {
50
50
  resetData(): void;
51
51
  onScanStart(): void;
52
52
  onScanStop(): void;
53
+ createMode(ModeClass: typeof CyclingMode): ICyclingMode;
53
54
  onData(callback: OnDeviceDataCallback): any;
54
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.4.6-beta.3",
3
+ "version": "2.4.6",
4
4
  "dependencies": {
5
5
  "@protobuf-ts/runtime": "^2.11.1",
6
6
  "@serialport/bindings-interface": "^1.2.2",