incyclist-devices 2.0.3 → 2.0.4

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.
@@ -1,10 +1,11 @@
1
1
  import { Profile } from "incyclist-ant-plus";
2
- import AntAdapter from "./adapter";
2
+ import { DeviceData } from "../types/data";
3
+ import AntAdapter, { BaseDeviceData } from "./adapter";
3
4
  import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "./types";
4
5
  export type AntAdapterInfo = {
5
6
  antProfile: Profile;
6
7
  incyclistProfile: LegacyProfile;
7
- Adapter: typeof AntAdapter;
8
+ Adapter: typeof AntAdapter<BaseDeviceData, DeviceData>;
8
9
  };
9
10
  export type AdapterQuery = {
10
11
  antProfile?: Profile;
@@ -15,7 +16,7 @@ export default class AntAdapterFactory {
15
16
  adapters: AntAdapterInfo[];
16
17
  static getInstance(): AntAdapterFactory;
17
18
  constructor();
18
- register(antProfile: Profile, incyclistProfile: LegacyProfile, Adapter: typeof AntAdapter): void;
19
+ register<TDeviceData extends BaseDeviceData, TData>(antProfile: Profile, incyclistProfile: LegacyProfile, Adapter: typeof AntAdapter<TDeviceData, TData>): void;
19
20
  getAdapter(query?: AdapterQuery): any;
20
21
  createInstance(settings: AntDeviceSettings, props?: AntDeviceProperties): any;
21
22
  createFromDetected(profile: Profile, deviceID: number, props?: AntDeviceProperties): any;
@@ -4,15 +4,19 @@ import AntInterface from './ant-interface';
4
4
  import IncyclistDevice from '../base/adpater';
5
5
  import { AntDeviceProperties, AntDeviceSettings } from './types';
6
6
  import { DeviceProperties } from '../types/device';
7
- import { Bike, IncyclistDeviceAdapter, OnDeviceDataCallback } from '../types/adapter';
7
+ import { Bike, IncyclistDeviceAdapter } from '../types/adapter';
8
8
  import CyclingMode from '../modes/cycling-mode';
9
9
  import { User } from '../types/user';
10
10
  export declare const DEFAULT_UPDATE_FREQUENCY = 1000;
11
- export default class AntAdapter extends IncyclistDevice {
11
+ export type BaseDeviceData = {
12
+ DeviceID: number;
13
+ ManId?: number;
14
+ };
15
+ export default class AntAdapter<TDeviceData extends BaseDeviceData, TData> extends IncyclistDevice {
12
16
  sensor: ISensor;
13
17
  lastUpdate?: number;
14
- data: any;
15
- deviceData: any;
18
+ data: TData;
19
+ deviceData: TDeviceData;
16
20
  updateFrequency: number;
17
21
  channel: IChannel;
18
22
  ant: AntInterface;
@@ -22,7 +26,7 @@ export default class AntAdapter extends IncyclistDevice {
22
26
  bikeSettings: {
23
27
  weight?: number;
24
28
  };
25
- onDataFn: OnDeviceDataCallback;
29
+ onDataFn: (data: TData) => void;
26
30
  startupRetryPause: number;
27
31
  protected ivDataTimeout: NodeJS.Timer;
28
32
  protected lastDataTS: number;
@@ -50,7 +54,7 @@ export default class AntAdapter extends IncyclistDevice {
50
54
  start(props?: AntDeviceProperties): Promise<boolean>;
51
55
  stop(): Promise<boolean>;
52
56
  }
53
- export declare class ControllableAntAdapter extends AntAdapter implements Bike {
57
+ export declare class ControllableAntAdapter<TDeviceData extends BaseDeviceData, TData> extends AntAdapter<TDeviceData, TData> implements Bike {
54
58
  cyclingMode: CyclingMode;
55
59
  user?: User;
56
60
  constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
@@ -2,7 +2,16 @@ import { FitnessEquipmentSensorState, ISensor, Profile } from "incyclist-ant-plu
2
2
  import { ControllableAntAdapter } from "../adapter";
3
3
  import CyclingMode, { IncyclistBikeData, UpdateRequest } from '../../modes/cycling-mode';
4
4
  import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types";
5
- export default class AntFEAdapter extends ControllableAntAdapter {
5
+ type FitnessEquipmentSensorData = {
6
+ speed: number;
7
+ slope: number;
8
+ power: number;
9
+ cadence: number;
10
+ heartrate: number;
11
+ distance: number;
12
+ timestamp: number;
13
+ };
14
+ export default class AntFEAdapter extends ControllableAntAdapter<FitnessEquipmentSensorState, FitnessEquipmentSensorData> {
6
15
  static INCYCLIST_PROFILE_NAME: LegacyProfile;
7
16
  static ANT_PROFILE_NAME: Profile;
8
17
  protected distanceInternal?: number;
@@ -20,9 +29,10 @@ export default class AntFEAdapter extends ControllableAntAdapter {
20
29
  onDeviceData(deviceData: FitnessEquipmentSensorState): void;
21
30
  canSendUpdate(): boolean;
22
31
  mapToCycleModeData(deviceData: FitnessEquipmentSensorState): IncyclistBikeData;
23
- transformData(bikeData: IncyclistBikeData): any;
32
+ transformData(bikeData: IncyclistBikeData): FitnessEquipmentSensorData;
24
33
  start(props?: any): Promise<any>;
25
34
  setFEDefaultTimeout(): void;
26
35
  reconnect(): Promise<boolean>;
27
36
  setCyclingMode(mode: string | CyclingMode, settings?: any): void;
28
37
  }
38
+ export {};
@@ -166,7 +166,7 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
166
166
  }
167
167
  if (bikeData.distanceInternal !== undefined)
168
168
  this.distanceInternal = bikeData.distanceInternal;
169
- let data = {
169
+ const data = {
170
170
  speed: bikeData.speed,
171
171
  slope: bikeData.slope,
172
172
  power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
@@ -180,6 +180,7 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
180
180
  start(props) {
181
181
  return __awaiter(this, void 0, void 0, function* () {
182
182
  const wasPaused = this.paused;
183
+ this.startProps = props || {};
183
184
  if (wasPaused)
184
185
  this.resume();
185
186
  if (this.started && !wasPaused) {
@@ -188,7 +189,6 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
188
189
  const connected = yield this.connect();
189
190
  if (!connected)
190
191
  throw new Error(`could not start device, reason:could not connect`);
191
- this.startProps = props;
192
192
  this.logEvent({ message: 'starting device', props, isStarted: this.started, isReconnecting: this.isReconnecting });
193
193
  const opts = props || {};
194
194
  const { args = {}, user = {} } = opts;
@@ -223,7 +223,9 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
223
223
  }
224
224
  if (this.started && startSuccess === 1) {
225
225
  try {
226
+ console.log('~~~ Device: waiting for data', 'timeout=', timeout || 'unknown');
226
227
  yield this.waitForData(timeout);
228
+ console.log('~~~ Device: data received');
227
229
  }
228
230
  catch (err) {
229
231
  stopTimeoutCheck();
@@ -1,7 +1,10 @@
1
1
  import { HeartRateSensorState, ISensor, Profile } from "incyclist-ant-plus";
2
2
  import AntAdapter from "../adapter";
3
3
  import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types";
4
- export default class AntHrAdapter extends AntAdapter {
4
+ type HeartRateSensorData = {
5
+ heartrate: number;
6
+ };
7
+ export default class AntHrAdapter extends AntAdapter<HeartRateSensorState, HeartRateSensorData> {
5
8
  static INCYCLIST_PROFILE_NAME: LegacyProfile;
6
9
  static ANT_PROFILE_NAME: Profile;
7
10
  constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
@@ -13,3 +16,4 @@ export default class AntHrAdapter extends AntAdapter {
13
16
  mapData(deviceData: HeartRateSensorState): void;
14
17
  hasData(): boolean;
15
18
  }
19
+ export {};
@@ -1,9 +1,16 @@
1
- import { ISensor, Profile } from "incyclist-ant-plus";
1
+ import { BicyclePowerSensorState, ISensor, Profile } from "incyclist-ant-plus";
2
2
  import { ControllableAntAdapter } from "../adapter";
3
3
  import CyclingMode, { IncyclistBikeData } from '../../modes/cycling-mode';
4
4
  import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types";
5
- import { DeviceData } from "../../types/data";
6
- export default class AntPwrAdapter extends ControllableAntAdapter {
5
+ type PowerSensorData = {
6
+ speed: number;
7
+ slope: number;
8
+ power: number;
9
+ cadence: number;
10
+ distance: number;
11
+ timestamp: number;
12
+ };
13
+ export default class AntPwrAdapter extends ControllableAntAdapter<BicyclePowerSensorState, PowerSensorData> {
7
14
  static INCYCLIST_PROFILE_NAME: LegacyProfile;
8
15
  static ANT_PROFILE_NAME: Profile;
9
16
  protected distanceInternal?: number;
@@ -19,6 +26,7 @@ export default class AntPwrAdapter extends ControllableAntAdapter {
19
26
  canSendUpdate(): boolean;
20
27
  sendUpdate(request: any): void;
21
28
  mapData(deviceData: any): IncyclistBikeData;
22
- transformData(bikeData: IncyclistBikeData): DeviceData;
29
+ transformData(bikeData: IncyclistBikeData): PowerSensorData;
23
30
  hasData(): boolean;
24
31
  }
32
+ export {};
@@ -119,7 +119,7 @@ class AntPwrAdapter extends adapter_1.ControllableAntAdapter {
119
119
  }
120
120
  if (bikeData.distanceInternal !== undefined)
121
121
  this.distanceInternal = bikeData.distanceInternal;
122
- let data = {
122
+ const data = {
123
123
  speed: bikeData.speed,
124
124
  slope: bikeData.slope,
125
125
  power: bikeData.power,
@@ -34,6 +34,7 @@ class BleERGCyclingMode extends power_base_1.default {
34
34
  }
35
35
  getBikeInitRequest() {
36
36
  const startPower = Number(this.getSetting('startPower'));
37
+ this.prevRequest = { targetPower: startPower };
37
38
  return { targetPower: startPower };
38
39
  }
39
40
  sendBikeUpdate(request) {
@@ -32,6 +32,7 @@ class FtmsCyclingMode extends power_base_1.default {
32
32
  return config.properties.find(p => p.name === name);
33
33
  }
34
34
  getBikeInitRequest() {
35
+ this.prevRequest = { slope: 0 };
35
36
  return { slope: 0 };
36
37
  }
37
38
  sendBikeUpdate(request) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",