incyclist-devices 1.4.85 → 1.4.87

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.
@@ -13,6 +13,7 @@ exports.BleDevice = void 0;
13
13
  const gd_eventlog_1 = require("gd-eventlog");
14
14
  const ble_1 = require("./ble");
15
15
  const CONNECT_WAIT_TIMEOUT = 10000;
16
+ const BLE_TIMEOUT = 1000;
16
17
  class BleDevice extends ble_1.BleDeviceClass {
17
18
  constructor(props) {
18
19
  super();
@@ -344,7 +345,7 @@ class BleDevice extends ble_1.BleDeviceClass {
344
345
  else {
345
346
  const writeId = this.writeQueue.length;
346
347
  let messageDeleted = false;
347
- this.writeQueue.push({ uuid: characteristicUuid.toLocaleLowerCase(), data, timeout: Date.now() + 2500, resolve, reject });
348
+ this.writeQueue.push({ uuid: characteristicUuid.toLocaleLowerCase(), data, timeout: Date.now() + BLE_TIMEOUT, resolve, reject });
348
349
  const to = setTimeout(() => {
349
350
  if (this.writeQueue.length > writeId && !messageDeleted)
350
351
  this.writeQueue.splice(writeId, 1);
@@ -362,7 +362,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
362
362
  createDevice(DeviceClass, peripheral, characteristics) {
363
363
  try {
364
364
  const C = DeviceClass;
365
- const device = new C({ peripheral, logger: this.logger });
365
+ const device = new C({ peripheral });
366
366
  const cids = characteristics ? characteristics.map(c => (0, ble_1.uuid)(c.uuid)) : [];
367
367
  this.logEvent({ message: 'trying to create device', peripheral: peripheral.address, characteristics: cids, profile: device.getProfile() });
368
368
  const existingDevice = this.devices.find(i => i.device.id === device.id && i.device.getProfile() === device.getProfile());
package/lib/ble/pwr.d.ts CHANGED
@@ -62,7 +62,6 @@ export declare class PwrAdapter extends DeviceAdapter {
62
62
  weight?: number;
63
63
  };
64
64
  constructor(device: BleDeviceClass, protocol: BleProtocol);
65
- select(): void;
66
65
  isBike(): boolean;
67
66
  isHrm(): boolean;
68
67
  isPower(): boolean;
package/lib/ble/pwr.js CHANGED
@@ -173,7 +173,6 @@ class PwrAdapter extends Device_1.default {
173
173
  this.mode = this.getDefaultCyclingMode();
174
174
  this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
175
175
  }
176
- select() { this.selected = true; }
177
176
  isBike() { return true; }
178
177
  isHrm() { return false; }
179
178
  isPower() { return true; }
@@ -37,6 +37,12 @@ export default class WahooAdvancedFitnessMachineDevice extends BleFitnessMachine
37
37
  prevSlope: any;
38
38
  wahooCP: string;
39
39
  isSimMode: boolean;
40
+ weight: number;
41
+ simModeSettings: {
42
+ weight: number;
43
+ crr: number;
44
+ cw: number;
45
+ };
40
46
  constructor(props?: any);
41
47
  isMatching(characteristics: string[]): boolean;
42
48
  init(): Promise<boolean>;
@@ -54,6 +54,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
54
54
  this.timeOffset = 0;
55
55
  this.tsPrevWrite = undefined;
56
56
  this.prevSlope = undefined;
57
+ this.weight = Device_1.DEFAULT_BIKE_WEIGHT + Device_1.DEFAULT_USER_WEIGHT;
57
58
  this.data = {};
58
59
  this.wahooCP = consts_1.WAHOO_ADVANCED_TRAINER_CP;
59
60
  }
@@ -252,6 +253,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
252
253
  this.setPowerAdjusting();
253
254
  this.data.targetPower = power;
254
255
  this.isSimMode = false;
256
+ this.simModeSettings = undefined;
255
257
  }
256
258
  return res;
257
259
  }
@@ -265,12 +267,27 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
265
267
  return __awaiter(this, void 0, void 0, function* () {
266
268
  this.logger.logEvent({ message: 'setSimMode', weight, crr, cw });
267
269
  try {
270
+ if (this.isSimMode && this.simModeSettings) {
271
+ if (weight === this.simModeSettings.weight &&
272
+ crr === this.simModeSettings.crr &&
273
+ cw === this.simModeSettings.cw)
274
+ return true;
275
+ }
276
+ const hasControl = yield this.requestControl();
277
+ if (!hasControl) {
278
+ this.logEvent({ message: 'setSimMode failed', reason: 'control is disabled' });
279
+ return false;
280
+ }
281
+ this.weight = weight;
282
+ this.crr = crr;
283
+ this.cw = cw;
268
284
  const data = Buffer.alloc(6);
269
285
  data.writeInt16LE(Math.round(weight * 100), 0);
270
286
  data.writeInt16LE(Math.round(crr * 10000), 2);
271
287
  data.writeInt16LE(Math.round(cw * 1000), 4);
272
288
  const res = yield this.writeWahooFtmsMessage(67, data);
273
289
  this.isSimMode = true;
290
+ this.simModeSettings = { weight, crr, cw };
274
291
  return res;
275
292
  }
276
293
  catch (err) {
@@ -361,10 +378,9 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
361
378
  if (this.prevSlope !== undefined && slope === this.prevSlope)
362
379
  return;
363
380
  try {
364
- const hasControl = yield this.requestControl();
365
- if (!hasControl) {
366
- this.logEvent({ message: 'setSlope failed', reason: 'control is disabled' });
367
- return false;
381
+ if (!this.isSimMode) {
382
+ const { weight, crr, cw } = this;
383
+ yield this.setSimMode(weight, crr, cw);
368
384
  }
369
385
  const res = yield this.setSimGrade(slope);
370
386
  this.logEvent({ message: 'setSlope result', res });
@@ -380,6 +396,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
380
396
  reset() {
381
397
  this.data = {};
382
398
  this.isSimMode = undefined;
399
+ this.simModeSettings = undefined;
383
400
  }
384
401
  }
385
402
  exports.default = WahooAdvancedFitnessMachineDevice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.4.85",
3
+ "version": "1.4.87",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",