incyclist-devices 3.0.11 → 3.0.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.
@@ -117,7 +117,7 @@ class BleFmAdapter extends adapter_js_1.default {
117
117
  }
118
118
  transformData(bikeData) {
119
119
  if (bikeData === undefined)
120
- return;
120
+ return {};
121
121
  let distance = 0;
122
122
  if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
123
123
  distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
@@ -22,6 +22,8 @@ class BleFitnessMachineDevice extends sensor_js_1.TBleSensor {
22
22
  windSpeed = 0;
23
23
  wheelSize = 2100;
24
24
  ftmsServiceData;
25
+ rowerDataTS;
26
+ rowerMaxPower;
25
27
  constructor(peripheral, props) {
26
28
  super(peripheral, props);
27
29
  this.reset();
@@ -262,6 +264,12 @@ class BleFitnessMachineDevice extends sensor_js_1.TBleSensor {
262
264
  parseRowerData(_data) {
263
265
  const data = Buffer.from(_data);
264
266
  let offset = 2;
267
+ let maxPower;
268
+ if (!this.rowerDataTS || this.rowerDataTS + 1000 < Date.now()) {
269
+ this.rowerDataTS = Date.now();
270
+ maxPower = this.rowerMaxPower;
271
+ delete this.rowerMaxPower;
272
+ }
265
273
  if (data.length > 2) {
266
274
  try {
267
275
  const flags = data.readUInt16LE(0);
@@ -294,12 +302,11 @@ class BleFitnessMachineDevice extends sensor_js_1.TBleSensor {
294
302
  if (flags & 0x0020) {
295
303
  this.data.instantaneousPower = data.readInt16LE(offset);
296
304
  offset += 2;
305
+ this.rowerMaxPower = Math.max(this.rowerMaxPower ?? 0, this.data.instantaneousPower);
297
306
  }
298
307
  if (flags & 0x0040) {
299
308
  this.data.averagePower = data.readInt16LE(offset);
300
309
  offset += 2;
301
- this.data.instantaneousPower = data.readInt16LE(offset);
302
- offset += 2;
303
310
  }
304
311
  if (flags & 0x0080) {
305
312
  this.data.resistanceLevel = data.readInt16LE(offset);
@@ -328,6 +335,8 @@ class BleFitnessMachineDevice extends sensor_js_1.TBleSensor {
328
335
  if (flags & 0x1000) {
329
336
  this.data.remainingTime = data.readUInt16LE(offset);
330
337
  }
338
+ this.logEvent({ message: 'rower data', device: this.getName(), raw: data.toString('hex'), data: structuredClone(this.data), maxPower: this.rowerMaxPower });
339
+ this.data.instantaneousPower = this.rowerMaxPower;
331
340
  }
332
341
  catch (err) {
333
342
  this.logEvent({ message: 'error', fn: 'parseRowerData()', device: this.getName(), data: data.toString('hex'), offset, error: err.message, stack: err.stack });
@@ -465,7 +474,7 @@ class BleFitnessMachineDevice extends sensor_js_1.TBleSensor {
465
474
  return this.ftmsServiceData;
466
475
  try {
467
476
  const peripheral = this.peripheral;
468
- if (!peripheral.getServiceData)
477
+ if (peripheral?.getServiceData === undefined)
469
478
  return;
470
479
  const bitSet = (value, bitNo) => (value & (0, utils_js_1.bit)(bitNo)) > 0;
471
480
  const data = peripheral.getServiceData(consts_js_1.FTMS);
@@ -189,5 +189,8 @@ class Simulator extends adpater_js_1.default {
189
189
  return;
190
190
  return this.getCyclingMode().buildUpdate(request);
191
191
  }
192
+ getSupportedSports() {
193
+ return ['cycling'];
194
+ }
192
195
  }
193
196
  exports.Simulator = Simulator;
@@ -18,5 +18,4 @@ __exportStar(require("./adapter.js"), exports);
18
18
  __exportStar(require("./capabilities.js"), exports);
19
19
  __exportStar(require("./data.js"), exports);
20
20
  __exportStar(require("./device.js"), exports);
21
- __exportStar(require("./interface.js"), exports);
22
21
  __exportStar(require("./user.js"), exports);
@@ -112,7 +112,7 @@ export default class BleFmAdapter extends BleAdapter {
112
112
  }
113
113
  transformData(bikeData) {
114
114
  if (bikeData === undefined)
115
- return;
115
+ return {};
116
116
  let distance = 0;
117
117
  if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
118
118
  distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
@@ -20,6 +20,8 @@ export default class BleFitnessMachineDevice extends TBleSensor {
20
20
  windSpeed = 0;
21
21
  wheelSize = 2100;
22
22
  ftmsServiceData;
23
+ rowerDataTS;
24
+ rowerMaxPower;
23
25
  constructor(peripheral, props) {
24
26
  super(peripheral, props);
25
27
  this.reset();
@@ -260,6 +262,12 @@ export default class BleFitnessMachineDevice extends TBleSensor {
260
262
  parseRowerData(_data) {
261
263
  const data = Buffer.from(_data);
262
264
  let offset = 2;
265
+ let maxPower;
266
+ if (!this.rowerDataTS || this.rowerDataTS + 1000 < Date.now()) {
267
+ this.rowerDataTS = Date.now();
268
+ maxPower = this.rowerMaxPower;
269
+ delete this.rowerMaxPower;
270
+ }
263
271
  if (data.length > 2) {
264
272
  try {
265
273
  const flags = data.readUInt16LE(0);
@@ -292,12 +300,11 @@ export default class BleFitnessMachineDevice extends TBleSensor {
292
300
  if (flags & 0x0020) {
293
301
  this.data.instantaneousPower = data.readInt16LE(offset);
294
302
  offset += 2;
303
+ this.rowerMaxPower = Math.max(this.rowerMaxPower ?? 0, this.data.instantaneousPower);
295
304
  }
296
305
  if (flags & 0x0040) {
297
306
  this.data.averagePower = data.readInt16LE(offset);
298
307
  offset += 2;
299
- this.data.instantaneousPower = data.readInt16LE(offset);
300
- offset += 2;
301
308
  }
302
309
  if (flags & 0x0080) {
303
310
  this.data.resistanceLevel = data.readInt16LE(offset);
@@ -326,6 +333,8 @@ export default class BleFitnessMachineDevice extends TBleSensor {
326
333
  if (flags & 0x1000) {
327
334
  this.data.remainingTime = data.readUInt16LE(offset);
328
335
  }
336
+ this.logEvent({ message: 'rower data', device: this.getName(), raw: data.toString('hex'), data: structuredClone(this.data), maxPower: this.rowerMaxPower });
337
+ this.data.instantaneousPower = this.rowerMaxPower;
329
338
  }
330
339
  catch (err) {
331
340
  this.logEvent({ message: 'error', fn: 'parseRowerData()', device: this.getName(), data: data.toString('hex'), offset, error: err.message, stack: err.stack });
@@ -463,7 +472,7 @@ export default class BleFitnessMachineDevice extends TBleSensor {
463
472
  return this.ftmsServiceData;
464
473
  try {
465
474
  const peripheral = this.peripheral;
466
- if (!peripheral.getServiceData)
475
+ if (peripheral?.getServiceData === undefined)
467
476
  return;
468
477
  const bitSet = (value, bitNo) => (value & bit(bitNo)) > 0;
469
478
  const data = peripheral.getServiceData(FTMS);
@@ -183,4 +183,7 @@ export class Simulator extends IncyclistDevice {
183
183
  return;
184
184
  return this.getCyclingMode().buildUpdate(request);
185
185
  }
186
+ getSupportedSports() {
187
+ return ['cycling'];
188
+ }
186
189
  }
@@ -2,5 +2,4 @@ export * from './adapter.js';
2
2
  export * from './capabilities.js';
3
3
  export * from './data.js';
4
4
  export * from './device.js';
5
- export * from './interface.js';
6
5
  export * from './user.js';
@@ -34,7 +34,7 @@ export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessM
34
34
  protected updateCyclingModeConfig(): void;
35
35
  protected checkCapabilities(): Promise<void>;
36
36
  protected updateCapabilitiesFromFeatures(features: IndoorBikeFeatures): void;
37
- sendUpdate(request: any, enforced?: boolean): Promise<UpdateRequest | void>;
37
+ sendUpdate(request: UpdateRequest, enforced?: boolean): Promise<UpdateRequest | void>;
38
38
  sendInitCommands(): Promise<boolean>;
39
39
  protected getFeatureToggle(): import("../../features/features.js").FeatureToggle;
40
40
  }
@@ -19,6 +19,8 @@ export default class BleFitnessMachineDevice extends TBleSensor {
19
19
  protected windSpeed: number;
20
20
  protected wheelSize: number;
21
21
  protected ftmsServiceData: FtmsServiceData;
22
+ protected rowerDataTS: number | undefined;
23
+ protected rowerMaxPower: number | undefined;
22
24
  constructor(peripheral: IBlePeripheral, props?: any);
23
25
  get features(): IndoorBikeFeatures;
24
26
  reset(): void;
@@ -20,4 +20,6 @@ export * from './direct-connect/index.js';
20
20
  export * from './features/index.js';
21
21
  export * from './proto/zwift_hub.js';
22
22
  export * from './bindings/index.js';
23
+ export type * from './types/index.js';
24
+ export type * from './ble/types.js';
23
25
  export { IAdapter, IncyclistDevice, IncyclistDeviceAdapter, DeviceSettings, DeviceProperties, AdapterFactory, InterfaceFactory, IncyclistInterface, INTERFACE, InterfaceProps, ICyclingMode, IncyclistAdapterData as DeviceData, IncyclistCapability, calc, MockBinding, BleHrMock, DaumClassicMock, DaumClassicSimulator, DaumClassicMockImpl, DaumPremiumMock, DaumPremiumMockImpl, DaumPremiumMockSimulator };
@@ -1,13 +1,14 @@
1
1
  import SimulatorCyclingMode from '../modes/simulator.js';
2
2
  import IncyclistDevice from '../base/adpater.js';
3
- import { IAdapter, IncyclistBikeData, DeviceProperties, DeviceSettings } from '../types/index.js';
3
+ import { IAdapter, IncyclistBikeData, DeviceProperties, DeviceSettings, ITrainer } from '../types/index.js';
4
4
  import { UpdateRequest } from '../modes/types.js';
5
+ import { Sport } from '../types/sport.js';
5
6
  interface SimulatorProperties extends DeviceProperties {
6
7
  isBot?: boolean;
7
8
  settings?: any;
8
9
  activity?: any;
9
10
  }
10
- export declare class Simulator extends IncyclistDevice<SimulatorProperties> {
11
+ export declare class Simulator extends IncyclistDevice<SimulatorProperties> implements ITrainer {
11
12
  static NAME: string;
12
13
  protected static controllers: {
13
14
  modes: (typeof SimulatorCyclingMode)[];
@@ -48,5 +49,6 @@ export declare class Simulator extends IncyclistDevice<SimulatorProperties> {
48
49
  canEmitData(): boolean;
49
50
  calculateDistance(speedKps: any, timeS: any): number;
50
51
  sendUpdate(request: any): Promise<UpdateRequest | void>;
52
+ getSupportedSports(): Array<Sport>;
51
53
  }
52
54
  export {};
@@ -2,5 +2,6 @@ export * from './adapter.js';
2
2
  export * from './capabilities.js';
3
3
  export * from './data.js';
4
4
  export * from './device.js';
5
- export * from './interface.js';
5
+ export type * from './interface.js';
6
6
  export * from './user.js';
7
+ export type * from './sport.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "scripts": {
5
5
  "lint": "eslint . --ext .ts",
6
6
  "build": "npm run build:esm && npm run build:cjs",
@@ -30,14 +30,14 @@
30
30
  "@protobuf-ts/plugin": "^2.11.1",
31
31
  "@serialport/binding-mock": "^10.2.2",
32
32
  "@serialport/bindings-cpp": "^13.0.1",
33
- "@stoprocent/noble": "^2.3.10",
34
- "@types/node": "^25.1.0",
35
- "@typescript-eslint/eslint-plugin": "^8.54.0",
36
- "@typescript-eslint/parser": "^8.54.0",
33
+ "@stoprocent/noble": "^2.4.0",
34
+ "@types/node": "^25.6.0",
35
+ "@typescript-eslint/eslint-plugin": "^8.59.0",
36
+ "@typescript-eslint/parser": "^8.59.0",
37
37
  "@vitest/coverage-v8": "^4.0.18",
38
38
  "bonjour-service": "^1.3.0",
39
- "eslint": "^9.39.2",
40
- "protoc": "^33.4.0",
39
+ "eslint": "^9.39.4",
40
+ "protoc": "^33.6.0",
41
41
  "ts-node": "^10.9.2",
42
42
  "typescript": "^5.9.3",
43
43
  "vitest": "^4.0.18"