incyclist-devices 2.1.9 → 2.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
1
3
|
import { IncyclistAdapterData, ControllerConfig, IAdapter, DeviceProperties, IncyclistBikeData } from '../../types';
|
|
2
4
|
import { SerialDeviceSettings } from "../types";
|
|
3
5
|
import { DaumSerialComms } from './types';
|
|
4
6
|
import { SerialIncyclistDevice } from '../base/adapter';
|
|
5
7
|
import SerialInterface from '../base/serial-interface';
|
|
8
|
+
import EventEmitter from 'events';
|
|
6
9
|
export default class DaumAdapter<S extends SerialDeviceSettings, P extends DeviceProperties, C extends DaumSerialComms> extends SerialIncyclistDevice<P> {
|
|
7
10
|
protected static controllers: ControllerConfig;
|
|
8
11
|
comms: C;
|
|
9
12
|
distanceInternal: number;
|
|
10
13
|
deviceData: IncyclistBikeData;
|
|
11
14
|
requests: Array<any>;
|
|
12
|
-
iv:
|
|
15
|
+
iv: {
|
|
16
|
+
sync: NodeJS.Timeout;
|
|
17
|
+
update: NodeJS.Timeout;
|
|
18
|
+
emitter: EventEmitter;
|
|
19
|
+
stopRequested?: boolean;
|
|
20
|
+
};
|
|
13
21
|
tsPrevData: number;
|
|
14
22
|
adapterTime: number;
|
|
15
23
|
requestBusy: boolean;
|
|
@@ -27,7 +35,7 @@ export default class DaumAdapter<S extends SerialDeviceSettings, P extends Devic
|
|
|
27
35
|
isStopped(): boolean;
|
|
28
36
|
initData(): void;
|
|
29
37
|
pause(): Promise<boolean>;
|
|
30
|
-
resume(): Promise<boolean>;
|
|
38
|
+
resume(startUpdatePull?: boolean): Promise<boolean>;
|
|
31
39
|
waitForPrevCheckFinished(): Promise<void>;
|
|
32
40
|
check(): Promise<boolean>;
|
|
33
41
|
performCheck(): Promise<boolean>;
|
|
@@ -35,7 +43,8 @@ export default class DaumAdapter<S extends SerialDeviceSettings, P extends Devic
|
|
|
35
43
|
start(props?: P): Promise<boolean>;
|
|
36
44
|
performStart(props?: P, isRelaunch?: boolean, wasPaused?: boolean): Promise<boolean>;
|
|
37
45
|
startUpdatePull(): void;
|
|
38
|
-
|
|
46
|
+
protected cleanupInterval(): void;
|
|
47
|
+
stopUpdatePull(): Promise<void>;
|
|
39
48
|
connect(): Promise<boolean>;
|
|
40
49
|
close(): Promise<boolean>;
|
|
41
50
|
verifyConnection(): Promise<void>;
|
|
@@ -18,6 +18,7 @@ const types_1 = require("../../types");
|
|
|
18
18
|
const adapter_1 = require("../base/adapter");
|
|
19
19
|
const daum_smarttrainer_1 = __importDefault(require("../../modes/daum-smarttrainer"));
|
|
20
20
|
const daum_power_1 = __importDefault(require("../../modes/daum-power"));
|
|
21
|
+
const events_1 = __importDefault(require("events"));
|
|
21
22
|
class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
22
23
|
constructor(settings, props) {
|
|
23
24
|
super(settings, props);
|
|
@@ -114,12 +115,13 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
114
115
|
});
|
|
115
116
|
var _a;
|
|
116
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
yield this.stopUpdatePull();
|
|
117
119
|
const paused = yield _super.pause.call(this);
|
|
118
120
|
(_a = this.comms) === null || _a === void 0 ? void 0 : _a.pauseLogging();
|
|
119
121
|
return paused;
|
|
120
122
|
});
|
|
121
123
|
}
|
|
122
|
-
resume() {
|
|
124
|
+
resume(startUpdatePull = true) {
|
|
123
125
|
const _super = Object.create(null, {
|
|
124
126
|
resume: { get: () => super.resume }
|
|
125
127
|
});
|
|
@@ -127,6 +129,8 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
127
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
130
|
const resumed = yield _super.resume.call(this);
|
|
129
131
|
(_a = this.comms) === null || _a === void 0 ? void 0 : _a.resumeLogging();
|
|
132
|
+
if (startUpdatePull)
|
|
133
|
+
yield this.startUpdatePull();
|
|
130
134
|
return resumed;
|
|
131
135
|
});
|
|
132
136
|
}
|
|
@@ -190,7 +194,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
190
194
|
try {
|
|
191
195
|
let wasPaused = false;
|
|
192
196
|
if (isRelaunch && this.isPaused()) {
|
|
193
|
-
this.resume();
|
|
197
|
+
this.resume(false);
|
|
194
198
|
wasPaused = true;
|
|
195
199
|
}
|
|
196
200
|
this.startPromise = this.performStart(props, isRelaunch, wasPaused).then((started) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -244,17 +248,34 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
244
248
|
}, this.pullFrequency);
|
|
245
249
|
this.iv = {
|
|
246
250
|
sync: ivSync,
|
|
247
|
-
update: ivUpdate
|
|
251
|
+
update: ivUpdate,
|
|
252
|
+
emitter: new events_1.default()
|
|
248
253
|
};
|
|
254
|
+
this.iv.emitter.once('stop', () => {
|
|
255
|
+
this.iv.stopRequested = true;
|
|
256
|
+
});
|
|
249
257
|
}
|
|
250
|
-
|
|
251
|
-
if (!this.iv)
|
|
252
|
-
return;
|
|
253
|
-
this.logEvent({ message: 'stop update pull', port: this.getPort() });
|
|
258
|
+
cleanupInterval() {
|
|
254
259
|
clearInterval(this.iv.sync);
|
|
255
260
|
clearInterval(this.iv.update);
|
|
261
|
+
this.iv.emitter.removeAllListeners();
|
|
256
262
|
this.iv = undefined;
|
|
257
263
|
}
|
|
264
|
+
stopUpdatePull() {
|
|
265
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
+
if (!this.iv || !this.iv.emitter)
|
|
267
|
+
return;
|
|
268
|
+
return new Promise(done => {
|
|
269
|
+
this.iv.emitter.on('stop-done', () => {
|
|
270
|
+
this.logEvent({ message: 'stop update pull done', port: this.getPort() });
|
|
271
|
+
this.cleanupInterval();
|
|
272
|
+
done();
|
|
273
|
+
});
|
|
274
|
+
this.iv.emitter.emit('stop');
|
|
275
|
+
this.logEvent({ message: 'stop update pull', port: this.getPort() });
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
}
|
|
258
279
|
connect() {
|
|
259
280
|
return __awaiter(this, void 0, void 0, function* () {
|
|
260
281
|
if (!this.comms)
|
|
@@ -318,7 +339,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
318
339
|
if (this.paused)
|
|
319
340
|
this.resume();
|
|
320
341
|
try {
|
|
321
|
-
this.stopUpdatePull();
|
|
342
|
+
yield this.stopUpdatePull();
|
|
322
343
|
yield this.comms.close();
|
|
323
344
|
this.logEvent({ message: 'stop request completed' });
|
|
324
345
|
this.stopped = true;
|
|
@@ -389,9 +410,15 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
389
410
|
});
|
|
390
411
|
}
|
|
391
412
|
bikeSync() {
|
|
413
|
+
var _a, _b, _c;
|
|
392
414
|
return __awaiter(this, void 0, void 0, function* () {
|
|
393
|
-
|
|
394
|
-
|
|
415
|
+
if (!((_a = this.iv) === null || _a === void 0 ? void 0 : _a.stopRequested))
|
|
416
|
+
yield this.sendRequests();
|
|
417
|
+
if (!((_b = this.iv) === null || _b === void 0 ? void 0 : _b.stopRequested))
|
|
418
|
+
yield this.update();
|
|
419
|
+
if ((_c = this.iv) === null || _c === void 0 ? void 0 : _c.stopRequested) {
|
|
420
|
+
this.iv.emitter.emit('stop-done', 'bikeSync');
|
|
421
|
+
}
|
|
395
422
|
});
|
|
396
423
|
}
|
|
397
424
|
updateData(bikeData) {
|