incyclist-devices 2.1.3 → 2.1.4

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.
@@ -48,6 +48,9 @@ class AntAdapter extends adpater_1.default {
48
48
  this.updateFrequency = consts_1.DEFAULT_UPDATE_FREQUENCY;
49
49
  this.channel = undefined;
50
50
  this.ant = interface_1.default.getInstance();
51
+ if (this.isDebugEnabled()) {
52
+ this.ant.setLogger(this);
53
+ }
51
54
  }
52
55
  getProfileName() {
53
56
  const C = this.constructor;
@@ -116,12 +119,10 @@ class AntAdapter extends adpater_1.default {
116
119
  if (!ManId && deviceData.ManId) {
117
120
  this.emit('device-info', this.getSettings(), { manufacturer: (0, utils_2.getBrand)(deviceData.ManId) });
118
121
  }
119
- if (!this.started || this.isStopped())
120
- return;
121
- if (!this.canEmitData())
122
- return;
123
122
  const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
124
123
  this.logEvent({ message: 'onDeviceData', data: logData, paused: this.paused });
124
+ if (!this.started || this.isStopped() || !this.canEmitData())
125
+ return;
125
126
  if (this.isControllable()) {
126
127
  let incyclistData = this.mapData(deviceData);
127
128
  incyclistData = this.getCyclingMode().updateData(incyclistData);
@@ -148,6 +149,7 @@ class AntAdapter extends adpater_1.default {
148
149
  resolve(true);
149
150
  }
150
151
  if (!this.promiseWaitForData) {
152
+ resolve(false);
151
153
  clearInterval(iv);
152
154
  }
153
155
  }, 10);
@@ -172,9 +174,9 @@ class AntAdapter extends adpater_1.default {
172
174
  }
173
175
  try {
174
176
  this.promiseWaitForData = (0, utils_1.runWithTimeout)(this._wait(), timeout);
175
- yield this.promiseWaitForData;
177
+ const hasData = yield this.promiseWaitForData;
176
178
  this.promiseWaitForData = null;
177
- return true;
179
+ return hasData;
178
180
  }
179
181
  catch (err) {
180
182
  this.promiseWaitForData = null;
@@ -293,8 +295,10 @@ class AntAdapter extends adpater_1.default {
293
295
  else {
294
296
  this.started = false;
295
297
  const { sensorStarted, hasData, interrupted } = this.startStatus;
296
- if (interrupted)
297
- return;
298
+ if (interrupted) {
299
+ this.logEvent({ message: 'start device interrupted', device: this.getName() });
300
+ return false;
301
+ }
298
302
  if (!sensorStarted) {
299
303
  this.logEvent({ message: 'start device failed', device: this.getName(), reason: 'could not connect' });
300
304
  throw new Error('could not start device, reason:could not connect');
@@ -362,7 +366,7 @@ class AntAdapter extends adpater_1.default {
362
366
  yield this.checkCapabilities();
363
367
  if (this.hasCapability(types_2.IncyclistCapability.Control))
364
368
  yield this.initControl();
365
- if (!this.startStatus.hasData) {
369
+ if (!this.startStatus.hasData && !this.startStatus.interrupted) {
366
370
  yield this.stopSensor();
367
371
  yield (0, utils_1.sleep)(retryDelay);
368
372
  continue;
@@ -388,7 +392,7 @@ class AntAdapter extends adpater_1.default {
388
392
  }
389
393
  throw err;
390
394
  }
391
- return true;
395
+ return this.started;
392
396
  });
393
397
  }
394
398
  stop() {
@@ -396,8 +400,11 @@ class AntAdapter extends adpater_1.default {
396
400
  let stopped;
397
401
  this.logger.logEvent({ message: 'stopping device', device: this.getName() });
398
402
  this.promiseWaitForData = null;
399
- if (this.startStatus)
403
+ if (this.startStatus) {
400
404
  this.startStatus.interrupted = true;
405
+ console.log('~~~ still starting');
406
+ yield (0, utils_1.sleep)(20);
407
+ }
401
408
  try {
402
409
  stopped = yield this.ant.stopSensor(this.sensor);
403
410
  }
@@ -5,6 +5,7 @@ import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types"
5
5
  import { IncyclistBikeData, ControllerConfig } from "../../types";
6
6
  interface AntFEStartDeviceProperties extends AntDeviceProperties {
7
7
  reconnect?: boolean;
8
+ restart?: boolean;
8
9
  reconnectTimeout?: number;
9
10
  }
10
11
  export default class AntFEAdapter extends AntAdapter<FitnessEquipmentSensorState> {
@@ -123,12 +123,18 @@ class AntFEAdapter extends adapter_1.default {
123
123
  resetStartStatus() {
124
124
  const props = this.startProps;
125
125
  const isReconnect = props.reconnect || false;
126
+ const isRestart = props.restart || false;
126
127
  super.resetStartStatus();
127
128
  if (isReconnect) {
128
129
  delete props.reconnect;
129
130
  this.startStatus.userInitialized = true;
130
131
  this.startStatus.controlInitialized = true;
131
132
  }
133
+ if (isRestart) {
134
+ delete props.restart;
135
+ this.startStatus.sensorStarted = true;
136
+ this.startStatus.hasData = true;
137
+ }
132
138
  }
133
139
  startPreChecks(props) {
134
140
  const _super = Object.create(null, {
@@ -137,6 +143,11 @@ class AntFEAdapter extends adapter_1.default {
137
143
  return __awaiter(this, void 0, void 0, function* () {
138
144
  this.startProps = props;
139
145
  this.setFEDefaultTimeout();
146
+ if (this.started && this.paused) {
147
+ this.resume();
148
+ props.restart = true;
149
+ return 'connected';
150
+ }
140
151
  return yield _super.startPreChecks.call(this, props);
141
152
  });
142
153
  }
@@ -20,6 +20,7 @@ export default class IncyclistDevice<P extends DeviceProperties> extends EventEm
20
20
  protected data: IncyclistAdapterData;
21
21
  constructor(settings: DeviceSettings, props?: P);
22
22
  getLogger(): EventLogger;
23
+ isDebugEnabled(): boolean;
23
24
  logEvent(event: any): void;
24
25
  getName(): string;
25
26
  getID(): string;
@@ -30,12 +30,18 @@ class IncyclistDevice extends events_1.default {
30
30
  this.cyclingMode = this.getDefaultCyclingMode();
31
31
  }
32
32
  getLogger() { return this.logger; }
33
+ isDebugEnabled() {
34
+ const w = global.window;
35
+ if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG || process.env.ANT_DEBUG) {
36
+ return true;
37
+ }
38
+ return false;
39
+ }
33
40
  logEvent(event) {
34
41
  if (!this.logger || this.paused)
35
42
  return;
36
43
  this.logger.logEvent(event);
37
- const w = global.window;
38
- if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG || process.env.ANT_DEBUG) {
44
+ if (this.isDebugEnabled()) {
39
45
  const logText = `~~~ ${this.getInterface()}: ${this.logger.getName()}`;
40
46
  console.log(logText, event);
41
47
  }
@@ -63,14 +69,16 @@ class IncyclistDevice extends events_1.default {
63
69
  stop() { throw new Error("Method not implemented."); }
64
70
  pause() {
65
71
  return __awaiter(this, void 0, void 0, function* () {
66
- this.logEvent({ message: 'pausing device', device: this.getName() });
72
+ if (this.isStarted() && !this.isStopped())
73
+ this.logEvent({ message: 'pausing device', device: this.getName() });
67
74
  this.paused = true;
68
75
  return true;
69
76
  });
70
77
  }
71
78
  resume() {
72
79
  return __awaiter(this, void 0, void 0, function* () {
73
- this.logger.logEvent({ message: 'resuming device', device: this.getName() });
80
+ if (this.isStarted() && !this.isStopped())
81
+ this.logger.logEvent({ message: 'resuming device', device: this.getName() });
74
82
  this.paused = false;
75
83
  return true;
76
84
  });
@@ -36,7 +36,7 @@ class Simulator extends adpater_1.default {
36
36
  this.setCyclingMode(name, modeSettings);
37
37
  this.capabilities = [
38
38
  types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence, types_1.IncyclistCapability.Gear,
39
- types_1.IncyclistCapability.Control
39
+ types_1.IncyclistCapability.Control, types_1.IncyclistCapability.HeartRate
40
40
  ];
41
41
  }
42
42
  isEqual(settings) {
@@ -53,12 +53,13 @@ class Simulator extends adpater_1.default {
53
53
  start(props) {
54
54
  return __awaiter(this, void 0, void 0, function* () {
55
55
  this.startProps = props;
56
+ this.stopped = false;
56
57
  this.paused = false;
57
58
  if (props)
58
59
  this.setBikeProps(props);
59
60
  return new Promise((resolve) => {
60
61
  if (!this.isBot)
61
- this.logger.logEvent({ message: 'start', iv: this.iv });
62
+ this.logEvent({ message: 'starting device', device: this.getName(), props });
62
63
  if (this.started) {
63
64
  return resolve(true);
64
65
  }
@@ -94,32 +95,31 @@ class Simulator extends adpater_1.default {
94
95
  });
95
96
  }
96
97
  pause() {
97
- return new Promise((resolve, reject) => {
98
- if (!this.started)
99
- return reject(new Error('illegal state - pause() has been called before start()'));
100
- if (!this.isBot)
101
- this.logger.logEvent({ message: 'pause', iv: this.iv });
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ if (!this.isBot && this.isStarted())
100
+ this.logEvent({ message: 'pausing device', device: this.getName() });
102
101
  this.paused = true;
103
- resolve(true);
102
+ return true;
104
103
  });
105
104
  }
106
105
  resume() {
107
- return new Promise((resolve, reject) => {
108
- if (!this.started)
109
- reject(new Error('illegal state - resume() has been called before start()'));
110
- if (!this.isBot)
111
- this.logger.logEvent({ message: 'resume', iv: this.iv });
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ if (!this.isBot && this.isStarted())
108
+ this.logger.logEvent({ message: 'resuming device', device: this.getName() });
112
109
  this.paused = false;
113
- resolve(true);
110
+ return true;
114
111
  });
115
112
  }
116
113
  toggle() {
117
- if (this.started) {
118
- return this.stop();
119
- }
120
- else {
121
- return this.start().then(() => { return true; });
122
- }
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ if (this.started) {
116
+ return yield this.stop();
117
+ }
118
+ else {
119
+ yield this.start();
120
+ return true;
121
+ }
122
+ });
123
123
  }
124
124
  faster() {
125
125
  if (this.speed < 15)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",