incyclist-devices 1.4.65 → 1.4.66

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.
@@ -47,7 +47,9 @@ class BleDevice extends ble_1.BleDeviceClass {
47
47
  if (this.logger) {
48
48
  this.logger.logEvent(event);
49
49
  }
50
- console.log('~~~BLE:', event);
50
+ if (process.env.BLE_DEBUG) {
51
+ console.log('~~~BLE:', event);
52
+ }
51
53
  }
52
54
  setLogger(logger) {
53
55
  this.logger = logger;
@@ -244,7 +246,6 @@ class BleDevice extends ble_1.BleDeviceClass {
244
246
  if (writeIdx !== -1) {
245
247
  const writeItem = this.writeQueue[writeIdx];
246
248
  this.writeQueue.splice(writeIdx, 1);
247
- console.log('~~~ write queue', this.writeQueue);
248
249
  if (writeItem.resolve)
249
250
  writeItem.resolve(data);
250
251
  }
@@ -255,9 +256,9 @@ class BleDevice extends ble_1.BleDeviceClass {
255
256
  try {
256
257
  const connector = this.ble.getConnector(this.peripheral);
257
258
  const isAlreadySubscribed = connector.isSubscribed(characteristicUuid);
258
- console.log('~~~ write ', characteristicUuid, data.toString('hex'), isAlreadySubscribed, this.subscribedCharacteristics);
259
259
  if (!withoutResponse && !isAlreadySubscribed) {
260
260
  const connector = this.ble.getConnector(this.peripheral);
261
+ connector.removeAllListeners(characteristicUuid);
261
262
  connector.on(characteristicUuid, (uuid, data) => {
262
263
  this.onData(uuid, data);
263
264
  });
@@ -287,7 +288,7 @@ class BleDevice extends ble_1.BleDeviceClass {
287
288
  this.writeQueue.splice(writeId, 1);
288
289
  this.logEvent({ message: 'writing response', err: 'timeout' });
289
290
  reject(new Error('timeout'));
290
- }, 1000);
291
+ }, 5000);
291
292
  this.logEvent({ message: 'writing' });
292
293
  characteristic.write(data, withoutResponse, (err) => {
293
294
  clearTimeout(to);
@@ -31,7 +31,9 @@ class BlePeripheralConnector {
31
31
  if (this.logger) {
32
32
  this.logger.logEvent(event);
33
33
  }
34
- console.log('~~~BLE:', event);
34
+ if (process.env.BLE_DEBUG) {
35
+ console.log('~~~BLE:', event);
36
+ }
35
37
  }
36
38
  connect() {
37
39
  return __awaiter(this, void 0, void 0, function* () {
@@ -110,7 +112,6 @@ class BlePeripheralConnector {
110
112
  try {
111
113
  yield this.subscribe(c.uuid);
112
114
  subscribed.push(c.uuid);
113
- this.state.subscribed.push(c.uuid);
114
115
  }
115
116
  catch (err) {
116
117
  this.logEvent({ message: 'cannot subscribe', peripheral: this.peripheral.address, characteristic: c.uuid, error: err.message || err });
@@ -137,6 +138,7 @@ class BlePeripheralConnector {
137
138
  reject(new Error('Characteristic not found'));
138
139
  return;
139
140
  }
141
+ characteristic.removeAllListeners('data');
140
142
  characteristic.on('data', (data, _isNotification) => {
141
143
  this.onData(characteristicUuid, data);
142
144
  });
@@ -149,8 +151,10 @@ class BlePeripheralConnector {
149
151
  this.logEvent({ message: 'subscribe result', characteristic: characteristicUuid, error: err });
150
152
  if (err)
151
153
  reject(err);
152
- else
154
+ else {
155
+ this.state.subscribed.push(characteristicUuid);
153
156
  resolve(true);
157
+ }
154
158
  });
155
159
  }
156
160
  catch (err) {
package/lib/ble/fm.js CHANGED
@@ -100,6 +100,23 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
100
100
  });
101
101
  return __awaiter(this, void 0, void 0, function* () {
102
102
  try {
103
+ const connector = this.ble.getConnector(this.peripheral);
104
+ const isAlreadySubscribed = connector.isSubscribed(FTMS_CP);
105
+ if (!isAlreadySubscribed) {
106
+ connector.removeAllListeners(FTMS_CP);
107
+ let prev = undefined;
108
+ let prevTS = undefined;
109
+ connector.on(FTMS_CP, (uuid, data) => {
110
+ const message = data.toString('hex');
111
+ if (prevTS && prev && message === prev && Date.now() - prevTS < 500) {
112
+ return;
113
+ }
114
+ prevTS = Date.now();
115
+ prev = message;
116
+ this.onData(uuid, data);
117
+ });
118
+ yield connector.subscribe(FTMS_CP);
119
+ }
103
120
  this.logEvent({ message: 'get device info' });
104
121
  yield _super.init.call(this);
105
122
  yield this.getFitnessMachineFeatures();
@@ -36,7 +36,7 @@ const ble_interface_1 = __importDefault(require("./ble-interface"));
36
36
  const Device_1 = require("../Device");
37
37
  const gd_eventlog_1 = require("gd-eventlog");
38
38
  const fm_1 = __importStar(require("./fm"));
39
- const WAHOO_ADVANCED_FTMS = 'a026e005';
39
+ const WAHOO_ADVANCED_FTMS = 'a026e00b';
40
40
  const WAHOO_ADVANCED_TRAINER_CP = 'a026e037';
41
41
  const cwABike = {
42
42
  race: 0.35,
@@ -60,6 +60,23 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
60
60
  });
61
61
  return __awaiter(this, void 0, void 0, function* () {
62
62
  try {
63
+ const connector = this.ble.getConnector(this.peripheral);
64
+ const isAlreadySubscribed = connector.isSubscribed(WAHOO_ADVANCED_TRAINER_CP);
65
+ if (!isAlreadySubscribed) {
66
+ connector.removeAllListeners(WAHOO_ADVANCED_TRAINER_CP);
67
+ let prev = undefined;
68
+ let prevTS = undefined;
69
+ connector.on(WAHOO_ADVANCED_TRAINER_CP, (uuid, data) => {
70
+ const message = data.toString('hex');
71
+ if (prevTS && prev && message === prev && Date.now() - prevTS < 500) {
72
+ return;
73
+ }
74
+ prevTS = Date.now();
75
+ prev = message;
76
+ this.onData(uuid, data);
77
+ });
78
+ yield connector.subscribe(WAHOO_ADVANCED_TRAINER_CP);
79
+ }
63
80
  this.logEvent({ message: 'get device info' });
64
81
  yield _super.init.call(this);
65
82
  this.logEvent({ message: 'device info', deviceInfo: this.deviceInfo, features: this.features });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.4.65",
3
+ "version": "1.4.66",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",