incyclist-devices 2.0.37 → 2.1.0
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/antv2/adapter-factory.d.ts +4 -2
- package/lib/antv2/adapter.d.ts +3 -20
- package/lib/antv2/adapter.js +7 -93
- package/lib/antv2/fe/adapter.d.ts +9 -5
- package/lib/antv2/fe/adapter.js +25 -14
- package/lib/antv2/hr/adapter.d.ts +2 -1
- package/lib/antv2/pwr/adapter.d.ts +9 -5
- package/lib/antv2/pwr/adapter.js +19 -8
- package/lib/antv2/types.d.ts +2 -1
- package/lib/base/adpater.d.ts +31 -13
- package/lib/base/adpater.js +84 -28
- package/lib/ble/adapter-factory.d.ts +10 -9
- package/lib/ble/base/adapter.d.ts +9 -20
- package/lib/ble/base/adapter.js +15 -72
- package/lib/ble/ble-interface.d.ts +5 -4
- package/lib/ble/cp/adapter.d.ts +5 -8
- package/lib/ble/cp/adapter.js +26 -10
- package/lib/ble/elite/adapter.d.ts +6 -5
- package/lib/ble/elite/adapter.js +26 -2
- package/lib/ble/fm/adapter.d.ts +10 -9
- package/lib/ble/fm/adapter.js +38 -11
- package/lib/ble/hr/adapter.d.ts +5 -3
- package/lib/ble/peripheral-cache.d.ts +3 -2
- package/lib/ble/tacx/adapter.d.ts +2 -2
- package/lib/ble/wahoo/adapter.d.ts +2 -2
- package/lib/index.d.ts +5 -5
- package/lib/index.js +4 -2
- package/lib/interfaces.d.ts +1 -1
- package/lib/modes/ant-fe-adv-st-mode.d.ts +12 -0
- package/lib/modes/ant-fe-adv-st-mode.js +83 -0
- package/lib/modes/antble-erg.d.ts +31 -0
- package/lib/modes/antble-erg.js +28 -0
- package/lib/modes/antble-smarttrainer.d.ts +23 -0
- package/lib/modes/antble-smarttrainer.js +65 -0
- package/lib/modes/base.d.ts +29 -0
- package/lib/modes/{cycling-mode.js → base.js} +23 -26
- package/lib/modes/daum-classic-standard.d.ts +16 -0
- package/lib/modes/daum-classic-standard.js +54 -0
- package/lib/modes/daum-erg.d.ts +49 -0
- package/lib/{serial/daum/ERGCyclingMode.js → modes/daum-erg.js} +45 -73
- package/lib/modes/daum-power.d.ts +5 -0
- package/lib/{serial/daum/DaumPowerMeterCyclingMode.js → modes/daum-power.js} +1 -10
- package/lib/modes/daum-premium-standard.d.ts +23 -0
- package/lib/{serial/daum/premium/modes/daum-classic.js → modes/daum-premium-standard.js} +26 -38
- package/lib/modes/daum-smarttrainer.d.ts +82 -0
- package/lib/{serial/daum/SmartTrainerCyclingMode.js → modes/daum-smarttrainer.js} +23 -26
- package/lib/modes/kettler-erg.d.ts +44 -0
- package/lib/{serial/kettler/ergo-racer/modes/erg.js → modes/kettler-erg.js} +12 -23
- package/lib/modes/power-base.d.ts +28 -3
- package/lib/modes/power-base.js +182 -5
- package/lib/modes/power-meter.d.ts +10 -16
- package/lib/modes/power-meter.js +15 -54
- package/lib/modes/simulator.d.ts +37 -10
- package/lib/modes/simulator.js +14 -46
- package/lib/modes/{cycling-mode.d.ts → types.d.ts} +22 -19
- package/lib/modes/types.js +56 -0
- package/lib/serial/adapter-factory.d.ts +7 -5
- package/lib/serial/adapter.d.ts +2 -2
- package/lib/serial/adapter.js +5 -2
- package/lib/serial/daum/DaumAdapter.d.ts +27 -24
- package/lib/serial/daum/DaumAdapter.js +200 -128
- package/lib/serial/daum/classic/adapter.d.ts +20 -21
- package/lib/serial/daum/classic/adapter.js +83 -157
- package/lib/serial/daum/classic/comms.d.ts +19 -13
- package/lib/serial/daum/classic/comms.js +39 -12
- package/lib/serial/daum/classic/mock.d.ts +4 -0
- package/lib/serial/daum/classic/mock.js +14 -4
- package/lib/serial/daum/premium/adapter.d.ts +16 -11
- package/lib/serial/daum/premium/adapter.js +98 -95
- package/lib/serial/daum/premium/comms.d.ts +4 -1
- package/lib/serial/daum/premium/comms.js +25 -17
- package/lib/serial/daum/premium/mock.d.ts +4 -0
- package/lib/serial/daum/premium/mock.js +15 -5
- package/lib/serial/daum/types.d.ts +11 -0
- package/lib/serial/daum/types.js +5 -0
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +10 -8
- package/lib/serial/kettler/ergo-racer/adapter.js +17 -7
- package/lib/serial/serial-interface.js +1 -2
- package/lib/simulator/Simulator.d.ts +14 -17
- package/lib/simulator/Simulator.js +18 -47
- package/lib/types/adapter.d.ts +29 -8
- package/lib/types/adapter.js +68 -0
- package/lib/utils/utils.d.ts +1 -1
- package/package.json +3 -3
- package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +0 -9
- package/lib/antv2/modes/ant-fe-adv-st-mode.js +0 -51
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +0 -6
- package/lib/antv2/modes/ant-fe-erg-mode.js +0 -14
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +0 -5
- package/lib/antv2/modes/ant-fe-st-mode.js +0 -13
- package/lib/modes/ble-erg-mode.d.ts +0 -18
- package/lib/modes/ble-erg-mode.js +0 -148
- package/lib/modes/ble-st-mode.d.ts +0 -15
- package/lib/modes/ble-st-mode.js +0 -96
- package/lib/serial/daum/DaumPowerMeterCyclingMode.d.ts +0 -8
- package/lib/serial/daum/ERGCyclingMode.d.ts +0 -26
- package/lib/serial/daum/SmartTrainerCyclingMode.d.ts +0 -42
- package/lib/serial/daum/classic/modes/daum-classic.d.ts +0 -13
- package/lib/serial/daum/classic/modes/daum-classic.js +0 -97
- package/lib/serial/daum/premium/modes/daum-classic.d.ts +0 -14
- package/lib/serial/kettler/ergo-racer/modes/erg.d.ts +0 -25
- /package/lib/serial/daum/{constants.d.ts → consts.d.ts} +0 -0
- /package/lib/serial/daum/{constants.js → consts.js} +0 -0
package/lib/base/adpater.js
CHANGED
|
@@ -12,7 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ControllableDevice = exports.DEFAULT_PROPS = exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_BIKE_WEIGHT = void 0;
|
|
15
|
+
exports.ControllableDevice = exports.NonControllableDevice = exports.DEFAULT_PROPS = exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_BIKE_WEIGHT = void 0;
|
|
16
|
+
const adapter_1 = require("../types/adapter");
|
|
16
17
|
const events_1 = __importDefault(require("events"));
|
|
17
18
|
exports.DEFAULT_BIKE_WEIGHT = 10;
|
|
18
19
|
exports.DEFAULT_USER_WEIGHT = 75;
|
|
@@ -30,13 +31,18 @@ class IncyclistDevice extends events_1.default {
|
|
|
30
31
|
this.started = false;
|
|
31
32
|
this.stopped = false;
|
|
32
33
|
this.paused = false;
|
|
34
|
+
this.bikeControl = new NonControllableDevice(this, props);
|
|
35
|
+
}
|
|
36
|
+
setControl(control) {
|
|
37
|
+
this.bikeControl = control;
|
|
33
38
|
}
|
|
34
39
|
connect() { throw new Error('not implemented'); }
|
|
35
40
|
close() { throw new Error('not implemented'); }
|
|
36
41
|
check() { throw new Error("Method not implemented."); }
|
|
37
|
-
getLogger() { return
|
|
42
|
+
getLogger() { return this.logger; }
|
|
38
43
|
isControllable() {
|
|
39
|
-
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = this.bikeControl) === null || _a === void 0 ? void 0 : _a.isControllable();
|
|
40
46
|
}
|
|
41
47
|
isEqual(settings) { throw new Error("Method not implemented."); }
|
|
42
48
|
getCapabilities() { return this.capabilities; }
|
|
@@ -124,46 +130,96 @@ class IncyclistDevice extends events_1.default {
|
|
|
124
130
|
hasDataListeners() {
|
|
125
131
|
return this.onDataFn || this.listenerCount('data') > 0;
|
|
126
132
|
}
|
|
133
|
+
setCyclingMode(mode, settings, sendInitCommands) {
|
|
134
|
+
var _a;
|
|
135
|
+
if (this.isControllable())
|
|
136
|
+
(_a = this.bikeControl) === null || _a === void 0 ? void 0 : _a.setCyclingMode(mode, settings, sendInitCommands);
|
|
137
|
+
}
|
|
138
|
+
getSupportedCyclingModes() {
|
|
139
|
+
var _a;
|
|
140
|
+
if (!this.isControllable())
|
|
141
|
+
return [];
|
|
142
|
+
return (_a = this.bikeControl) === null || _a === void 0 ? void 0 : _a.getSupportedCyclingModes();
|
|
143
|
+
}
|
|
144
|
+
getCyclingMode() {
|
|
145
|
+
if (this.isControllable())
|
|
146
|
+
return this.bikeControl.getCyclingMode();
|
|
147
|
+
}
|
|
148
|
+
getDefaultCyclingMode() {
|
|
149
|
+
if (this.isControllable())
|
|
150
|
+
return this.bikeControl.getDefaultCyclingMode();
|
|
151
|
+
}
|
|
152
|
+
setBikeProps(props) {
|
|
153
|
+
if (this.isControllable())
|
|
154
|
+
this.bikeControl.setBikeProps(props);
|
|
155
|
+
}
|
|
156
|
+
setUser(user) {
|
|
157
|
+
if (this.isControllable())
|
|
158
|
+
this.bikeControl.setUser(user);
|
|
159
|
+
}
|
|
160
|
+
getUser() {
|
|
161
|
+
var _a;
|
|
162
|
+
return ((_a = this.bikeControl) === null || _a === void 0 ? void 0 : _a.getUser()) || {};
|
|
163
|
+
}
|
|
164
|
+
getWeight() {
|
|
165
|
+
var _a;
|
|
166
|
+
return (_a = this.bikeControl) === null || _a === void 0 ? void 0 : _a.getWeight();
|
|
167
|
+
}
|
|
168
|
+
sendInitCommands() {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
if (this.isControllable())
|
|
171
|
+
return yield this.bikeControl.sendInitCommands();
|
|
172
|
+
return false;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
127
175
|
}
|
|
128
176
|
exports.default = IncyclistDevice;
|
|
129
|
-
class
|
|
130
|
-
constructor(settings, props) {
|
|
131
|
-
super(settings, props);
|
|
132
|
-
this.cyclingMode = this.getDefaultCyclingMode();
|
|
133
|
-
this.user = {};
|
|
134
|
-
}
|
|
177
|
+
class NonControllableDevice extends adapter_1.Controllable {
|
|
135
178
|
isControllable() {
|
|
136
|
-
return
|
|
179
|
+
return false;
|
|
137
180
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
181
|
+
setCyclingMode(mode, settings, sendInitCommands) {
|
|
182
|
+
throw new Error("Method not implemented.");
|
|
183
|
+
}
|
|
184
|
+
getSupportedCyclingModes() {
|
|
185
|
+
throw new Error("Method not implemented.");
|
|
186
|
+
}
|
|
187
|
+
getCyclingMode() {
|
|
188
|
+
throw new Error("Method not implemented.");
|
|
189
|
+
}
|
|
190
|
+
getDefaultCyclingMode() {
|
|
191
|
+
throw new Error("Method not implemented.");
|
|
142
192
|
}
|
|
143
193
|
setBikeProps(props) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (p === null)
|
|
153
|
-
delete this.props[k];
|
|
154
|
-
else if (p !== undefined)
|
|
155
|
-
this.props[k] = p;
|
|
194
|
+
throw new Error("Method not implemented.");
|
|
195
|
+
}
|
|
196
|
+
setUser(user) {
|
|
197
|
+
throw new Error("Method not implemented.");
|
|
198
|
+
}
|
|
199
|
+
sendInitCommands() {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
return false;
|
|
156
202
|
});
|
|
157
203
|
}
|
|
204
|
+
}
|
|
205
|
+
exports.NonControllableDevice = NonControllableDevice;
|
|
206
|
+
class ControllableDevice extends adapter_1.Controllable {
|
|
207
|
+
constructor(adapter, props) {
|
|
208
|
+
super(adapter, props);
|
|
209
|
+
this.cyclingMode = this.getDefaultCyclingMode();
|
|
210
|
+
}
|
|
211
|
+
isControllable() {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
158
214
|
getSupportedCyclingModes() { throw new Error('not implemented'); }
|
|
159
215
|
getDefaultCyclingMode() { throw new Error('not implemented'); }
|
|
160
216
|
setCyclingMode(mode, settings) {
|
|
161
217
|
let selectedMode;
|
|
162
218
|
if (typeof mode === 'string') {
|
|
163
219
|
const supported = this.getSupportedCyclingModes();
|
|
164
|
-
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
220
|
+
const CyclingModeClass = supported.find(M => { const m = new M(this.adapter); return m.getName() === mode; });
|
|
165
221
|
if (CyclingModeClass) {
|
|
166
|
-
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
222
|
+
this.cyclingMode = new CyclingModeClass(this.adapter, settings);
|
|
167
223
|
return;
|
|
168
224
|
}
|
|
169
225
|
selectedMode = this.getDefaultCyclingMode();
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import { DeviceProperties } from "../types/device";
|
|
2
2
|
import BleAdapter from "./base/adapter";
|
|
3
|
-
import { BleDeviceSettings, BleProtocol } from "./types";
|
|
3
|
+
import { BleDeviceProperties, BleDeviceSettings, BleProtocol } from "./types";
|
|
4
4
|
import { BleComms } from "./base/comms";
|
|
5
|
+
import { Controllable } from "../types/adapter";
|
|
5
6
|
export interface BleAdapterInfo {
|
|
6
7
|
protocol: BleProtocol;
|
|
7
|
-
Adapter: typeof BleAdapter
|
|
8
|
+
Adapter: typeof BleAdapter<Controllable<BleDeviceProperties>>;
|
|
8
9
|
Comm: typeof BleComms;
|
|
9
10
|
}
|
|
10
11
|
export default class BleAdapterFactory {
|
|
11
12
|
static _instance: BleAdapterFactory;
|
|
12
13
|
implementations: BleAdapterInfo[];
|
|
13
|
-
instances: BleAdapter
|
|
14
|
+
instances: Array<BleAdapter<Controllable<BleDeviceProperties>>>;
|
|
14
15
|
static getInstance(): BleAdapterFactory;
|
|
15
16
|
constructor();
|
|
16
17
|
getAdapterInfo(protocol: BleProtocol): BleAdapterInfo;
|
|
17
18
|
getAll(): BleAdapterInfo[];
|
|
18
|
-
createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter
|
|
19
|
+
createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter<Controllable<BleDeviceProperties>>;
|
|
19
20
|
removeInstance(query: {
|
|
20
21
|
settings?: BleDeviceSettings;
|
|
21
|
-
adapter?: BleAdapter
|
|
22
|
+
adapter?: BleAdapter<Controllable<DeviceProperties>>;
|
|
22
23
|
}): void;
|
|
23
|
-
find(settings?: BleDeviceSettings): BleAdapter
|
|
24
|
-
register(protocol: BleProtocol, Adapter: typeof BleAdapter
|
|
25
|
-
getAllInstances(): BleAdapter
|
|
24
|
+
find(settings?: BleDeviceSettings): BleAdapter<Controllable<BleDeviceProperties>>;
|
|
25
|
+
register(protocol: BleProtocol, Adapter: typeof BleAdapter<Controllable<BleDeviceProperties>>, Comm: typeof BleComms): void;
|
|
26
|
+
getAllInstances(): Array<BleAdapter<Controllable<DeviceProperties>>>;
|
|
26
27
|
getAllSupportedComms(): (typeof BleComms)[];
|
|
27
|
-
getAllSupportedAdapters(): (typeof BleAdapter)
|
|
28
|
+
getAllSupportedAdapters(): Array<(typeof BleAdapter<Controllable<BleDeviceProperties>>)>;
|
|
28
29
|
getAllSupportedServices(): string[];
|
|
29
30
|
getDeviceClasses(peripheral: any, props?: {
|
|
30
31
|
protocol?: BleProtocol;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import IncyclistDevice from "../../base/adpater";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import IncyclistDevice, { ControllableDevice } from "../../base/adpater";
|
|
2
|
+
import ICyclingMode, { IncyclistBikeData } from "../../modes/types";
|
|
3
|
+
import { Controllable, IncyclistDeviceAdapter } from "../../types/adapter";
|
|
4
4
|
import { DeviceData } from "../../types/data";
|
|
5
5
|
import { DeviceProperties } from "../../types/device";
|
|
6
|
-
import { User } from "../../types/user";
|
|
7
6
|
import { BleComms } from "./comms";
|
|
8
7
|
import BleInterface from "../ble-interface";
|
|
9
8
|
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from "../types";
|
|
10
|
-
export
|
|
9
|
+
export declare class BlePowerControl extends ControllableDevice<BleDeviceProperties> {
|
|
10
|
+
getDefaultCyclingMode(): ICyclingMode;
|
|
11
|
+
getSupportedCyclingModes(): any[];
|
|
12
|
+
}
|
|
13
|
+
export default class BleAdapter<DC extends Controllable<BleDeviceProperties>> extends IncyclistDevice<DC, BleDeviceProperties> {
|
|
11
14
|
ble: BleInterface;
|
|
12
15
|
deviceData: any;
|
|
13
16
|
data: DeviceData;
|
|
@@ -20,7 +23,7 @@ export default class BleAdapter extends IncyclistDevice {
|
|
|
20
23
|
close(): Promise<boolean>;
|
|
21
24
|
getComms(): BleComms;
|
|
22
25
|
isEqual(settings: BleDeviceSettings): boolean;
|
|
23
|
-
isSame(adapter:
|
|
26
|
+
isSame(adapter: IncyclistDeviceAdapter): boolean;
|
|
24
27
|
isConnected(): boolean;
|
|
25
28
|
resetData(): void;
|
|
26
29
|
getInterface(): string;
|
|
@@ -38,17 +41,3 @@ export default class BleAdapter extends IncyclistDevice {
|
|
|
38
41
|
pause(): Promise<boolean>;
|
|
39
42
|
resume(): Promise<boolean>;
|
|
40
43
|
}
|
|
41
|
-
export declare class BleControllableAdapter extends BleAdapter implements Bike {
|
|
42
|
-
cyclingMode: CyclingMode;
|
|
43
|
-
user?: User;
|
|
44
|
-
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
45
|
-
setUser(user: User): void;
|
|
46
|
-
isControllable(): boolean;
|
|
47
|
-
setBikeProps(props: DeviceProperties): void;
|
|
48
|
-
getWeight(): number;
|
|
49
|
-
getSupportedCyclingModes(): any[];
|
|
50
|
-
getDefaultCyclingMode(): CyclingMode;
|
|
51
|
-
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
52
|
-
sendInitCommands(): Promise<boolean>;
|
|
53
|
-
getCyclingMode(): CyclingMode;
|
|
54
|
-
}
|
package/lib/ble/base/adapter.js
CHANGED
|
@@ -35,10 +35,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.
|
|
38
|
+
exports.BlePowerControl = void 0;
|
|
39
39
|
const adpater_1 = __importStar(require("../../base/adpater"));
|
|
40
40
|
const ble_interface_1 = __importDefault(require("../ble-interface"));
|
|
41
|
+
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
41
42
|
const INTERFACE_NAME = 'ble';
|
|
43
|
+
class BlePowerControl extends adpater_1.ControllableDevice {
|
|
44
|
+
getDefaultCyclingMode() {
|
|
45
|
+
return new power_meter_1.default(this.adapter);
|
|
46
|
+
}
|
|
47
|
+
getSupportedCyclingModes() {
|
|
48
|
+
return [power_meter_1.default];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.BlePowerControl = BlePowerControl;
|
|
42
52
|
class BleAdapter extends adpater_1.default {
|
|
43
53
|
constructor(settings, props) {
|
|
44
54
|
super(settings, props);
|
|
@@ -136,8 +146,8 @@ class BleAdapter extends adpater_1.default {
|
|
|
136
146
|
this.deviceData = Object.assign({}, deviceData);
|
|
137
147
|
if (!this.started || !this.canSendUpdate())
|
|
138
148
|
return;
|
|
139
|
-
this.logEvent({ message: 'onDeviceData', data: deviceData, isControllable: (
|
|
140
|
-
if (this
|
|
149
|
+
this.logEvent({ message: 'onDeviceData', data: deviceData, isControllable: this.isControllable() });
|
|
150
|
+
if (this.isControllable()) {
|
|
141
151
|
const mappedData = this.mapData(deviceData);
|
|
142
152
|
const incyclistData = this.getCyclingMode().updateData(mappedData);
|
|
143
153
|
this.data = this.transformData(incyclistData);
|
|
@@ -168,10 +178,9 @@ class BleAdapter extends adpater_1.default {
|
|
|
168
178
|
const wasStopped = this.stopped;
|
|
169
179
|
if (wasPaused)
|
|
170
180
|
this.resume();
|
|
171
|
-
if (wasStopped)
|
|
172
|
-
this.stopped = false;
|
|
173
|
-
if (this.started && !wasPaused && !wasStopped)
|
|
181
|
+
if (this.started && !wasStopped)
|
|
174
182
|
return true;
|
|
183
|
+
this.stopped = false;
|
|
175
184
|
const connected = yield this.connect();
|
|
176
185
|
if (!connected)
|
|
177
186
|
throw new Error(`could not start device, reason:could not connect`);
|
|
@@ -233,69 +242,3 @@ class BleAdapter extends adpater_1.default {
|
|
|
233
242
|
}
|
|
234
243
|
}
|
|
235
244
|
exports.default = BleAdapter;
|
|
236
|
-
class BleControllableAdapter extends BleAdapter {
|
|
237
|
-
constructor(settings, props) {
|
|
238
|
-
super(settings, props);
|
|
239
|
-
this.cyclingMode = this.getDefaultCyclingMode();
|
|
240
|
-
this.user = {};
|
|
241
|
-
}
|
|
242
|
-
setUser(user) {
|
|
243
|
-
this.user = user;
|
|
244
|
-
if (!user.weight)
|
|
245
|
-
this.user.weight = adpater_1.DEFAULT_USER_WEIGHT;
|
|
246
|
-
}
|
|
247
|
-
isControllable() {
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
setBikeProps(props) {
|
|
251
|
-
const { user, userWeight } = props || {};
|
|
252
|
-
if (user)
|
|
253
|
-
this.setUser(user);
|
|
254
|
-
if (userWeight)
|
|
255
|
-
this.user.weight = userWeight;
|
|
256
|
-
const keys = Object.keys(props);
|
|
257
|
-
keys.forEach(k => {
|
|
258
|
-
const p = props[k];
|
|
259
|
-
if (p === null)
|
|
260
|
-
delete this.props[k];
|
|
261
|
-
else if (p !== undefined)
|
|
262
|
-
this.props[k] = p;
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
getWeight() {
|
|
266
|
-
const { user = {}, props = adpater_1.DEFAULT_PROPS } = this;
|
|
267
|
-
const userWeight = user.weight || props.userWeight || adpater_1.DEFAULT_USER_WEIGHT;
|
|
268
|
-
const bikeWeight = props.bikeWeight || adpater_1.DEFAULT_BIKE_WEIGHT;
|
|
269
|
-
return userWeight + bikeWeight;
|
|
270
|
-
}
|
|
271
|
-
getSupportedCyclingModes() { throw new Error('not implemented'); }
|
|
272
|
-
getDefaultCyclingMode() { throw new Error('not implemented'); }
|
|
273
|
-
setCyclingMode(mode, settings) {
|
|
274
|
-
let selectedMode;
|
|
275
|
-
if (typeof mode === 'string') {
|
|
276
|
-
const supported = this.getSupportedCyclingModes();
|
|
277
|
-
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
278
|
-
if (CyclingModeClass) {
|
|
279
|
-
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
selectedMode = this.getDefaultCyclingMode();
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
selectedMode = mode;
|
|
286
|
-
}
|
|
287
|
-
this.cyclingMode = selectedMode;
|
|
288
|
-
this.cyclingMode.setSettings(settings);
|
|
289
|
-
}
|
|
290
|
-
sendInitCommands() {
|
|
291
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
return true;
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
getCyclingMode() {
|
|
296
|
-
if (!this.cyclingMode)
|
|
297
|
-
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
298
|
-
return this.cyclingMode;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
exports.BleControllableAdapter = BleControllableAdapter;
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { EventLogger } from 'gd-eventlog';
|
|
4
4
|
import BleAdapterFactory from './adapter-factory';
|
|
5
|
-
import { BleInterfaceProps, BlePeripheral, BleDeviceSettings, BleProtocol, BleBinding, BleInterfaceState, BleScanProps, BleCharacteristic } from './types';
|
|
5
|
+
import { BleInterfaceProps, BlePeripheral, BleDeviceSettings, BleProtocol, BleBinding, BleInterfaceState, BleScanProps, BleCharacteristic, BleDeviceProperties } from './types';
|
|
6
6
|
import { BleComms } from './base/comms';
|
|
7
7
|
import { IncyclistInterface } from '../types/interface';
|
|
8
8
|
import BleAdapter from './base/adapter';
|
|
9
9
|
import { IncyclistScanProps } from '../types/device';
|
|
10
10
|
import BlePeripheralCache from './peripheral-cache';
|
|
11
11
|
import EventEmitter from 'events';
|
|
12
|
+
import { Controllable } from '..';
|
|
12
13
|
export interface ScanState {
|
|
13
14
|
isScanning: boolean;
|
|
14
15
|
isConnecting: boolean;
|
|
@@ -40,7 +41,7 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
|
|
|
40
41
|
logger: EventLogger;
|
|
41
42
|
props: BleInterfaceProps;
|
|
42
43
|
binding: BleBinding;
|
|
43
|
-
connectedDevices: BleAdapter
|
|
44
|
+
connectedDevices: Array<BleAdapter<Controllable<BleDeviceProperties>>>;
|
|
44
45
|
sensorIsConnecting: boolean;
|
|
45
46
|
emittingAdapters: {
|
|
46
47
|
comms: BleComms;
|
|
@@ -79,6 +80,6 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
|
|
|
79
80
|
scan(props?: BleScanProps): Promise<BleDeviceSettings[]>;
|
|
80
81
|
stopScan(): Promise<boolean>;
|
|
81
82
|
isScanning(): boolean;
|
|
82
|
-
addConnectedDevice(device: BleAdapter): void;
|
|
83
|
-
removeConnectedDevice(device: BleAdapter): void;
|
|
83
|
+
addConnectedDevice(device: BleAdapter<Controllable<BleDeviceProperties>>): void;
|
|
84
|
+
removeConnectedDevice(device: BleAdapter<Controllable<BleDeviceProperties>>): void;
|
|
84
85
|
}
|
package/lib/ble/cp/adapter.d.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { BleControllableAdapter } from '../base/adapter';
|
|
1
|
+
import { IncyclistBikeData } from '../../modes/types';
|
|
2
|
+
import BleAdapter, { BlePowerControl } from '../base/adapter';
|
|
4
3
|
import { DeviceProperties } from '../../types/device';
|
|
5
4
|
import { PowerData } from './types';
|
|
6
5
|
import { DeviceData } from '../../types/data';
|
|
7
6
|
import { BleDeviceSettings } from '../types';
|
|
8
|
-
import
|
|
9
|
-
export default class PwrAdapter extends
|
|
7
|
+
import { IncyclistDeviceAdapter } from '../../types/adapter';
|
|
8
|
+
export default class PwrAdapter extends BleAdapter<BlePowerControl> {
|
|
10
9
|
distanceInternal: number;
|
|
11
10
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
12
|
-
isSame(device:
|
|
11
|
+
isSame(device: IncyclistDeviceAdapter): boolean;
|
|
13
12
|
getProfile(): string;
|
|
14
13
|
getName(): string;
|
|
15
14
|
getDisplayName(): string;
|
|
16
|
-
getDefaultCyclingMode(): CyclingMode;
|
|
17
|
-
getSupportedCyclingModes(): any[];
|
|
18
15
|
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
19
16
|
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
20
17
|
sendUpdate(request: any): Promise<void>;
|
package/lib/ble/cp/adapter.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -13,18 +36,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
36
|
};
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
38
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
-
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
17
39
|
const comm_1 = __importDefault(require("./comm"));
|
|
18
|
-
const adapter_1 = require("../base/adapter");
|
|
40
|
+
const adapter_1 = __importStar(require("../base/adapter"));
|
|
19
41
|
const capabilities_1 = require("../../types/capabilities");
|
|
20
|
-
class PwrAdapter extends adapter_1.
|
|
42
|
+
class PwrAdapter extends adapter_1.default {
|
|
21
43
|
constructor(settings, props) {
|
|
22
44
|
super(settings, props);
|
|
23
45
|
this.distanceInternal = 0;
|
|
46
|
+
this.setControl(new adapter_1.BlePowerControl(this, props));
|
|
24
47
|
this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
|
|
25
48
|
const { id, address, name } = settings;
|
|
26
49
|
const logger = this.logger;
|
|
27
|
-
const ble = this.ble;
|
|
28
50
|
this.device = new comm_1.default({ id, address, name, logger });
|
|
29
51
|
this.capabilities = [
|
|
30
52
|
capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Speed
|
|
@@ -47,12 +69,6 @@ class PwrAdapter extends adapter_1.BleControllableAdapter {
|
|
|
47
69
|
const powerStr = power ? ` (${power})` : '';
|
|
48
70
|
return `${name}${powerStr}`;
|
|
49
71
|
}
|
|
50
|
-
getDefaultCyclingMode() {
|
|
51
|
-
return new power_meter_1.default(this);
|
|
52
|
-
}
|
|
53
|
-
getSupportedCyclingModes() {
|
|
54
|
-
return [power_meter_1.default];
|
|
55
|
-
}
|
|
56
72
|
mapData(deviceData) {
|
|
57
73
|
const data = {
|
|
58
74
|
isPedalling: false,
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import BleAdapter, {
|
|
2
|
-
import
|
|
1
|
+
import BleAdapter, { BlePowerControl } from '../base/adapter';
|
|
2
|
+
import ICyclingMode, { IncyclistBikeData } from '../../modes/types';
|
|
3
3
|
import { PowerData } from '../cp';
|
|
4
4
|
import { DeviceProperties } from '../../types/device';
|
|
5
5
|
import { DeviceData } from '../../types/data';
|
|
6
6
|
import { BleDeviceSettings } from '../types';
|
|
7
|
-
|
|
7
|
+
import { IncyclistDeviceAdapter } from '../../types/adapter';
|
|
8
|
+
export default class BleEliteAdapter extends BleAdapter<BlePowerControl> {
|
|
8
9
|
distanceInternal: number;
|
|
9
10
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
10
|
-
isSame(device:
|
|
11
|
+
isSame(device: IncyclistDeviceAdapter): boolean;
|
|
11
12
|
getProfile(): string;
|
|
12
13
|
getName(): string;
|
|
13
|
-
getDefaultCyclingMode():
|
|
14
|
+
getDefaultCyclingMode(): ICyclingMode;
|
|
14
15
|
getSupportedCyclingModes(): any[];
|
|
15
16
|
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
16
17
|
transformData(bikeData: IncyclistBikeData): DeviceData;
|
package/lib/ble/elite/adapter.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -13,14 +36,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
36
|
};
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
38
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
-
const adapter_1 = require("../base/adapter");
|
|
39
|
+
const adapter_1 = __importStar(require("../base/adapter"));
|
|
17
40
|
const comms_1 = __importDefault(require("./comms"));
|
|
18
41
|
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
19
42
|
const capabilities_1 = require("../../types/capabilities");
|
|
20
|
-
class BleEliteAdapter extends adapter_1.
|
|
43
|
+
class BleEliteAdapter extends adapter_1.default {
|
|
21
44
|
constructor(settings, props) {
|
|
22
45
|
super(settings, props);
|
|
23
46
|
this.distanceInternal = 0;
|
|
47
|
+
this.setControl(new adapter_1.BlePowerControl(this, props));
|
|
24
48
|
this.logger = new gd_eventlog_1.EventLogger('BLE-Elite');
|
|
25
49
|
const { id, address, name } = settings;
|
|
26
50
|
const logger = this.logger;
|
package/lib/ble/fm/adapter.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import BleAdapter
|
|
2
|
-
import
|
|
3
|
-
import { DeviceProperties } from '../../types/device';
|
|
1
|
+
import BleAdapter from '../base/adapter';
|
|
2
|
+
import ICyclingMode, { CyclingMode, IncyclistBikeData } from '../../modes/types';
|
|
4
3
|
import { IndoorBikeData } from './types';
|
|
5
4
|
import { DeviceData } from '../../types/data';
|
|
6
|
-
import { BleDeviceSettings, BleStartProperties } from '../types';
|
|
7
|
-
|
|
5
|
+
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from '../types';
|
|
6
|
+
import { ControllableDevice } from '../../base/adpater';
|
|
7
|
+
import { IncyclistDeviceAdapter } from '../../types/adapter';
|
|
8
|
+
export default class BleFmAdapter extends BleAdapter<ControllableDevice<BleDeviceProperties>> {
|
|
8
9
|
distanceInternal: number;
|
|
9
10
|
connectPromise: Promise<boolean>;
|
|
10
|
-
constructor(settings: BleDeviceSettings, props?:
|
|
11
|
-
isSame(device:
|
|
11
|
+
constructor(settings: BleDeviceSettings, props?: BleDeviceProperties);
|
|
12
|
+
isSame(device: IncyclistDeviceAdapter): boolean;
|
|
12
13
|
getProfile(): string;
|
|
13
14
|
getName(): string;
|
|
14
15
|
getDisplayName(): string;
|
|
15
|
-
getSupportedCyclingModes(): Array<
|
|
16
|
-
getDefaultCyclingMode():
|
|
16
|
+
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
17
|
+
getDefaultCyclingMode(): ICyclingMode;
|
|
17
18
|
mapData(deviceData: IndoorBikeData): IncyclistBikeData;
|
|
18
19
|
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
19
20
|
start(props?: BleStartProperties): Promise<any>;
|