incyclist-devices 2.4.12 → 2.4.13

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.
@@ -294,18 +294,27 @@ class BleFmAdapter extends adapter_1.default {
294
294
  const device = this.getSensor();
295
295
  if (this.hasCapability(types_1.IncyclistCapability.Control)) {
296
296
  const send = () => __awaiter(this, void 0, void 0, function* () {
297
- var _a;
298
297
  const res = {};
299
298
  if (update.slope !== undefined) {
300
- yield device.setSlope(update.slope);
299
+ if (update.isHub) {
300
+ if (!this.zwiftPlay) {
301
+ this.initVirtualShifting();
302
+ }
303
+ if (this.zwiftPlay) {
304
+ yield this.zwiftPlay.setIncline(update.slope);
305
+ }
306
+ }
307
+ else {
308
+ yield device.setSlope(update.slope);
309
+ }
301
310
  res.slope = update.slope;
302
311
  }
303
- if (update.targetPower !== undefined) {
312
+ if (update.targetPower !== undefined && !update.isHub) {
304
313
  const tp = update.targetPower > 0 ? update.targetPower : 0;
305
314
  yield device.setTargetPower(tp);
306
315
  res.targetPower = tp;
307
316
  }
308
- if (update.targetResistance !== undefined) {
317
+ if (update.targetResistance !== undefined && !update.isHub) {
309
318
  yield device.setTargetResistanceLevel(update.targetResistance);
310
319
  res.targetResistance = update.targetResistance;
311
320
  }
@@ -314,10 +323,6 @@ class BleFmAdapter extends adapter_1.default {
314
323
  this.initVirtualShifting();
315
324
  }
316
325
  if (this.zwiftPlay && !Number.isNaN(update.gearRatio)) {
317
- let slope = (_a = update.slope) !== null && _a !== void 0 ? _a : 0;
318
- if (slope === 0)
319
- slope = 0.01;
320
- yield this.zwiftPlay.setSimulationData({ inclineX100: slope * 100 });
321
326
  const gearRatio = yield this.zwiftPlay.setGearRatio(update.gearRatio);
322
327
  res.gearRatio = gearRatio;
323
328
  }
@@ -1,6 +1,6 @@
1
1
  import { EventLogger } from "gd-eventlog";
2
2
  import { LegacyProfile } from "../../../antv2/types";
3
- import { HubCommand, HubRequest, SimulationParam } from "../../../proto/zwift_hub";
3
+ import { DeviceSettingsSubContent, HubCommand, HubRequest, SimulationParam } from "../../../proto/zwift_hub";
4
4
  import { TBleSensor } from "../../base/sensor";
5
5
  import { BleProtocol, IBlePeripheral } from "../../types";
6
6
  import { EventEmitter } from "events";
@@ -37,6 +37,8 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
37
37
  protected initHubServicePromise: Promise<boolean>;
38
38
  protected pairPromise: Promise<boolean>;
39
39
  protected subscribePromise: Promise<boolean>;
40
+ protected prevHubSettings: DeviceSettingsSubContent | undefined;
41
+ protected prevcWax10000: number;
40
42
  constructor(peripheral: IBlePeripheral | TBleSensor, props?: BleZwiftPlaySensorProps);
41
43
  reconnectSensor(): Promise<void>;
42
44
  stopSensor(): Promise<boolean>;
@@ -44,6 +46,7 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
44
46
  onData(characteristic: string, data: Buffer, isNotify?: boolean): boolean;
45
47
  requestDataUpdate(dataId: number): Promise<void>;
46
48
  setSimulationData(data?: SimulationParam): Promise<void>;
49
+ setIncline(incline: number): Promise<void>;
47
50
  setGearRatio(gearRatio: number): Promise<number>;
48
51
  protected sendPlayCommand(id: number, command: Buffer): Promise<Buffer<ArrayBufferLike>>;
49
52
  protected onMeasurement(d: Buffer): boolean;
@@ -74,7 +74,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
74
74
  }
75
75
  setSimulationData(data) {
76
76
  return __awaiter(this, void 0, void 0, function* () {
77
- var _a, _b, _c, _d;
77
+ var _a, _b, _c, _d, _e, _f, _g;
78
78
  try {
79
79
  if (!this.isHubServiceActive) {
80
80
  yield this.initHubService(false);
@@ -87,7 +87,19 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
87
87
  let inclineX100 = Math.round((_d = data === null || data === void 0 ? void 0 : data.inclineX100) !== null && _d !== void 0 ? _d : 1);
88
88
  if (inclineX100 === 0 || Number.isNaN(inclineX100))
89
89
  inclineX100 = 1;
90
- const simulation = { inclineX100, crrx100000, cWax10000, windx100 };
90
+ const simulation = {};
91
+ if (inclineX100 !== ((_e = this.prevHubSettings) === null || _e === void 0 ? void 0 : _e.inclineX100)) {
92
+ simulation.inclineX100 = inclineX100;
93
+ }
94
+ if (crrx100000 !== ((_f = this.prevHubSettings) === null || _f === void 0 ? void 0 : _f.crrx100000))
95
+ simulation.crrx100000 = crrx100000;
96
+ if (cWax10000 !== this.prevcWax10000) {
97
+ simulation.cWax10000 = cWax10000;
98
+ this.prevcWax10000 = cWax10000;
99
+ }
100
+ if (windx100 !== ((_g = this.prevHubSettings) === null || _g === void 0 ? void 0 : _g.windx100)) {
101
+ simulation.windx100 = windx100;
102
+ }
91
103
  yield this.sendHubCommand({ simulation });
92
104
  yield this.requestDataUpdate(512);
93
105
  }
@@ -96,8 +108,15 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
96
108
  }
97
109
  });
98
110
  }
111
+ setIncline(incline) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const inclineX100 = Math.round(incline * 100);
114
+ yield this.setSimulationData({ inclineX100 });
115
+ });
116
+ }
99
117
  setGearRatio(gearRatio) {
100
118
  return __awaiter(this, void 0, void 0, function* () {
119
+ var _a, _b, _c;
101
120
  try {
102
121
  if (!this.isHubServiceActive) {
103
122
  yield this.initHubService();
@@ -107,10 +126,18 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
107
126
  const gearRatioX10000 = Math.round(gearRatio * 10000);
108
127
  const bikeWeightx100 = 10 * 100;
109
128
  const riderWeightx100 = 75 * 100;
110
- const command = {
111
- physical: { bikeWeightx100, gearRatioX10000, riderWeightx100 }
112
- };
113
- yield this.sendHubCommand(command);
129
+ const physical = {};
130
+ if (bikeWeightx100 !== ((_a = this.prevHubSettings) === null || _a === void 0 ? void 0 : _a.bikeWeightx100))
131
+ physical.bikeWeightx100 = bikeWeightx100;
132
+ if (riderWeightx100 !== ((_b = this.prevHubSettings) === null || _b === void 0 ? void 0 : _b.riderWeightx100))
133
+ physical.riderWeightx100 = riderWeightx100;
134
+ if (gearRatioX10000 !== ((_c = this.prevHubSettings) === null || _c === void 0 ? void 0 : _c.gearRatiox10000)) {
135
+ physical.gearRatioX10000 = gearRatioX10000;
136
+ }
137
+ if (Object.keys(physical).length === 0) {
138
+ return;
139
+ }
140
+ yield this.sendHubCommand({ physical });
114
141
  yield this.requestDataUpdate(512);
115
142
  }
116
143
  catch (err) {
@@ -279,6 +306,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
279
306
  const si = zwift_hub_1.DeviceSettings.fromBinary(payload);
280
307
  this.emit('hub-settings', si === null || si === void 0 ? void 0 : si.subContent);
281
308
  this.logEvent({ message: 'hub settings update', settings: si === null || si === void 0 ? void 0 : si.subContent });
309
+ this.prevHubSettings = si === null || si === void 0 ? void 0 : si.subContent;
282
310
  }
283
311
  }
284
312
  catch (err) {
@@ -485,6 +513,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
485
513
  this.isHubServiceSubscribed = false;
486
514
  this.isHubServiceActive = false;
487
515
  delete this.initHubServicePromise;
516
+ delete this.prevHubSettings;
488
517
  }
489
518
  getManufacturerData() {
490
519
  const data = this.peripheral.getManufacturerData();
@@ -1,7 +1,7 @@
1
1
  import ICyclingMode, { CyclingModeConfig, CyclingModeProperyType, UpdateRequest } from "./types";
2
2
  import PowerBasedCyclingModeBase from "./power-base";
3
3
  import { IAdapter, IncyclistBikeData } from "../types";
4
- type VirtshiftMode = 'Disabled' | 'SlopeDelta' | 'Adapter' | 'Simulated';
4
+ export type VirtshiftMode = 'Disabled' | 'SlopeDelta' | 'Adapter' | 'Simulated';
5
5
  export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
6
6
  protected static config: {
7
7
  name: string;
@@ -61,4 +61,3 @@ export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase i
61
61
  protected getGearString(): string;
62
62
  protected getFeatureToogle(): import("../features").FeatureToggle;
63
63
  }
64
- export {};
@@ -57,7 +57,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
57
57
  if (virtshiftMode === 'Adapter') {
58
58
  this.gear = (0, utils_1.intVal)(this.getSetting('startGear'));
59
59
  const gearRatio = this.gearRatios[this.gear - 1];
60
- return { slope: 0, gearRatio };
60
+ return { slope: 0, gearRatio, isHub: true };
61
61
  }
62
62
  this.prevRequest = { slope: 0 };
63
63
  return { slope: 0 };
@@ -135,6 +135,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
135
135
  this.checkSlopeNoShiftig(request, newRequest);
136
136
  const gear = (_a = this.gear) !== null && _a !== void 0 ? _a : this.getSetting('startGear');
137
137
  newRequest.gearRatio = this.gearRatios[gear - 1];
138
+ newRequest.isHub = true;
138
139
  }
139
140
  getSlopeDelta() {
140
141
  return this.gearDelta * 0.5;
@@ -14,6 +14,7 @@ export type UpdateRequest = {
14
14
  gear?: number;
15
15
  gearRatio?: number;
16
16
  forced?: boolean;
17
+ isHub?: boolean;
17
18
  };
18
19
  export declare enum CyclingModeProperyType {
19
20
  Integer = "Integer",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.4.12",
3
+ "version": "2.4.13",
4
4
  "dependencies": {
5
5
  "@protobuf-ts/runtime": "^2.11.1",
6
6
  "@serialport/bindings-interface": "^1.2.2",