incyclist-devices 2.4.11 → 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,12 +46,14 @@ 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;
50
53
  initHubService(setSimulation?: boolean): Promise<boolean>;
51
54
  sendHubRequest(request: HubRequest): Promise<Buffer<ArrayBufferLike>>;
52
55
  sendHubCommand(command: HubCommand): Promise<Buffer<ArrayBufferLike>>;
56
+ protected onTrainerResponse(m: Buffer): void;
53
57
  protected onRidingData(m: Buffer): void;
54
58
  protected onDeviceInformation(m: Buffer): void;
55
59
  onClickButtonMessage(d: Buffer): void;
@@ -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) {
@@ -146,6 +173,9 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
146
173
  else if (type === 0x03) {
147
174
  this.onRidingData(message);
148
175
  }
176
+ else if (type === 0x2A) {
177
+ this.onTrainerResponse(message);
178
+ }
149
179
  else if (type === 0x3c) {
150
180
  this.onDeviceInformation(message);
151
181
  }
@@ -242,6 +272,16 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
242
272
  return yield this.sendPlayCommand(0x04, message);
243
273
  });
244
274
  }
275
+ onTrainerResponse(m) {
276
+ try {
277
+ const data = zwift_hub_1.TrainerResponse.fromBinary(m);
278
+ this.emit('hub-trainer-response', data);
279
+ this.logEvent({ message: 'trainer response received', data });
280
+ }
281
+ catch (err) {
282
+ this.logEvent({ message: 'Error', fn: 'onTrainerResponse', error: err.message, stack: err.stack });
283
+ }
284
+ }
245
285
  onRidingData(m) {
246
286
  try {
247
287
  this.tsLastRidingData = Date.now();
@@ -266,6 +306,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
266
306
  const si = zwift_hub_1.DeviceSettings.fromBinary(payload);
267
307
  this.emit('hub-settings', si === null || si === void 0 ? void 0 : si.subContent);
268
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;
269
310
  }
270
311
  }
271
312
  catch (err) {
@@ -472,6 +513,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
472
513
  this.isHubServiceSubscribed = false;
473
514
  this.isHubServiceActive = false;
474
515
  delete this.initHubServicePromise;
516
+ delete this.prevHubSettings;
475
517
  }
476
518
  getManufacturerData() {
477
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",
@@ -67,6 +67,13 @@ export interface RideKeyPadStatus {
67
67
  buttonMap?: number;
68
68
  analogButtons?: RideAnalogKeyGroup;
69
69
  }
70
+ export interface TrainerResponse {
71
+ unknown?: number;
72
+ content?: TrainerResponseContent;
73
+ }
74
+ export interface TrainerResponseContent {
75
+ text?: string;
76
+ }
70
77
  export interface ClickKeyPadStatus {
71
78
  buttonPlus?: PlayButtonStatus;
72
79
  buttonMinus?: PlayButtonStatus;
@@ -230,6 +237,20 @@ declare class RideKeyPadStatus$Type extends MessageType<RideKeyPadStatus> {
230
237
  internalBinaryWrite(message: RideKeyPadStatus, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
231
238
  }
232
239
  export declare const RideKeyPadStatus: RideKeyPadStatus$Type;
240
+ declare class TrainerResponse$Type extends MessageType<TrainerResponse> {
241
+ constructor();
242
+ create(value?: PartialMessage<TrainerResponse>): TrainerResponse;
243
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: TrainerResponse): TrainerResponse;
244
+ internalBinaryWrite(message: TrainerResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
245
+ }
246
+ export declare const TrainerResponse: TrainerResponse$Type;
247
+ declare class TrainerResponseContent$Type extends MessageType<TrainerResponseContent> {
248
+ constructor();
249
+ create(value?: PartialMessage<TrainerResponseContent>): TrainerResponseContent;
250
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: TrainerResponseContent): TrainerResponseContent;
251
+ internalBinaryWrite(message: TrainerResponseContent, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
252
+ }
253
+ export declare const TrainerResponseContent: TrainerResponseContent$Type;
233
254
  declare class ClickKeyPadStatus$Type extends MessageType<ClickKeyPadStatus> {
234
255
  constructor();
235
256
  create(value?: PartialMessage<ClickKeyPadStatus>): ClickKeyPadStatus;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeviceDataEnvelope = exports.DeviceSettingsSubContent = exports.DeviceSettings = exports.DeviceInformation = exports.SubContent = exports.DeviceInformationContent = exports.ClickKeyPadStatus = exports.RideKeyPadStatus = exports.RideAnalogKeyGroup = exports.RideAnalogKeyPress = exports.Idle = exports.PlayCommand = exports.PlayCommandContents = exports.PlayCommandParameters = exports.PlayKeyPadStatus = exports.HubCommand = exports.PhysicalParam = exports.SimulationParam = exports.HubRidingData = exports.HubRequest = exports.RideAnalogLocation = exports.RideButtonMask = exports.PlayButtonStatus = void 0;
3
+ exports.DeviceDataEnvelope = exports.DeviceSettingsSubContent = exports.DeviceSettings = exports.DeviceInformation = exports.SubContent = exports.DeviceInformationContent = exports.ClickKeyPadStatus = exports.TrainerResponseContent = exports.TrainerResponse = exports.RideKeyPadStatus = exports.RideAnalogKeyGroup = exports.RideAnalogKeyPress = exports.Idle = exports.PlayCommand = exports.PlayCommandContents = exports.PlayCommandParameters = exports.PlayKeyPadStatus = exports.HubCommand = exports.PhysicalParam = exports.SimulationParam = exports.HubRidingData = exports.HubRequest = exports.RideAnalogLocation = exports.RideButtonMask = exports.PlayButtonStatus = void 0;
4
4
  const runtime_1 = require("@protobuf-ts/runtime");
5
5
  const runtime_2 = require("@protobuf-ts/runtime");
6
6
  const runtime_3 = require("@protobuf-ts/runtime");
@@ -715,6 +715,94 @@ class RideKeyPadStatus$Type extends runtime_4.MessageType {
715
715
  }
716
716
  }
717
717
  exports.RideKeyPadStatus = new RideKeyPadStatus$Type();
718
+ class TrainerResponse$Type extends runtime_4.MessageType {
719
+ constructor() {
720
+ super("org.cagnulen.qdomyoszwift.TrainerResponse", [
721
+ { no: 1, name: "Unknown", kind: "scalar", jsonName: "Unknown", opt: true, T: 13 },
722
+ { no: 2, name: "Content", kind: "message", jsonName: "Content", T: () => exports.TrainerResponseContent }
723
+ ]);
724
+ }
725
+ create(value) {
726
+ const message = globalThis.Object.create((this.messagePrototype));
727
+ if (value !== undefined)
728
+ (0, runtime_3.reflectionMergePartial)(this, message, value);
729
+ return message;
730
+ }
731
+ internalBinaryRead(reader, length, options, target) {
732
+ let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length;
733
+ while (reader.pos < end) {
734
+ let [fieldNo, wireType] = reader.tag();
735
+ switch (fieldNo) {
736
+ case 1:
737
+ message.unknown = reader.uint32();
738
+ break;
739
+ case 2:
740
+ message.content = exports.TrainerResponseContent.internalBinaryRead(reader, reader.uint32(), options, message.content);
741
+ break;
742
+ default:
743
+ let u = options.readUnknownField;
744
+ if (u === "throw")
745
+ throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
746
+ let d = reader.skip(wireType);
747
+ if (u !== false)
748
+ (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
749
+ }
750
+ }
751
+ return message;
752
+ }
753
+ internalBinaryWrite(message, writer, options) {
754
+ if (message.unknown !== undefined)
755
+ writer.tag(1, runtime_1.WireType.Varint).uint32(message.unknown);
756
+ if (message.content)
757
+ exports.TrainerResponseContent.internalBinaryWrite(message.content, writer.tag(2, runtime_1.WireType.LengthDelimited).fork(), options).join();
758
+ let u = options.writeUnknownFields;
759
+ if (u !== false)
760
+ (u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
761
+ return writer;
762
+ }
763
+ }
764
+ exports.TrainerResponse = new TrainerResponse$Type();
765
+ class TrainerResponseContent$Type extends runtime_4.MessageType {
766
+ constructor() {
767
+ super("org.cagnulen.qdomyoszwift.TrainerResponseContent", [
768
+ { no: 4, name: "Text", kind: "scalar", jsonName: "Text", opt: true, T: 9 }
769
+ ]);
770
+ }
771
+ create(value) {
772
+ const message = globalThis.Object.create((this.messagePrototype));
773
+ if (value !== undefined)
774
+ (0, runtime_3.reflectionMergePartial)(this, message, value);
775
+ return message;
776
+ }
777
+ internalBinaryRead(reader, length, options, target) {
778
+ let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length;
779
+ while (reader.pos < end) {
780
+ let [fieldNo, wireType] = reader.tag();
781
+ switch (fieldNo) {
782
+ case 4:
783
+ message.text = reader.string();
784
+ break;
785
+ default:
786
+ let u = options.readUnknownField;
787
+ if (u === "throw")
788
+ throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
789
+ let d = reader.skip(wireType);
790
+ if (u !== false)
791
+ (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
792
+ }
793
+ }
794
+ return message;
795
+ }
796
+ internalBinaryWrite(message, writer, options) {
797
+ if (message.text !== undefined)
798
+ writer.tag(4, runtime_1.WireType.LengthDelimited).string(message.text);
799
+ let u = options.writeUnknownFields;
800
+ if (u !== false)
801
+ (u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
802
+ return writer;
803
+ }
804
+ }
805
+ exports.TrainerResponseContent = new TrainerResponseContent$Type();
718
806
  class ClickKeyPadStatus$Type extends runtime_4.MessageType {
719
807
  constructor() {
720
808
  super("org.cagnulen.qdomyoszwift.ClickKeyPadStatus", [
@@ -2,7 +2,7 @@ import { DeviceType, IncyclistBikeData } from '../../../types';
2
2
  export declare const DEFAULT_AGE = 30;
3
3
  export declare const DEFAULT_USER_WEIGHT = 75;
4
4
  export declare const DEFAULT_BIKE_WEIGHT = 10;
5
- export declare function getCockpit(c: number): "Cardio" | "Fitness" | "Vita De Luxe" | "8008" | "8008 TRS" | "8080" | "Therapie" | "8008 TRS Pro" | "8008 TRS3" | "ergo_lyps Cardio Pro" | "Unknown";
5
+ export declare function getCockpit(c: number): "Unknown" | "Cardio" | "Fitness" | "Vita De Luxe" | "8008" | "8008 TRS" | "8080" | "Therapie" | "8008 TRS Pro" | "8008 TRS3" | "ergo_lyps Cardio Pro";
6
6
  export declare function getSerialNo(arr: Uint8Array, start: number, length: number): string;
7
7
  export declare function getBikeType(type?: DeviceType): number;
8
8
  export declare function getGender(sex: any): 0 | 1 | 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.4.11",
3
+ "version": "2.4.13",
4
4
  "dependencies": {
5
5
  "@protobuf-ts/runtime": "^2.11.1",
6
6
  "@serialport/bindings-interface": "^1.2.2",