incyclist-devices 1.4.35 → 1.4.36

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.
@@ -84,22 +84,26 @@ class BleInterface extends ble_1.BleInterfaceClass {
84
84
  try {
85
85
  if (!this.connectState.isInitSuccess) {
86
86
  const binding = this.getBinding()._bindings;
87
- const binding_init_original = binding.init.bind(binding);
88
- const self = this;
89
- binding.on('error', (err) => { this.getBinding().emit('error', err); });
90
- binding.init = function () {
91
- try {
92
- binding_init_original();
93
- self.connectState.isInitSuccess = true;
94
- }
95
- catch (err) {
96
- self.connectState.isInitSuccess = false;
97
- self.connectState.isConnected = false;
98
- self.connectState.isConnecting = false;
99
- self.logEvent({ message: 'connect result: error', error: err.message });
100
- return reject(new Error(err.message));
101
- }
102
- };
87
+ if (binding) {
88
+ const binding_init_original = binding.init.bind(binding);
89
+ const self = this;
90
+ binding.on('error', (err) => { this.getBinding().emit('error', err); });
91
+ binding.init = function () {
92
+ try {
93
+ binding_init_original();
94
+ self.connectState.isInitSuccess = true;
95
+ }
96
+ catch (err) {
97
+ self.connectState.isInitSuccess = false;
98
+ self.connectState.isConnected = false;
99
+ self.connectState.isConnecting = false;
100
+ self.logEvent({ message: 'connect result: error', error: err.message });
101
+ return reject(new Error(err.message));
102
+ }
103
+ };
104
+ }
105
+ else {
106
+ }
103
107
  }
104
108
  const state = this.getBinding().state;
105
109
  if (state === ble_1.BleState.POWERED_ON) {
@@ -280,8 +284,10 @@ class BleInterface extends ble_1.BleInterfaceClass {
280
284
  }
281
285
  const detectedPeripherals = {};
282
286
  this.devices = [];
283
- if (scanForDevice)
284
- this.logEvent({ message: 'search device request', device, deviceTypes });
287
+ if (scanForDevice) {
288
+ const { id, address, name } = device;
289
+ this.logEvent({ message: 'search device request', device: { id, address, name }, deviceTypes });
290
+ }
285
291
  else
286
292
  this.logEvent({ message: 'scan start', services });
287
293
  return new Promise((resolve, reject) => {
package/lib/ble/hrm.d.ts CHANGED
@@ -19,7 +19,7 @@ export default class BleHrmDevice extends BleDevice {
19
19
  constructor(props?: any);
20
20
  getProfile(): string;
21
21
  getServiceUUids(): string[];
22
- parseHrm(data: Buffer): HrmData;
22
+ parseHrm(_data: Uint8Array): HrmData;
23
23
  onData(characteristic: string, data: Buffer): void;
24
24
  write(characteristic: any, data: any): Promise<boolean>;
25
25
  read(characteristic: any): Promise<Buffer>;
package/lib/ble/hrm.js CHANGED
@@ -28,20 +28,20 @@ class BleHrmDevice extends ble_device_1.BleDevice {
28
28
  getServiceUUids() {
29
29
  return BleHrmDevice.services;
30
30
  }
31
- parseHrm(data) {
31
+ parseHrm(_data) {
32
+ const data = Buffer.from(_data);
32
33
  try {
33
- const ab = new Uint8Array(data);
34
- const flags = ab[0];
35
- let offset = 1;
34
+ const flags = data.readUInt8(0);
35
+ let offset = 2;
36
36
  if (flags % 1 === 0) {
37
- this.heartrate = ab[1];
37
+ this.heartrate = data.readUInt8(1);
38
38
  }
39
39
  else {
40
- this.heartrate = ab[1] + ab[2] * 256;
41
- offset = 2;
40
+ this.heartrate = data.readUInt16LE(1);
41
+ offset = 3;
42
42
  }
43
43
  if (flags % 0xF) {
44
- this.rr = (ab[offset + 1] + ab[offset + 2] * 256) / 1024;
44
+ this.rr = (data.readUInt16LE(offset)) / 1024;
45
45
  }
46
46
  }
47
47
  catch (err) {
package/lib/ble/pwr.d.ts CHANGED
@@ -14,7 +14,7 @@ declare type PowerData = {
14
14
  accTorque?: number;
15
15
  time: number;
16
16
  rpm: number;
17
- raw?: Buffer;
17
+ raw?: string;
18
18
  };
19
19
  declare type CrankData = {
20
20
  revolutions?: number;
@@ -39,7 +39,7 @@ export default class BleCyclingPowerDevice extends BleDevice {
39
39
  rpm: number;
40
40
  time: any;
41
41
  };
42
- parsePower(data: Buffer): PowerData;
42
+ parsePower(_data: Uint8Array): PowerData;
43
43
  onData(characteristic: string, data: Buffer): void;
44
44
  write(characteristic: any, data: any): Promise<boolean>;
45
45
  read(characteristic: any): Promise<Buffer>;
package/lib/ble/pwr.js CHANGED
@@ -66,7 +66,8 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
66
66
  this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
67
67
  return { rpm, time: this.timeOffset + c.time };
68
68
  }
69
- parsePower(data) {
69
+ parsePower(_data) {
70
+ const data = Buffer.from(_data);
70
71
  try {
71
72
  let offset = 4;
72
73
  const flags = data.readUInt16LE(0);
@@ -91,7 +92,7 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
91
92
  catch (err) {
92
93
  }
93
94
  const { instantaneousPower, balance, accTorque, rpm, time } = this;
94
- return { instantaneousPower, balance, accTorque, rpm, time, raw: data };
95
+ return { instantaneousPower, balance, accTorque, rpm, time, raw: data.toString('hex') };
95
96
  }
96
97
  onData(characteristic, data) {
97
98
  if (characteristic.toLocaleLowerCase() === '2a63') {
@@ -176,7 +177,7 @@ class PwrAdapter extends Device_1.default {
176
177
  const data = {
177
178
  isPedalling: false,
178
179
  power: 0,
179
- pedalRpm: 0,
180
+ pedalRpm: undefined,
180
181
  speed: 0,
181
182
  heartrate: 0,
182
183
  distanceInternal: 0,
@@ -47,7 +47,7 @@ class PowerMeterCyclingMode extends power_base_1.default {
47
47
  let power = bikeData.power || 0;
48
48
  const slope = prevData.slope || 0;
49
49
  const distanceInternal = prevData.distanceInternal || 0;
50
- if (!bikeData.pedalRpm || bikeData.isPedalling === false) {
50
+ if (bikeData.pedalRpm === 0 || bikeData.isPedalling === false) {
51
51
  power = 0;
52
52
  }
53
53
  const m = this.getWeight();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.4.35",
3
+ "version": "1.4.36",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",