incyclist-devices 2.1.0 → 2.1.1
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.
- package/lib/adapters.d.ts +1 -1
- package/lib/antv2/adapter-factory.d.ts +4 -15
- package/lib/antv2/adapter.d.ts +15 -15
- package/lib/antv2/adapter.js +67 -21
- package/lib/antv2/ant-interface.d.ts +3 -11
- package/lib/antv2/ant-interface.js +1 -1
- package/lib/antv2/base/adapter.d.ts +62 -0
- package/lib/antv2/base/adapter.js +360 -0
- package/lib/antv2/base/ant-interface.d.ts +35 -0
- package/lib/antv2/base/ant-interface.js +285 -0
- package/lib/antv2/base/binding.d.ts +13 -0
- package/lib/antv2/base/binding.js +27 -0
- package/lib/antv2/cad/adapter.d.ts +10 -0
- package/lib/antv2/cad/adapter.js +25 -0
- package/lib/antv2/cad/index.d.ts +2 -0
- package/lib/antv2/cad/index.js +7 -0
- package/lib/antv2/consts.d.ts +2 -0
- package/lib/antv2/consts.js +5 -0
- package/lib/antv2/factories/adapter-factory.d.ts +14 -0
- package/lib/antv2/factories/adapter-factory.js +65 -0
- package/lib/antv2/factories/sensor-factory.d.ts +5 -0
- package/lib/antv2/factories/sensor-factory.js +22 -0
- package/lib/antv2/fe/adapter.d.ts +24 -29
- package/lib/antv2/fe/adapter.js +208 -225
- package/lib/antv2/hr/adapter.d.ts +6 -15
- package/lib/antv2/hr/adapter.js +7 -55
- package/lib/antv2/hr copy/adapter.d.ts +11 -0
- package/lib/antv2/hr copy/adapter.js +30 -0
- package/lib/antv2/hr copy/index.d.ts +2 -0
- package/lib/antv2/hr copy/index.js +7 -0
- package/lib/antv2/index.d.ts +5 -4
- package/lib/antv2/index.js +4 -2
- package/lib/antv2/pwr/adapter.d.ts +9 -33
- package/lib/antv2/pwr/adapter.js +19 -140
- package/lib/antv2/types.d.ts +23 -4
- package/lib/base/adpater.d.ts +39 -60
- package/lib/base/adpater.js +139 -161
- package/lib/base/consts.d.ts +4 -0
- package/lib/base/consts.js +9 -0
- package/lib/ble/adapter-factory.d.ts +10 -11
- package/lib/ble/base/adapter.d.ts +7 -14
- package/lib/ble/base/adapter.js +2 -36
- package/lib/ble/ble-interface.d.ts +5 -7
- package/lib/ble/cp/adapter.d.ts +6 -8
- package/lib/ble/cp/adapter.js +8 -27
- package/lib/ble/elite/adapter.d.ts +7 -8
- package/lib/ble/elite/adapter.js +5 -25
- package/lib/ble/fm/adapter.d.ts +6 -7
- package/lib/ble/fm/adapter.js +13 -34
- package/lib/ble/hr/adapter.d.ts +5 -8
- package/lib/ble/hr/adapter.js +2 -2
- package/lib/ble/peripheral-cache.d.ts +2 -3
- package/lib/ble/tacx/adapter.d.ts +2 -3
- package/lib/ble/tacx/adapter.js +8 -8
- package/lib/ble/types.d.ts +1 -2
- package/lib/ble/wahoo/adapter.d.ts +2 -2
- package/lib/ble/wahoo/adapter.js +6 -6
- package/lib/ble/wahoo/comms.js +16 -16
- package/lib/factories/adapters.d.ts +7 -0
- package/lib/factories/adapters.js +49 -0
- package/lib/factories/index.d.ts +3 -0
- package/lib/factories/index.js +10 -0
- package/lib/factories/interfaces.d.ts +7 -0
- package/lib/factories/interfaces.js +27 -0
- package/lib/index.d.ts +5 -6
- package/lib/index.js +4 -9
- package/lib/interfaces.d.ts +1 -1
- package/lib/modes/ant-fe-adv-st-mode.d.ts +1 -1
- package/lib/modes/antble-erg.d.ts +1 -1
- package/lib/modes/antble-smarttrainer.d.ts +2 -2
- package/lib/modes/base.d.ts +5 -5
- package/lib/modes/daum-classic-standard.d.ts +3 -2
- package/lib/modes/daum-erg.d.ts +3 -3
- package/lib/modes/daum-premium-standard.d.ts +3 -2
- package/lib/modes/daum-smarttrainer.d.ts +3 -2
- package/lib/modes/kettler-erg.d.ts +3 -3
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +2 -2
- package/lib/modes/power-meter.d.ts +3 -2
- package/lib/modes/simulator.d.ts +2 -1
- package/lib/modes/types.d.ts +2 -13
- package/lib/serial/SinglePathScanner.d.ts +17 -0
- package/lib/serial/SinglePathScanner.js +87 -0
- package/lib/serial/adapter-factory.d.ts +6 -6
- package/lib/serial/adapter.d.ts +6 -11
- package/lib/serial/base/adapter.d.ts +17 -0
- package/lib/serial/base/adapter.js +67 -0
- package/lib/serial/base/comms.d.ts +62 -0
- package/lib/serial/base/comms.js +280 -0
- package/lib/serial/base/serial-interface.d.ts +36 -0
- package/lib/serial/base/serial-interface.js +288 -0
- package/lib/serial/base/serial-scanner.d.ts +16 -0
- package/lib/serial/base/serial-scanner.js +87 -0
- package/lib/serial/base/serialport.d.ts +17 -0
- package/lib/serial/base/serialport.js +87 -0
- package/lib/serial/comms.d.ts +2 -2
- package/lib/serial/daum/DaumAdapter.d.ts +12 -24
- package/lib/serial/daum/DaumAdapter.js +40 -59
- package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +2 -0
- package/lib/serial/daum/classic/PROTOCOL_NAME.js +5 -0
- package/lib/serial/daum/classic/adapter.d.ts +8 -20
- package/lib/serial/daum/classic/adapter.js +28 -58
- package/lib/serial/daum/classic/comms.d.ts +4 -6
- package/lib/serial/daum/classic/comms.js +2 -2
- package/lib/serial/daum/classic/consts.d.ts +2 -0
- package/lib/serial/daum/classic/consts.js +5 -0
- package/lib/serial/daum/classic/mock.js +4 -3
- package/lib/serial/daum/classic/types.d.ts +8 -10
- package/lib/serial/daum/classic/utils.d.ts +1 -2
- package/lib/serial/daum/consts.d.ts +0 -19
- package/lib/serial/daum/consts.js +0 -22
- package/lib/serial/daum/premium/adapter.d.ts +8 -11
- package/lib/serial/daum/premium/adapter.js +27 -53
- package/lib/serial/daum/premium/comms.d.ts +4 -7
- package/lib/serial/daum/premium/comms.js +23 -22
- package/lib/serial/daum/premium/mock.d.ts +1 -1
- package/lib/serial/daum/premium/mock.js +2 -2
- package/lib/serial/daum/premium/types.d.ts +32 -17
- package/lib/serial/daum/premium/types.js +8 -8
- package/lib/serial/daum/premium/utils.d.ts +2 -3
- package/lib/serial/daum/premium/utils.js +3 -3
- package/lib/serial/daum/types.d.ts +4 -1
- package/lib/serial/daum/types.js +9 -1
- package/lib/serial/factories/adapter-factory.d.ts +14 -0
- package/lib/serial/factories/adapter-factory.js +30 -0
- package/lib/serial/index.d.ts +8 -5
- package/lib/serial/index.js +15 -15
- package/lib/serial/kettler/comms.d.ts +1 -1
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +11 -18
- package/lib/serial/kettler/ergo-racer/adapter.js +9 -21
- package/lib/serial/kettler/types.d.ts +8 -0
- package/lib/serial/kettler/types.js +2 -0
- package/lib/serial/serial-interface.d.ts +2 -32
- package/lib/serial/serial-interface.js +3 -76
- package/lib/serial/serial-scanner.d.ts +16 -0
- package/lib/serial/serial-scanner.js +87 -0
- package/lib/serial/serialport.d.ts +1 -13
- package/lib/serial/types.d.ts +45 -0
- package/lib/serial/types.js +9 -0
- package/lib/simulator/Simulator.d.ts +10 -13
- package/lib/simulator/Simulator.js +11 -23
- package/lib/types/Command.d.ts +8 -0
- package/lib/types/Command.js +2 -0
- package/lib/types/adapter.d.ts +22 -33
- package/lib/types/adapter.js +0 -68
- package/lib/types/command.d.ts +0 -8
- package/lib/types/command.js +0 -2
- package/lib/types/data.d.ts +12 -1
- package/lib/types/device.d.ts +8 -23
- package/lib/types/device.js +9 -8
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.js +22 -0
- package/lib/types/route.d.ts +0 -19
- package/lib/types/route.js +0 -2
- package/lib/types/types.d.ts +8 -0
- package/lib/types/types.js +2 -0
- package/lib/utils/utils.d.ts +1 -0
- package/lib/utils/utils.js +22 -4
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
7
|
+
const types_1 = require("../../types");
|
|
8
|
+
class AntHrAdapter extends adapter_1.default {
|
|
9
|
+
constructor(settings, props) {
|
|
10
|
+
super(settings, props);
|
|
11
|
+
this.capabilities = [types_1.IncyclistCapability.HeartRate];
|
|
12
|
+
}
|
|
13
|
+
getDisplayName() {
|
|
14
|
+
const { ComputedHeartRate } = this.deviceData;
|
|
15
|
+
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
16
|
+
return `${this.getUniqueName()}${hrmStr}`;
|
|
17
|
+
}
|
|
18
|
+
mapToAdapterData(deviceData) {
|
|
19
|
+
if (deviceData.ComputedHeartRate) {
|
|
20
|
+
this.data.heartrate = deviceData.ComputedHeartRate;
|
|
21
|
+
this.data.timestamp = Date.now();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
hasData() {
|
|
25
|
+
return this.deviceData.ComputedHeartRate !== undefined && this.deviceData.ComputedHeartRate !== null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
AntHrAdapter.INCYCLIST_PROFILE_NAME = 'Heartrate Monitor';
|
|
29
|
+
AntHrAdapter.ANT_PROFILE_NAME = 'HR';
|
|
30
|
+
exports.default = AntHrAdapter;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const adapter_1 = __importDefault(require("./adapter"));
|
|
7
|
+
exports.default = adapter_1.default;
|
package/lib/antv2/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import AntPwrAdapter from "./pwr";
|
|
2
2
|
import AntFEAdapter from "./fe";
|
|
3
3
|
import AntHrAdapter from "./hr";
|
|
4
|
-
import AntAdapterFactory from "./adapter-factory";
|
|
5
|
-
import AntInterface
|
|
6
|
-
import {
|
|
7
|
-
export {
|
|
4
|
+
import AntAdapterFactory from "./factories/adapter-factory";
|
|
5
|
+
import AntInterface from "./base/ant-interface";
|
|
6
|
+
import { AntInterfaceProps } from "./types";
|
|
7
|
+
export { AntDeviceSettings, AntDeviceProperties, AntScanProps } from "./types";
|
|
8
|
+
export { AntAdapterFactory, AntFEAdapter, AntHrAdapter, AntPwrAdapter, AntInterface, AntInterfaceProps };
|
package/lib/antv2/index.js
CHANGED
|
@@ -10,11 +10,13 @@ const fe_1 = __importDefault(require("./fe"));
|
|
|
10
10
|
exports.AntFEAdapter = fe_1.default;
|
|
11
11
|
const hr_1 = __importDefault(require("./hr"));
|
|
12
12
|
exports.AntHrAdapter = hr_1.default;
|
|
13
|
-
const
|
|
13
|
+
const cad_1 = __importDefault(require("./cad"));
|
|
14
|
+
const adapter_factory_1 = __importDefault(require("./factories/adapter-factory"));
|
|
14
15
|
exports.AntAdapterFactory = adapter_factory_1.default;
|
|
15
|
-
const ant_interface_1 = __importDefault(require("./ant-interface"));
|
|
16
|
+
const ant_interface_1 = __importDefault(require("./base/ant-interface"));
|
|
16
17
|
exports.AntInterface = ant_interface_1.default;
|
|
17
18
|
const af = adapter_factory_1.default.getInstance();
|
|
18
19
|
af.register('PWR', 'Power Meter', pwr_1.default);
|
|
19
20
|
af.register('HR', 'Heartrate Monitor', hr_1.default);
|
|
20
21
|
af.register('FE', 'Smart Trainer', fe_1.default);
|
|
22
|
+
af.register('CAD', 'Cadence Sensor', cad_1.default);
|
|
@@ -1,37 +1,13 @@
|
|
|
1
|
-
import { BicyclePowerSensorState,
|
|
2
|
-
import AntAdapter from "../adapter";
|
|
3
|
-
import ICyclingMode, { CyclingMode, IncyclistBikeData } from '../../modes/types';
|
|
1
|
+
import { BicyclePowerSensorState, Profile } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "../base/adapter";
|
|
4
3
|
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
cadence: number;
|
|
11
|
-
distance: number;
|
|
12
|
-
timestamp: number;
|
|
13
|
-
};
|
|
14
|
-
export declare class AntPwrControl extends ControllableDevice<AntDeviceProperties> {
|
|
15
|
-
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
16
|
-
getDefaultCyclingMode(): ICyclingMode;
|
|
17
|
-
sendInitCommands(): Promise<boolean>;
|
|
18
|
-
}
|
|
19
|
-
export default class AntPwrAdapter extends AntAdapter<AntPwrControl, BicyclePowerSensorState, PowerSensorData> {
|
|
20
|
-
static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
21
|
-
static ANT_PROFILE_NAME: Profile;
|
|
22
|
-
protected distanceInternal?: number;
|
|
4
|
+
import { ControllerConfig, IncyclistBikeData } from "../../types";
|
|
5
|
+
export default class AntPwrAdapter extends AntAdapter<BicyclePowerSensorState> {
|
|
6
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
7
|
+
protected static ANT_PROFILE_NAME: Profile;
|
|
8
|
+
protected static controllers: ControllerConfig;
|
|
23
9
|
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
getUniqueName(): string;
|
|
27
|
-
getDisplayName(): string;
|
|
28
|
-
getLogData(data: any, excludeList: any): any;
|
|
29
|
-
onDeviceData(deviceData: any): void;
|
|
30
|
-
canSendUpdate(): boolean;
|
|
31
|
-
sendUpdate(request: any): void;
|
|
32
|
-
mapData(deviceData: any): IncyclistBikeData;
|
|
33
|
-
transformData(bikeData: IncyclistBikeData): PowerSensorData;
|
|
10
|
+
mapData(deviceData: BicyclePowerSensorState): IncyclistBikeData;
|
|
11
|
+
transformData(bikeData: IncyclistBikeData): void;
|
|
34
12
|
hasData(): boolean;
|
|
35
|
-
start(props?: any): Promise<any>;
|
|
36
13
|
}
|
|
37
|
-
export {};
|
package/lib/antv2/pwr/adapter.js
CHANGED
|
@@ -1,177 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
|
|
16
|
-
const adapter_1 = __importDefault(require("../adapter"));
|
|
17
|
-
const utils_1 = require("../utils");
|
|
18
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
6
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
19
7
|
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
20
|
-
const
|
|
21
|
-
const capabilities_1 = require("../../types/capabilities");
|
|
22
|
-
const adpater_1 = require("../../base/adpater");
|
|
23
|
-
class AntPwrControl extends adpater_1.ControllableDevice {
|
|
24
|
-
getSupportedCyclingModes() {
|
|
25
|
-
return [power_meter_1.default];
|
|
26
|
-
}
|
|
27
|
-
getDefaultCyclingMode() {
|
|
28
|
-
return new power_meter_1.default(this.adapter);
|
|
29
|
-
}
|
|
30
|
-
sendInitCommands() {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
return false;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.AntPwrControl = AntPwrControl;
|
|
8
|
+
const types_1 = require("../../types");
|
|
37
9
|
class AntPwrAdapter extends adapter_1.default {
|
|
38
10
|
constructor(settings, props) {
|
|
39
|
-
if (settings.protocol && settings.profile !== AntPwrAdapter.INCYCLIST_PROFILE_NAME)
|
|
40
|
-
throw new Error('Incorrect Profile');
|
|
41
|
-
if (!settings.protocol && settings.profile !== AntPwrAdapter.ANT_PROFILE_NAME)
|
|
42
|
-
throw new Error('Incorrect Profile');
|
|
43
11
|
super(settings, props);
|
|
44
|
-
this.setControl(new AntPwrControl(this, props));
|
|
45
|
-
this.deviceData = {
|
|
46
|
-
DeviceID: this.sensor.getDeviceID()
|
|
47
|
-
};
|
|
48
|
-
this.logger = new gd_eventlog_1.EventLogger('Ant+PWR');
|
|
49
12
|
this.capabilities = [
|
|
50
|
-
|
|
13
|
+
types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Cadence, types_1.IncyclistCapability.Speed
|
|
51
14
|
];
|
|
52
15
|
}
|
|
53
|
-
createSensor(settings) {
|
|
54
|
-
return sensor_factory_1.default.create(AntPwrAdapter.ANT_PROFILE_NAME, Number(settings.deviceID));
|
|
55
|
-
}
|
|
56
|
-
getName() {
|
|
57
|
-
if (this.settings.name)
|
|
58
|
-
return this.settings.name;
|
|
59
|
-
const deviceID = this.sensor.getDeviceID();
|
|
60
|
-
return `Ant+PWR ${deviceID}`;
|
|
61
|
-
}
|
|
62
|
-
getUniqueName() {
|
|
63
|
-
if (this.settings.name)
|
|
64
|
-
return this.settings.name;
|
|
65
|
-
const { DeviceID, ManId } = this.deviceData;
|
|
66
|
-
const brand = (0, utils_1.getBrand)(ManId);
|
|
67
|
-
if (brand)
|
|
68
|
-
return `${brand} PWR ${DeviceID}`;
|
|
69
|
-
else
|
|
70
|
-
return `${this.getName()}`;
|
|
71
|
-
}
|
|
72
|
-
getDisplayName() {
|
|
73
|
-
const { Power } = this.deviceData;
|
|
74
|
-
const pwrStr = Power ? ` (${Power})` : '';
|
|
75
|
-
return `${this.getUniqueName()}${pwrStr}`;
|
|
76
|
-
}
|
|
77
|
-
getLogData(data, excludeList) {
|
|
78
|
-
const logData = JSON.parse(JSON.stringify(data));
|
|
79
|
-
excludeList.forEach((key) => {
|
|
80
|
-
delete logData[key];
|
|
81
|
-
});
|
|
82
|
-
return logData;
|
|
83
|
-
}
|
|
84
|
-
onDeviceData(deviceData) {
|
|
85
|
-
this.dataMsgCount++;
|
|
86
|
-
this.lastDataTS = Date.now();
|
|
87
|
-
super.onDeviceData(deviceData);
|
|
88
|
-
if (!this.started)
|
|
89
|
-
return;
|
|
90
|
-
if (!this.ivDataTimeout)
|
|
91
|
-
this.startDataTimeoutCheck();
|
|
92
|
-
try {
|
|
93
|
-
if (!this.canSendUpdate())
|
|
94
|
-
return;
|
|
95
|
-
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
96
|
-
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
97
|
-
let incyclistData = this.mapData(deviceData);
|
|
98
|
-
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
99
|
-
const data = this.transformData(incyclistData);
|
|
100
|
-
this.emitData(data);
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
canSendUpdate() {
|
|
106
|
-
if (!this.hasDataListeners() || this.paused)
|
|
107
|
-
return false;
|
|
108
|
-
return super.canSendUpdate();
|
|
109
|
-
}
|
|
110
|
-
sendUpdate(request) {
|
|
111
|
-
if (this.isPaused())
|
|
112
|
-
return;
|
|
113
|
-
this.getCyclingMode().sendBikeUpdate(request);
|
|
114
|
-
}
|
|
115
16
|
mapData(deviceData) {
|
|
116
17
|
const data = {
|
|
117
18
|
isPedalling: false,
|
|
118
19
|
power: 0,
|
|
119
20
|
pedalRpm: 0,
|
|
120
|
-
speed: 0
|
|
121
|
-
heartrate: 0,
|
|
122
|
-
distanceInternal: 0,
|
|
123
|
-
slope: undefined,
|
|
124
|
-
time: undefined
|
|
21
|
+
speed: 0
|
|
125
22
|
};
|
|
126
|
-
data.slope = (deviceData.Slope !== undefined ? deviceData.Slope : data.slope);
|
|
127
23
|
data.power = (deviceData.Power !== undefined ? deviceData.Power : data.power);
|
|
128
24
|
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
129
25
|
data.time = (deviceData.TimeStamp !== undefined ? deviceData.TimeStamp : data.time);
|
|
130
|
-
|
|
26
|
+
if (deviceData.CalculatedPower !== undefined && deviceData.Power === undefined)
|
|
27
|
+
data.power = deviceData.CalculatedPower;
|
|
28
|
+
if (deviceData.CalculatedCadence !== undefined && deviceData.Cadence === undefined)
|
|
29
|
+
data.pedalRpm = deviceData.CalculatedCadence;
|
|
30
|
+
data.isPedalling = data.pedalRpm > 0 || data.power > 0;
|
|
131
31
|
return data;
|
|
132
32
|
}
|
|
133
33
|
transformData(bikeData) {
|
|
134
|
-
if (bikeData === undefined)
|
|
135
|
-
return;
|
|
136
|
-
let distance = 0;
|
|
137
|
-
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
138
|
-
distance = bikeData.distanceInternal - this.distanceInternal;
|
|
139
|
-
}
|
|
140
|
-
if (bikeData.distanceInternal !== undefined)
|
|
141
|
-
this.distanceInternal = bikeData.distanceInternal;
|
|
142
34
|
const data = {
|
|
143
|
-
speed: bikeData.speed,
|
|
144
|
-
slope: bikeData.slope,
|
|
145
35
|
power: bikeData.power,
|
|
146
36
|
cadence: bikeData.pedalRpm,
|
|
147
|
-
distance,
|
|
148
37
|
timestamp: Date.now()
|
|
149
38
|
};
|
|
150
|
-
|
|
39
|
+
if (bikeData.time)
|
|
40
|
+
data.deviceTime = bikeData.time;
|
|
41
|
+
this.data = data;
|
|
151
42
|
}
|
|
152
43
|
hasData() {
|
|
153
|
-
const { Power,
|
|
154
|
-
const
|
|
44
|
+
const { Power, CalculatedPower, CalculatedCadence, Cadence } = this.deviceData;
|
|
45
|
+
const has = v => (v !== undefined && v !== null);
|
|
46
|
+
const hasData = has(Power) || has(CalculatedPower) || has(Cadence) || has(CalculatedCadence);
|
|
155
47
|
return hasData;
|
|
156
48
|
}
|
|
157
|
-
start(props) {
|
|
158
|
-
const _super = Object.create(null, {
|
|
159
|
-
start: { get: () => super.start }
|
|
160
|
-
});
|
|
161
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const wasPaused = this.paused;
|
|
163
|
-
const wasStopped = this.stopped;
|
|
164
|
-
if (wasPaused)
|
|
165
|
-
this.resume();
|
|
166
|
-
if (wasStopped)
|
|
167
|
-
this.stopped = false;
|
|
168
|
-
if (this.started && !wasPaused && !wasStopped) {
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
return yield _super.start.call(this, props);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
49
|
}
|
|
175
50
|
AntPwrAdapter.INCYCLIST_PROFILE_NAME = 'Power Meter';
|
|
176
51
|
AntPwrAdapter.ANT_PROFILE_NAME = 'PWR';
|
|
52
|
+
AntPwrAdapter.controllers = {
|
|
53
|
+
modes: [power_meter_1.default],
|
|
54
|
+
default: power_meter_1.default
|
|
55
|
+
};
|
|
177
56
|
exports.default = AntPwrAdapter;
|
package/lib/antv2/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Profile } from 'incyclist-ant-plus';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Controllable } from '../types/adapter';
|
|
2
|
+
import { IAdapter, DeviceProperties, DeviceSettings, IncyclistScanProps, InterfaceProps } from '../types';
|
|
3
|
+
import AntAdapter from './base/adapter';
|
|
5
4
|
export interface AntDeviceSettings extends DeviceSettings {
|
|
6
5
|
deviceID?: string;
|
|
7
6
|
profile: Profile | LegacyProfile;
|
|
@@ -9,7 +8,7 @@ export interface AntDeviceSettings extends DeviceSettings {
|
|
|
9
8
|
}
|
|
10
9
|
export type LegacyProfile = 'Heartrate Monitor' | 'Power Meter' | 'Smart Trainer' | 'Speed Sensor' | 'Cadence Sensor' | 'Speed + Cadence Sensor';
|
|
11
10
|
export declare const isLegacyProfile: (o: unknown) => boolean;
|
|
12
|
-
export type DeviceFoundCallback = (device:
|
|
11
|
+
export type DeviceFoundCallback = (device: IAdapter, protocol: string) => void;
|
|
13
12
|
export type ScanFinishedCallback = (id: number) => void;
|
|
14
13
|
export interface AntScanProps extends IncyclistScanProps {
|
|
15
14
|
profiles?: Profile[];
|
|
@@ -21,3 +20,23 @@ export interface AntDeviceProperties extends DeviceProperties {
|
|
|
21
20
|
startupTimeout?: number;
|
|
22
21
|
automaticReconnect?: boolean;
|
|
23
22
|
}
|
|
23
|
+
export type BaseDeviceData = {
|
|
24
|
+
DeviceID: number;
|
|
25
|
+
ManId?: number;
|
|
26
|
+
};
|
|
27
|
+
export type AntAdapterInfo = {
|
|
28
|
+
antProfile: Profile;
|
|
29
|
+
incyclistProfile: LegacyProfile;
|
|
30
|
+
Adapter: typeof AntAdapter<BaseDeviceData>;
|
|
31
|
+
};
|
|
32
|
+
export type AdapterQuery = {
|
|
33
|
+
antProfile?: Profile;
|
|
34
|
+
incyclistProfile?: LegacyProfile;
|
|
35
|
+
};
|
|
36
|
+
export interface AntInterfaceProps extends InterfaceProps {
|
|
37
|
+
startupTimeout?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface ConnectState {
|
|
40
|
+
connected: boolean;
|
|
41
|
+
connecting: boolean;
|
|
42
|
+
}
|
package/lib/base/adpater.d.ts
CHANGED
|
@@ -1,88 +1,67 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import ICyclingMode, { CyclingMode } from "../modes/types";
|
|
3
|
-
import { DeviceProperties, DeviceSettings } from "../types
|
|
4
|
-
import { Controllable, IncyclistDeviceAdapter, OnDeviceDataCallback } from '../types/adapter';
|
|
5
|
-
import { User } from "../types/user";
|
|
6
|
-
import { IncyclistCapability } from "../types/capabilities";
|
|
3
|
+
import { DeviceProperties, DeviceSettings, ControllerConfig, IAdapter, OnDeviceDataCallback, IncyclistCapability, IncyclistAdapterData, User } from "../types";
|
|
7
4
|
import { EventLogger } from "gd-eventlog";
|
|
8
|
-
import { DeviceData } from "../types/data";
|
|
9
5
|
import EventEmitter from "events";
|
|
10
|
-
export
|
|
11
|
-
export declare const DEFAULT_USER_WEIGHT = 75;
|
|
12
|
-
export declare const DEFAULT_PROPS: DeviceProperties;
|
|
13
|
-
export default class IncyclistDevice<B extends Controllable<P>, P extends DeviceProperties> extends EventEmitter implements IncyclistDeviceAdapter {
|
|
6
|
+
export default class IncyclistDevice<P extends DeviceProperties> extends EventEmitter implements IAdapter {
|
|
14
7
|
onDataFn: OnDeviceDataCallback;
|
|
15
8
|
settings: DeviceSettings;
|
|
16
9
|
lastUpdate?: number;
|
|
17
10
|
updateFrequency: number;
|
|
18
11
|
capabilities: IncyclistCapability[];
|
|
19
|
-
protected logger: EventLogger;
|
|
20
12
|
started: boolean;
|
|
21
13
|
stopped: boolean;
|
|
22
14
|
paused: boolean;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
protected props: P;
|
|
16
|
+
protected cyclingMode: ICyclingMode;
|
|
17
|
+
protected logger: EventLogger;
|
|
18
|
+
protected static controllers: ControllerConfig;
|
|
19
|
+
protected user: User;
|
|
20
|
+
protected data: IncyclistAdapterData;
|
|
21
|
+
constructor(settings: DeviceSettings, props?: P);
|
|
30
22
|
getLogger(): EventLogger;
|
|
31
|
-
|
|
23
|
+
logEvent(event: any): void;
|
|
24
|
+
getName(): string;
|
|
25
|
+
getID(): string;
|
|
26
|
+
getUniqueName(): string;
|
|
27
|
+
getDisplayName(): string;
|
|
28
|
+
getSettings(): DeviceSettings;
|
|
29
|
+
isSame(adapter: IAdapter): boolean;
|
|
32
30
|
isEqual(settings: DeviceSettings): boolean;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
addCapability(capability: IncyclistCapability): void;
|
|
36
|
-
update(): void;
|
|
31
|
+
getInterface(): string;
|
|
32
|
+
check(): Promise<boolean>;
|
|
37
33
|
start(props?: DeviceProperties): Promise<boolean>;
|
|
38
34
|
stop(): Promise<boolean>;
|
|
39
35
|
pause(): Promise<boolean>;
|
|
40
36
|
resume(): Promise<boolean>;
|
|
41
|
-
|
|
37
|
+
connect(): Promise<boolean>;
|
|
38
|
+
close(): Promise<boolean>;
|
|
39
|
+
getControllerInfo(): ControllerConfig | undefined;
|
|
40
|
+
isControllable(): boolean;
|
|
41
|
+
getCapabilities(): IncyclistCapability[];
|
|
42
|
+
hasCapability(capability: IncyclistCapability): boolean;
|
|
43
|
+
addCapability(capability: IncyclistCapability): void;
|
|
42
44
|
getMaxUpdateFrequency(): number;
|
|
43
45
|
setMaxUpdateFrequency(value: number): void;
|
|
44
|
-
|
|
45
|
-
getID(): string;
|
|
46
|
-
getDisplayName(): string;
|
|
47
|
-
getName(): string;
|
|
48
|
-
getUniqueName(): string;
|
|
49
|
-
getSettings(): DeviceSettings;
|
|
50
|
-
getInterface(): string;
|
|
51
|
-
onData(callback: OnDeviceDataCallback): void;
|
|
52
|
-
canSendUpdate(): boolean;
|
|
53
|
-
emitData(data: DeviceData): void;
|
|
54
|
-
isStopped(): boolean;
|
|
55
|
-
isStarted(): boolean;
|
|
56
|
-
isPaused(): boolean;
|
|
57
|
-
hasDataListeners(): boolean | OnDeviceDataCallback;
|
|
46
|
+
update(): void;
|
|
58
47
|
setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
|
|
59
|
-
getSupportedCyclingModes():
|
|
48
|
+
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
60
49
|
getCyclingMode(): ICyclingMode;
|
|
61
50
|
getDefaultCyclingMode(): ICyclingMode;
|
|
62
51
|
setBikeProps(props: P): void;
|
|
63
|
-
setUser(user: User): void;
|
|
64
|
-
getUser(): User;
|
|
65
|
-
getWeight(): number;
|
|
66
52
|
sendInitCommands(): Promise<boolean>;
|
|
67
|
-
|
|
68
|
-
export declare class NonControllableDevice<P extends DeviceProperties> extends Controllable<P> {
|
|
69
|
-
isControllable(): boolean;
|
|
70
|
-
setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
|
|
71
|
-
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
72
|
-
getCyclingMode(): ICyclingMode;
|
|
73
|
-
getDefaultCyclingMode(): ICyclingMode;
|
|
74
|
-
setBikeProps(props: DeviceProperties): void;
|
|
53
|
+
sendUpdate(request: any): void;
|
|
75
54
|
setUser(user: User): void;
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
export declare class ControllableDevice<P extends DeviceProperties> extends Controllable<P> {
|
|
79
|
-
protected cyclingMode: ICyclingMode;
|
|
80
|
-
constructor(adapter: IncyclistDeviceAdapter, props?: P);
|
|
81
|
-
isControllable(): boolean;
|
|
82
|
-
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
83
|
-
getDefaultCyclingMode(): ICyclingMode;
|
|
84
|
-
setCyclingMode(mode: ICyclingMode | string, settings?: any): void;
|
|
85
|
-
sendInitCommands(): Promise<boolean>;
|
|
86
|
-
getCyclingMode(): ICyclingMode;
|
|
55
|
+
getUser(): User;
|
|
87
56
|
getWeight(): number;
|
|
57
|
+
isUpdateWithinFrequency(): boolean;
|
|
58
|
+
canEmitData(): boolean;
|
|
59
|
+
emitData(data: IncyclistAdapterData): void;
|
|
60
|
+
isStopped(): boolean;
|
|
61
|
+
isStarted(): boolean;
|
|
62
|
+
isPaused(): boolean;
|
|
63
|
+
getData(): IncyclistAdapterData;
|
|
64
|
+
hasDataListeners(): boolean | OnDeviceDataCallback;
|
|
65
|
+
onData(callback: OnDeviceDataCallback): void;
|
|
88
66
|
}
|
|
67
|
+
export type IncyclistDeviceAdapter = IncyclistDevice<DeviceProperties>;
|