incyclist-devices 2.1.0 → 2.1.2
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 +69 -0
- package/lib/antv2/base/adapter.js +439 -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/base/interface.d.ts +46 -0
- package/lib/antv2/base/interface.js +337 -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 +73 -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 +21 -30
- package/lib/antv2/fe/adapter.js +139 -251
- 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 +5 -3
- package/lib/antv2/pwr/adapter.d.ts +9 -33
- package/lib/antv2/pwr/adapter.js +19 -140
- package/lib/antv2/types.d.ts +32 -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 +5 -4
- 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 +2 -0
- package/lib/utils/utils.js +39 -4
- package/package.json +1 -1
package/lib/base/adpater.js
CHANGED
|
@@ -12,15 +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.NonControllableDevice = exports.DEFAULT_PROPS = exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_BIKE_WEIGHT = void 0;
|
|
16
|
-
const adapter_1 = require("../types/adapter");
|
|
17
15
|
const events_1 = __importDefault(require("events"));
|
|
18
|
-
|
|
19
|
-
exports.DEFAULT_USER_WEIGHT = 75;
|
|
20
|
-
exports.DEFAULT_PROPS = {
|
|
21
|
-
userWeight: exports.DEFAULT_USER_WEIGHT,
|
|
22
|
-
bikeWeight: exports.DEFAULT_BIKE_WEIGHT
|
|
23
|
-
};
|
|
16
|
+
const consts_1 = require("./consts");
|
|
24
17
|
class IncyclistDevice extends events_1.default {
|
|
25
18
|
constructor(settings, props) {
|
|
26
19
|
super();
|
|
@@ -31,220 +24,205 @@ class IncyclistDevice extends events_1.default {
|
|
|
31
24
|
this.started = false;
|
|
32
25
|
this.stopped = false;
|
|
33
26
|
this.paused = false;
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.bikeControl = control;
|
|
27
|
+
this.user = {};
|
|
28
|
+
this.data = {};
|
|
29
|
+
this.cyclingMode = this.getDefaultCyclingMode();
|
|
38
30
|
}
|
|
39
|
-
connect() { throw new Error('not implemented'); }
|
|
40
|
-
close() { throw new Error('not implemented'); }
|
|
41
|
-
check() { throw new Error("Method not implemented."); }
|
|
42
31
|
getLogger() { return this.logger; }
|
|
43
|
-
isControllable() {
|
|
44
|
-
var _a;
|
|
45
|
-
return (_a = this.bikeControl) === null || _a === void 0 ? void 0 : _a.isControllable();
|
|
46
|
-
}
|
|
47
|
-
isEqual(settings) { throw new Error("Method not implemented."); }
|
|
48
|
-
getCapabilities() { return this.capabilities; }
|
|
49
|
-
hasCapability(capability) {
|
|
50
|
-
return this.capabilities.find(c => c === capability) !== undefined;
|
|
51
|
-
}
|
|
52
|
-
addCapability(capability) {
|
|
53
|
-
if (!this.capabilities.includes(capability))
|
|
54
|
-
this.capabilities.push(capability);
|
|
55
|
-
}
|
|
56
|
-
update() { throw new Error("Method not implemented."); }
|
|
57
|
-
start(props) { throw new Error("Method not implemented."); }
|
|
58
|
-
stop() { throw new Error("Method not implemented."); }
|
|
59
|
-
pause() {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
this.paused = true;
|
|
62
|
-
return true;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
resume() {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
this.paused = false;
|
|
68
|
-
return true;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
32
|
logEvent(event) {
|
|
72
33
|
if (!this.logger || this.paused)
|
|
73
34
|
return;
|
|
74
35
|
this.logger.logEvent(event);
|
|
75
36
|
const w = global.window;
|
|
76
37
|
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG || process.env.ANT_DEBUG) {
|
|
77
|
-
const logText =
|
|
38
|
+
const logText = `~~~ ${this.getInterface()}: ${this.logger.getName()}`;
|
|
78
39
|
console.log(logText, event);
|
|
79
40
|
}
|
|
80
41
|
}
|
|
81
|
-
getMaxUpdateFrequency() {
|
|
82
|
-
return this.updateFrequency;
|
|
83
|
-
}
|
|
84
|
-
setMaxUpdateFrequency(value) {
|
|
85
|
-
this.updateFrequency = value;
|
|
86
|
-
}
|
|
87
|
-
sendUpdate(request) { throw new Error("Method not implemented."); }
|
|
88
|
-
getID() { throw new Error('not implemented'); }
|
|
89
|
-
getDisplayName() {
|
|
90
|
-
return this.getName();
|
|
91
|
-
}
|
|
92
42
|
getName() {
|
|
93
43
|
return this.settings.name;
|
|
94
44
|
}
|
|
45
|
+
getID() { throw new Error('not implemented'); }
|
|
95
46
|
getUniqueName() {
|
|
96
47
|
throw new Error("Method not implemented.");
|
|
97
48
|
}
|
|
49
|
+
getDisplayName() {
|
|
50
|
+
return this.getName();
|
|
51
|
+
}
|
|
98
52
|
getSettings() {
|
|
99
53
|
return this.settings;
|
|
100
54
|
}
|
|
55
|
+
isSame(adapter) { throw new Error("Method not implemented."); }
|
|
56
|
+
isEqual(settings) { throw new Error("Method not implemented."); }
|
|
101
57
|
getInterface() {
|
|
102
58
|
return typeof this.settings.interface === 'string' ? this.settings.interface : this.settings.interface.getName();
|
|
103
59
|
}
|
|
104
|
-
|
|
105
|
-
|
|
60
|
+
check() { throw new Error("Method not implemented."); }
|
|
61
|
+
start(props) { throw new Error("Method not implemented."); }
|
|
62
|
+
stop() { throw new Error("Method not implemented."); }
|
|
63
|
+
pause() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
this.paused = true;
|
|
66
|
+
return true;
|
|
67
|
+
});
|
|
106
68
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
69
|
+
resume() {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
this.paused = false;
|
|
110
72
|
return true;
|
|
111
|
-
|
|
73
|
+
});
|
|
112
74
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
75
|
+
connect() { throw new Error('not implemented'); }
|
|
76
|
+
close() { throw new Error('not implemented'); }
|
|
77
|
+
getControllerInfo() {
|
|
78
|
+
const a = this.constructor;
|
|
79
|
+
const config = a.controllers;
|
|
80
|
+
if (!config)
|
|
81
|
+
return undefined;
|
|
82
|
+
if (config.modes && config.modes.length > 0) {
|
|
83
|
+
if (!config.default)
|
|
84
|
+
config.default = config.modes[0];
|
|
85
|
+
return config;
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
120
88
|
}
|
|
121
|
-
|
|
122
|
-
|
|
89
|
+
isControllable() {
|
|
90
|
+
if (!this.getControllerInfo())
|
|
91
|
+
return false;
|
|
92
|
+
return true;
|
|
123
93
|
}
|
|
124
|
-
|
|
125
|
-
|
|
94
|
+
getCapabilities() { return this.capabilities; }
|
|
95
|
+
hasCapability(capability) {
|
|
96
|
+
return this.capabilities.find(c => c === capability) !== undefined;
|
|
126
97
|
}
|
|
127
|
-
|
|
128
|
-
|
|
98
|
+
addCapability(capability) {
|
|
99
|
+
if (!this.capabilities.includes(capability))
|
|
100
|
+
this.capabilities.push(capability);
|
|
129
101
|
}
|
|
130
|
-
|
|
131
|
-
return this.
|
|
102
|
+
getMaxUpdateFrequency() {
|
|
103
|
+
return this.updateFrequency;
|
|
104
|
+
}
|
|
105
|
+
setMaxUpdateFrequency(value) {
|
|
106
|
+
this.updateFrequency = value;
|
|
132
107
|
}
|
|
108
|
+
update() { throw new Error("Method not implemented."); }
|
|
133
109
|
setCyclingMode(mode, settings, sendInitCommands) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
110
|
+
if (!this.isControllable())
|
|
111
|
+
return;
|
|
112
|
+
let selectedMode;
|
|
113
|
+
if (typeof mode === 'string') {
|
|
114
|
+
const supported = this.getSupportedCyclingModes();
|
|
115
|
+
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
116
|
+
if (CyclingModeClass) {
|
|
117
|
+
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
selectedMode = this.getDefaultCyclingMode();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
selectedMode = mode;
|
|
124
|
+
}
|
|
125
|
+
this.cyclingMode = selectedMode;
|
|
126
|
+
this.cyclingMode.setSettings(settings);
|
|
137
127
|
}
|
|
138
128
|
getSupportedCyclingModes() {
|
|
139
|
-
var _a;
|
|
140
129
|
if (!this.isControllable())
|
|
141
130
|
return [];
|
|
142
|
-
|
|
131
|
+
const config = this.getControllerInfo();
|
|
132
|
+
return config.modes;
|
|
143
133
|
}
|
|
144
134
|
getCyclingMode() {
|
|
145
135
|
if (this.isControllable())
|
|
146
|
-
return this.
|
|
136
|
+
return this.cyclingMode;
|
|
147
137
|
}
|
|
148
138
|
getDefaultCyclingMode() {
|
|
149
|
-
if (this.isControllable())
|
|
150
|
-
return
|
|
139
|
+
if (!this.isControllable())
|
|
140
|
+
return;
|
|
141
|
+
const config = this.getControllerInfo();
|
|
142
|
+
const C = config.default;
|
|
143
|
+
try {
|
|
144
|
+
return new C(this);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
this.logEvent({ message: 'error', error: err.message, fn: 'getDefaultCyclingMode', stack: err.stack });
|
|
148
|
+
}
|
|
151
149
|
}
|
|
152
150
|
setBikeProps(props) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return (_a = this.bikeControl) === null || _a === void 0 ? void 0 : _a.getWeight();
|
|
151
|
+
const { user, userWeight } = props || {};
|
|
152
|
+
if (user)
|
|
153
|
+
this.setUser(user);
|
|
154
|
+
if (userWeight)
|
|
155
|
+
this.user.weight = userWeight;
|
|
156
|
+
const keys = Object.keys(props);
|
|
157
|
+
keys.forEach(k => {
|
|
158
|
+
const p = props[k];
|
|
159
|
+
if (p === null)
|
|
160
|
+
delete this.props[k];
|
|
161
|
+
else if (p !== undefined)
|
|
162
|
+
this.props[k] = p;
|
|
163
|
+
});
|
|
167
164
|
}
|
|
168
165
|
sendInitCommands() {
|
|
169
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
if (this.isControllable())
|
|
171
|
-
return yield this.bikeControl.sendInitCommands();
|
|
172
167
|
return false;
|
|
173
168
|
});
|
|
174
169
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
isControllable() {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
setCyclingMode(mode, settings, sendInitCommands) {
|
|
182
|
-
throw new Error("Method not implemented.");
|
|
183
|
-
}
|
|
184
|
-
getSupportedCyclingModes() {
|
|
170
|
+
sendUpdate(request) {
|
|
171
|
+
if (!this.isControllable())
|
|
172
|
+
return;
|
|
185
173
|
throw new Error("Method not implemented.");
|
|
186
174
|
}
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
setUser(user) {
|
|
176
|
+
this.user = user;
|
|
177
|
+
if (!user.weight)
|
|
178
|
+
this.user.weight = consts_1.DEFAULT_USER_WEIGHT;
|
|
189
179
|
}
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
getUser() {
|
|
181
|
+
return this.user;
|
|
192
182
|
}
|
|
193
|
-
|
|
194
|
-
|
|
183
|
+
getWeight() {
|
|
184
|
+
const { user = {}, props = consts_1.DEFAULT_PROPS } = this;
|
|
185
|
+
const userWeight = user.weight || props.userWeight || consts_1.DEFAULT_USER_WEIGHT;
|
|
186
|
+
const bikeWeight = props.bikeWeight || consts_1.DEFAULT_BIKE_WEIGHT;
|
|
187
|
+
return userWeight + bikeWeight;
|
|
195
188
|
}
|
|
196
|
-
|
|
197
|
-
|
|
189
|
+
isUpdateWithinFrequency() {
|
|
190
|
+
const updateFrequency = this.getMaxUpdateFrequency();
|
|
191
|
+
if (updateFrequency === -1 || updateFrequency === undefined)
|
|
192
|
+
return true;
|
|
193
|
+
return (!this.lastUpdate || (Date.now() - this.lastUpdate) > updateFrequency);
|
|
198
194
|
}
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
canEmitData() {
|
|
196
|
+
if (this.paused || this.stopped)
|
|
201
197
|
return false;
|
|
202
|
-
|
|
198
|
+
return this.isUpdateWithinFrequency();
|
|
203
199
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
this.
|
|
200
|
+
emitData(data) {
|
|
201
|
+
if (!this.canEmitData())
|
|
202
|
+
return;
|
|
203
|
+
if (this.onDataFn)
|
|
204
|
+
this.onDataFn(data);
|
|
205
|
+
this.emit('data', this.getSettings(), data);
|
|
206
|
+
this.lastUpdate = Date.now();
|
|
210
207
|
}
|
|
211
|
-
|
|
212
|
-
return
|
|
208
|
+
isStopped() {
|
|
209
|
+
return this.stopped;
|
|
213
210
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
setCyclingMode(mode, settings) {
|
|
217
|
-
let selectedMode;
|
|
218
|
-
if (typeof mode === 'string') {
|
|
219
|
-
const supported = this.getSupportedCyclingModes();
|
|
220
|
-
const CyclingModeClass = supported.find(M => { const m = new M(this.adapter); return m.getName() === mode; });
|
|
221
|
-
if (CyclingModeClass) {
|
|
222
|
-
this.cyclingMode = new CyclingModeClass(this.adapter, settings);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
selectedMode = this.getDefaultCyclingMode();
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
selectedMode = mode;
|
|
229
|
-
}
|
|
230
|
-
this.cyclingMode = selectedMode;
|
|
231
|
-
this.cyclingMode.setSettings(settings);
|
|
211
|
+
isStarted() {
|
|
212
|
+
return this.started;
|
|
232
213
|
}
|
|
233
|
-
|
|
234
|
-
return
|
|
235
|
-
return true;
|
|
236
|
-
});
|
|
214
|
+
isPaused() {
|
|
215
|
+
return this.paused;
|
|
237
216
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
241
|
-
return this.cyclingMode;
|
|
217
|
+
getData() {
|
|
218
|
+
return this.data;
|
|
242
219
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
220
|
+
hasDataListeners() {
|
|
221
|
+
return this.onDataFn || this.listenerCount('data') > 0;
|
|
222
|
+
}
|
|
223
|
+
onData(callback) {
|
|
224
|
+
this.onDataFn = callback;
|
|
248
225
|
}
|
|
249
226
|
}
|
|
250
|
-
|
|
227
|
+
IncyclistDevice.controllers = {};
|
|
228
|
+
exports.default = IncyclistDevice;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_PROPS = exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_BIKE_WEIGHT = void 0;
|
|
4
|
+
exports.DEFAULT_BIKE_WEIGHT = 10;
|
|
5
|
+
exports.DEFAULT_USER_WEIGHT = 75;
|
|
6
|
+
exports.DEFAULT_PROPS = {
|
|
7
|
+
userWeight: exports.DEFAULT_USER_WEIGHT,
|
|
8
|
+
bikeWeight: exports.DEFAULT_BIKE_WEIGHT
|
|
9
|
+
};
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import { DeviceProperties } from "../types/device";
|
|
2
1
|
import BleAdapter from "./base/adapter";
|
|
3
|
-
import {
|
|
2
|
+
import { BleDeviceSettings, BleProtocol } from "./types";
|
|
3
|
+
import { DeviceProperties } from "../types";
|
|
4
4
|
import { BleComms } from "./base/comms";
|
|
5
|
-
import { Controllable } from "../types/adapter";
|
|
6
5
|
export interface BleAdapterInfo {
|
|
7
6
|
protocol: BleProtocol;
|
|
8
|
-
Adapter: typeof BleAdapter
|
|
7
|
+
Adapter: typeof BleAdapter;
|
|
9
8
|
Comm: typeof BleComms;
|
|
10
9
|
}
|
|
11
10
|
export default class BleAdapterFactory {
|
|
12
11
|
static _instance: BleAdapterFactory;
|
|
13
12
|
implementations: BleAdapterInfo[];
|
|
14
|
-
instances: Array<BleAdapter
|
|
13
|
+
instances: Array<BleAdapter>;
|
|
15
14
|
static getInstance(): BleAdapterFactory;
|
|
16
15
|
constructor();
|
|
17
16
|
getAdapterInfo(protocol: BleProtocol): BleAdapterInfo;
|
|
18
17
|
getAll(): BleAdapterInfo[];
|
|
19
|
-
createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter
|
|
18
|
+
createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter;
|
|
20
19
|
removeInstance(query: {
|
|
21
20
|
settings?: BleDeviceSettings;
|
|
22
|
-
adapter?: BleAdapter
|
|
21
|
+
adapter?: BleAdapter;
|
|
23
22
|
}): void;
|
|
24
|
-
find(settings?: BleDeviceSettings): BleAdapter
|
|
25
|
-
register(protocol: BleProtocol, Adapter: typeof BleAdapter
|
|
26
|
-
getAllInstances(): Array<BleAdapter
|
|
23
|
+
find(settings?: BleDeviceSettings): BleAdapter;
|
|
24
|
+
register(protocol: BleProtocol, Adapter: typeof BleAdapter, Comm: typeof BleComms): void;
|
|
25
|
+
getAllInstances(): Array<BleAdapter>;
|
|
27
26
|
getAllSupportedComms(): (typeof BleComms)[];
|
|
28
|
-
getAllSupportedAdapters(): Array<(typeof BleAdapter
|
|
27
|
+
getAllSupportedAdapters(): Array<(typeof BleAdapter)>;
|
|
29
28
|
getAllSupportedServices(): string[];
|
|
30
29
|
getDeviceClasses(peripheral: any, props?: {
|
|
31
30
|
protocol?: BleProtocol;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import IncyclistDevice
|
|
2
|
-
import ICyclingMode, { IncyclistBikeData } from "../../modes/types";
|
|
3
|
-
import { Controllable, IncyclistDeviceAdapter } from "../../types/adapter";
|
|
4
|
-
import { DeviceData } from "../../types/data";
|
|
5
|
-
import { DeviceProperties } from "../../types/device";
|
|
1
|
+
import IncyclistDevice from "../../base/adpater";
|
|
6
2
|
import { BleComms } from "./comms";
|
|
7
3
|
import BleInterface from "../ble-interface";
|
|
8
4
|
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from "../types";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
getSupportedCyclingModes(): any[];
|
|
12
|
-
}
|
|
13
|
-
export default class BleAdapter<DC extends Controllable<BleDeviceProperties>> extends IncyclistDevice<DC, BleDeviceProperties> {
|
|
5
|
+
import { IAdapter, IncyclistBikeData, IncyclistAdapterData, DeviceProperties } from "../../types";
|
|
6
|
+
export default class BleAdapter extends IncyclistDevice<BleDeviceProperties> {
|
|
14
7
|
ble: BleInterface;
|
|
15
8
|
deviceData: any;
|
|
16
|
-
data:
|
|
9
|
+
data: IncyclistAdapterData;
|
|
17
10
|
dataMsgCount: number;
|
|
18
11
|
lastDataTS: number;
|
|
19
12
|
device: BleComms;
|
|
@@ -23,7 +16,7 @@ export default class BleAdapter<DC extends Controllable<BleDeviceProperties>> ex
|
|
|
23
16
|
close(): Promise<boolean>;
|
|
24
17
|
getComms(): BleComms;
|
|
25
18
|
isEqual(settings: BleDeviceSettings): boolean;
|
|
26
|
-
isSame(adapter:
|
|
19
|
+
isSame(adapter: IAdapter): boolean;
|
|
27
20
|
isConnected(): boolean;
|
|
28
21
|
resetData(): void;
|
|
29
22
|
getInterface(): string;
|
|
@@ -31,8 +24,8 @@ export default class BleAdapter<DC extends Controllable<BleDeviceProperties>> ex
|
|
|
31
24
|
getID(): string;
|
|
32
25
|
getName(): string;
|
|
33
26
|
onDeviceData(deviceData: any): void;
|
|
34
|
-
mapData(deviceData: any):
|
|
35
|
-
transformData(data: IncyclistBikeData):
|
|
27
|
+
mapData(deviceData: any): IncyclistAdapterData | IncyclistBikeData;
|
|
28
|
+
transformData(data: IncyclistBikeData): IncyclistAdapterData;
|
|
36
29
|
getSettings(): BleDeviceSettings;
|
|
37
30
|
setProperties(props: BleDeviceProperties): void;
|
|
38
31
|
check(): Promise<boolean>;
|
package/lib/ble/base/adapter.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
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
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,20 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
13
|
};
|
|
37
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
|
|
39
|
-
const adpater_1 = __importStar(require("../../base/adpater"));
|
|
15
|
+
const adpater_1 = __importDefault(require("../../base/adpater"));
|
|
40
16
|
const ble_interface_1 = __importDefault(require("../ble-interface"));
|
|
41
|
-
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
42
17
|
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;
|
|
52
18
|
class BleAdapter extends adpater_1.default {
|
|
53
19
|
constructor(settings, props) {
|
|
54
20
|
super(settings, props);
|
|
@@ -144,7 +110,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
144
110
|
this.dataMsgCount++;
|
|
145
111
|
this.lastDataTS = Date.now();
|
|
146
112
|
this.deviceData = Object.assign({}, deviceData);
|
|
147
|
-
if (!this.started || !this.
|
|
113
|
+
if (!this.started || !this.canEmitData())
|
|
148
114
|
return;
|
|
149
115
|
this.logEvent({ message: 'onDeviceData', data: deviceData, isControllable: this.isControllable() });
|
|
150
116
|
if (this.isControllable()) {
|
|
@@ -2,14 +2,12 @@
|
|
|
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
|
|
5
|
+
import { BleInterfaceProps, BlePeripheral, BleDeviceSettings, BleProtocol, BleBinding, BleInterfaceState, BleScanProps, BleCharacteristic } from './types';
|
|
6
6
|
import { BleComms } from './base/comms';
|
|
7
|
-
import { IncyclistInterface } from '../types
|
|
7
|
+
import { IncyclistInterface, IncyclistScanProps } from '../types';
|
|
8
8
|
import BleAdapter from './base/adapter';
|
|
9
|
-
import { IncyclistScanProps } from '../types/device';
|
|
10
9
|
import BlePeripheralCache from './peripheral-cache';
|
|
11
10
|
import EventEmitter from 'events';
|
|
12
|
-
import { Controllable } from '..';
|
|
13
11
|
export interface ScanState {
|
|
14
12
|
isScanning: boolean;
|
|
15
13
|
isConnecting: boolean;
|
|
@@ -41,7 +39,7 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
|
|
|
41
39
|
logger: EventLogger;
|
|
42
40
|
props: BleInterfaceProps;
|
|
43
41
|
binding: BleBinding;
|
|
44
|
-
connectedDevices: Array<BleAdapter
|
|
42
|
+
connectedDevices: Array<BleAdapter>;
|
|
45
43
|
sensorIsConnecting: boolean;
|
|
46
44
|
emittingAdapters: {
|
|
47
45
|
comms: BleComms;
|
|
@@ -80,6 +78,6 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
|
|
|
80
78
|
scan(props?: BleScanProps): Promise<BleDeviceSettings[]>;
|
|
81
79
|
stopScan(): Promise<boolean>;
|
|
82
80
|
isScanning(): boolean;
|
|
83
|
-
addConnectedDevice(device: BleAdapter
|
|
84
|
-
removeConnectedDevice(device: BleAdapter
|
|
81
|
+
addConnectedDevice(device: BleAdapter): void;
|
|
82
|
+
removeConnectedDevice(device: BleAdapter): void;
|
|
85
83
|
}
|
package/lib/ble/cp/adapter.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import BleAdapter, { BlePowerControl } from '../base/adapter';
|
|
3
|
-
import { DeviceProperties } from '../../types/device';
|
|
1
|
+
import BleAdapter from '../base/adapter';
|
|
4
2
|
import { PowerData } from './types';
|
|
5
|
-
import { DeviceData } from '../../types/data';
|
|
6
3
|
import { BleDeviceSettings } from '../types';
|
|
7
|
-
import {
|
|
8
|
-
export default class PwrAdapter extends BleAdapter
|
|
4
|
+
import { DeviceProperties, IncyclistBikeData, IncyclistAdapterData, ControllerConfig, IAdapter } from '../../types';
|
|
5
|
+
export default class PwrAdapter extends BleAdapter {
|
|
6
|
+
protected static controllers: ControllerConfig;
|
|
9
7
|
distanceInternal: number;
|
|
10
8
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
11
|
-
isSame(device:
|
|
9
|
+
isSame(device: IAdapter): boolean;
|
|
12
10
|
getProfile(): string;
|
|
13
11
|
getName(): string;
|
|
14
12
|
getDisplayName(): string;
|
|
15
13
|
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
16
|
-
transformData(bikeData: IncyclistBikeData):
|
|
14
|
+
transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
|
|
17
15
|
sendUpdate(request: any): Promise<void>;
|
|
18
16
|
stop(): Promise<boolean>;
|
|
19
17
|
}
|
package/lib/ble/cp/adapter.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
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
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -37,19 +14,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
15
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
39
16
|
const comm_1 = __importDefault(require("./comm"));
|
|
40
|
-
const adapter_1 =
|
|
41
|
-
const
|
|
17
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
18
|
+
const types_1 = require("../../types");
|
|
19
|
+
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
42
20
|
class PwrAdapter extends adapter_1.default {
|
|
43
21
|
constructor(settings, props) {
|
|
44
22
|
super(settings, props);
|
|
45
23
|
this.distanceInternal = 0;
|
|
46
|
-
this.setControl(new adapter_1.BlePowerControl(this, props));
|
|
47
24
|
this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
|
|
48
25
|
const { id, address, name } = settings;
|
|
49
26
|
const logger = this.logger;
|
|
50
27
|
this.device = new comm_1.default({ id, address, name, logger });
|
|
51
28
|
this.capabilities = [
|
|
52
|
-
|
|
29
|
+
types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Cadence, types_1.IncyclistCapability.Speed
|
|
53
30
|
];
|
|
54
31
|
}
|
|
55
32
|
isSame(device) {
|
|
@@ -124,4 +101,8 @@ class PwrAdapter extends adapter_1.default {
|
|
|
124
101
|
});
|
|
125
102
|
}
|
|
126
103
|
}
|
|
104
|
+
PwrAdapter.controllers = {
|
|
105
|
+
modes: [power_meter_1.default],
|
|
106
|
+
default: power_meter_1.default
|
|
107
|
+
};
|
|
127
108
|
exports.default = PwrAdapter;
|