incyclist-devices 2.1.10 → 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;
|
|
@@ -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);
|
|
@@ -247,17 +248,34 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
247
248
|
}, this.pullFrequency);
|
|
248
249
|
this.iv = {
|
|
249
250
|
sync: ivSync,
|
|
250
|
-
update: ivUpdate
|
|
251
|
+
update: ivUpdate,
|
|
252
|
+
emitter: new events_1.default()
|
|
251
253
|
};
|
|
254
|
+
this.iv.emitter.once('stop', () => {
|
|
255
|
+
this.iv.stopRequested = true;
|
|
256
|
+
});
|
|
252
257
|
}
|
|
253
|
-
|
|
254
|
-
if (!this.iv)
|
|
255
|
-
return;
|
|
256
|
-
this.logEvent({ message: 'stop update pull', port: this.getPort() });
|
|
258
|
+
cleanupInterval() {
|
|
257
259
|
clearInterval(this.iv.sync);
|
|
258
260
|
clearInterval(this.iv.update);
|
|
261
|
+
this.iv.emitter.removeAllListeners();
|
|
259
262
|
this.iv = undefined;
|
|
260
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
|
+
}
|
|
261
279
|
connect() {
|
|
262
280
|
return __awaiter(this, void 0, void 0, function* () {
|
|
263
281
|
if (!this.comms)
|
|
@@ -321,7 +339,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
321
339
|
if (this.paused)
|
|
322
340
|
this.resume();
|
|
323
341
|
try {
|
|
324
|
-
this.stopUpdatePull();
|
|
342
|
+
yield this.stopUpdatePull();
|
|
325
343
|
yield this.comms.close();
|
|
326
344
|
this.logEvent({ message: 'stop request completed' });
|
|
327
345
|
this.stopped = true;
|
|
@@ -392,9 +410,15 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
392
410
|
});
|
|
393
411
|
}
|
|
394
412
|
bikeSync() {
|
|
413
|
+
var _a, _b, _c;
|
|
395
414
|
return __awaiter(this, void 0, void 0, function* () {
|
|
396
|
-
|
|
397
|
-
|
|
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
|
+
}
|
|
398
422
|
});
|
|
399
423
|
}
|
|
400
424
|
updateData(bikeData) {
|