incyclist-devices 2.3.36 → 2.3.37

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.
@@ -102,8 +102,10 @@ class SmartTrainerCyclingMode extends power_base_1.default {
102
102
  }
103
103
  }
104
104
  checkSlopeWithAdapterShifting(request, newRequest = {}) {
105
+ var _a;
105
106
  this.checkSlopeNoShiftig(request, newRequest);
106
- newRequest.gearRatio = this.gearRatios[this.gear];
107
+ const gear = (_a = this.gear) !== null && _a !== void 0 ? _a : this.getSetting('startGear');
108
+ newRequest.gearRatio = this.gearRatios[gear - 1];
107
109
  }
108
110
  getSlopeDelta() {
109
111
  return this.gearDelta * 0.5;
@@ -123,7 +125,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
123
125
  }
124
126
  }
125
127
  checkSlopeWithSimulatedShifting(request, newRequest = {}) {
126
- var _a, _b, _c, _d;
128
+ var _a, _b, _c, _d, _e;
127
129
  if (this.gear === undefined) {
128
130
  this.checkSlopeNoShiftig(request, newRequest);
129
131
  return;
@@ -139,15 +141,34 @@ class SmartTrainerCyclingMode extends power_base_1.default {
139
141
  if (slopeAdj !== undefined)
140
142
  this.simSlope = this.simSlope * slopeAdj / 100;
141
143
  }
142
- catch (_e) {
144
+ catch (_f) {
143
145
  }
144
- if (this.data.slope !== prev) {
145
- const virtualSpeed = (0, calculations_1.calculateVirtualSpeed)(this.data.pedalRpm, this.gearRatios[this.gear - 1]);
146
- const m = (_c = (_b = this.adapter) === null || _b === void 0 ? void 0 : _b.getWeight()) !== null && _c !== void 0 ? _c : 85;
147
- this.simPower = calculations_1.default.calculatePower(m, virtualSpeed, (_d = this.simSlope) !== null && _d !== void 0 ? _d : 0);
148
- this.verifySimPower();
149
- this.logger.logEvent({ message: 'set simulater power', power: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope });
146
+ const virtualSpeed = (0, calculations_1.calculateVirtualSpeed)(this.data.pedalRpm, this.gearRatios[this.gear - 1]);
147
+ const m = (_c = (_b = this.adapter) === null || _b === void 0 ? void 0 : _b.getWeight()) !== null && _c !== void 0 ? _c : 85;
148
+ const vCurrent = this.data.speed * 1000 / 3600;
149
+ const eKinCurrent = m * vCurrent * vCurrent / 2;
150
+ const newPower = calculations_1.default.calculatePower(m, virtualSpeed, (_d = this.simSlope) !== null && _d !== void 0 ? _d : 0);
151
+ const prevPower = this.data.power;
152
+ if (this.data.speed < 10 && this.data.isPedalling && (this.data.slope < 1 || this.data.speed === 0)) {
153
+ this.simPower = Math.max(newPower, prevPower);
154
+ this.logger.logEvent({ message: 'set simulater power', power: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope, prevPower, newPower });
155
+ }
156
+ else if (this.data.slope === prev && newPower < prevPower) {
157
+ this.simPower = prevPower;
158
+ this.logger.logEvent({ message: 'set simulater power', power: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope, prevPower, newPower });
159
+ }
160
+ else {
161
+ const powerDiff = newPower - prevPower;
162
+ const vTarget = virtualSpeed * 1000 / 3600;
163
+ const eKinTarget = m * vTarget * vTarget / 2;
164
+ const eKinPrev = eKinCurrent;
165
+ const delta = eKinTarget - eKinPrev;
166
+ const eKinAfter1sec = eKinPrev - powerDiff * 1;
167
+ const vAfter1sec = Math.sqrt(2 * eKinAfter1sec / m) * 3600 / 1000;
168
+ this.simPower = calculations_1.default.calculatePower(m, vAfter1sec / 3.6, (_e = this.simSlope) !== null && _e !== void 0 ? _e : 0);
169
+ this.logger.logEvent({ message: 'set simulater power', power: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope, eKinPrev, eKinTarget, delta, prevPower, newPower });
150
170
  }
171
+ this.verifySimPower();
151
172
  }
152
173
  newRequest.targetPower = this.simPower;
153
174
  }
@@ -196,13 +217,17 @@ class SmartTrainerCyclingMode extends power_base_1.default {
196
217
  this.gear = this.gearRatios.length;
197
218
  }
198
219
  delete request.gearDelta;
199
- const virtualSpeed = (0, calculations_1.calculateVirtualSpeed)(this.data.pedalRpm, this.gearRatios[this.gear - 1]);
200
- const m = (_b = (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.getWeight()) !== null && _b !== void 0 ? _b : 85;
201
- this.simPower = calculations_1.default.calculatePower(m, virtualSpeed, (_d = (_c = this.simSlope) !== null && _c !== void 0 ? _c : this.data.slope) !== null && _d !== void 0 ? _d : 0);
202
- this.verifySimPower();
203
- this.logger.logEvent({ message: 'set simulater power', power: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope });
204
- this.adapter.sendUpdate({ targetPower: this.simPower }).then(() => {
205
- });
220
+ if (this.data.pedalRpm > 0) {
221
+ const virtualSpeed = (0, calculations_1.calculateVirtualSpeed)(this.data.pedalRpm, this.gearRatios[this.gear - 1]);
222
+ const m = (_b = (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.getWeight()) !== null && _b !== void 0 ? _b : 85;
223
+ this.simPower = calculations_1.default.calculatePower(m, virtualSpeed, (_d = (_c = this.simSlope) !== null && _c !== void 0 ? _c : this.data.slope) !== null && _d !== void 0 ? _d : 0);
224
+ this.verifySimPower();
225
+ this.logger.logEvent({ message: 'set simulater power', power: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope });
226
+ this.adapter.sendUpdate({ targetPower: this.simPower }).then(() => { });
227
+ }
228
+ else {
229
+ delete this.simPower;
230
+ }
206
231
  }
207
232
  break;
208
233
  case 'Adapter':
@@ -259,6 +284,9 @@ class SmartTrainerCyclingMode extends power_base_1.default {
259
284
  if (this.data.pedalRpm > 0 && this.simPower < MIN_POWER) {
260
285
  this.simPower = MIN_POWER;
261
286
  }
287
+ if (!this.data.isPedalling) {
288
+ delete this.simPower;
289
+ }
262
290
  }
263
291
  checkEmptyRequest(newRequest) {
264
292
  if (Object.keys(newRequest).length === 0) {
@@ -340,7 +368,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
340
368
  return newRequest;
341
369
  }
342
370
  getGearString() {
343
- var _a, _b, _c, _d, _e;
371
+ var _a, _b, _c, _d;
344
372
  const mode = this.getVirtualShiftMode();
345
373
  if (mode === "Disabled")
346
374
  return undefined;
@@ -351,10 +379,10 @@ class SmartTrainerCyclingMode extends power_base_1.default {
351
379
  if (mode === "SlopeDelta")
352
380
  return this.gearDelta > 0 ? `+${this.gearDelta}` : `${this.gearDelta}`;
353
381
  if (mode === 'Adapter') {
354
- this.gear = (_d = (_c = this.gear) !== null && _c !== void 0 ? _c : this.getSetting('startGear')) !== null && _d !== void 0 ? _d : 0;
382
+ this.gear = (_c = this.gear) !== null && _c !== void 0 ? _c : this.getSetting('startGear');
355
383
  return this.gear.toString();
356
384
  }
357
- return (_e = this.gear) === null || _e === void 0 ? void 0 : _e.toString();
385
+ return (_d = this.gear) === null || _d === void 0 ? void 0 : _d.toString();
358
386
  }
359
387
  }
360
388
  SmartTrainerCyclingMode.config = {
@@ -179,6 +179,7 @@ class PowerBasedCyclingModeBase extends base_1.CyclingModeBase {
179
179
  }
180
180
  copyBikeData(data, bikeData) {
181
181
  var _a;
182
+ const prevCadence = data.pedalRpm;
182
183
  const keys = Object.keys(bikeData);
183
184
  keys.forEach(key => {
184
185
  if (bikeData[key] === null)
@@ -195,7 +196,10 @@ class PowerBasedCyclingModeBase extends base_1.CyclingModeBase {
195
196
  if (data.slope === undefined)
196
197
  data.slope = 0;
197
198
  if (bikeData.isPedalling === undefined)
198
- data.isPedalling = data.pedalRpm > 0;
199
+ (data.isPedalling = data.pedalRpm > 0 || data.power > 0);
200
+ if (bikeData.pedalRpm === 0 && bikeData.power > 0 && prevCadence !== undefined) {
201
+ data.pedalRpm = prevCadence;
202
+ }
199
203
  if (((_a = this.prevRequest) === null || _a === void 0 ? void 0 : _a.slope) !== undefined) {
200
204
  data.slope = this.prevRequest.slope;
201
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.3.36",
3
+ "version": "2.3.37",
4
4
  "dependencies": {
5
5
  "@protobuf-ts/runtime": "^2.11.1",
6
6
  "@serialport/bindings-interface": "^1.2.2",