Added RSSI back in, as reported by the hub
This commit is contained in:
parent
3a816b9f11
commit
e96b7bd47d
10
src/hub.ts
10
src/hub.ts
@ -30,6 +30,7 @@ export class Hub extends EventEmitter {
|
||||
protected _batteryLevel: number = 100;
|
||||
protected _voltage: number = 0;
|
||||
protected _current: number = 0;
|
||||
protected _rssi: number = -60;
|
||||
|
||||
protected _bleDevice: IBLEDevice;
|
||||
|
||||
@ -100,6 +101,15 @@ export class Hub extends EventEmitter {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {number} rssi Signal strength of the hub
|
||||
*/
|
||||
public get rssi () {
|
||||
return this._rssi;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {number} voltage Voltage of the hub (Volts)
|
||||
|
@ -58,6 +58,7 @@ export class LPF2Hub extends Hub {
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x02, 0x02])); // Activate button reports
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x03, 0x05])); // Request firmware version
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x04, 0x05])); // Request hardware version
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x05, 0x02])); // Activate RSSI updates
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x06, 0x02])); // Activate battery level reports
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x0d, 0x05])); // Request primary MAC address
|
||||
this.emit("connect");
|
||||
@ -269,6 +270,14 @@ export class LPF2Hub extends Hub {
|
||||
} else if (data[3] === 0x04) {
|
||||
this._hardwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5));
|
||||
|
||||
// RSSI update
|
||||
} else if (data[3] === 0x05) {
|
||||
const rssi = data.readInt8(5);
|
||||
if (rssi !== 0) {
|
||||
this._rssi = rssi;
|
||||
this.emit("rssiChange", this._rssi);
|
||||
}
|
||||
|
||||
// primary MAC Address
|
||||
} else if (data[3] === 0x0d) {
|
||||
this._primaryMACAddress = LPF2Hub.decodeMACAddress(data.slice(4, 10));
|
||||
|
@ -28,7 +28,7 @@ export class NobleDevice extends EventEmitter implements IBLEDevice {
|
||||
this._noblePeripheral = device;
|
||||
this._uuid = device.uuid;
|
||||
device.on("disconnect", () => {
|
||||
this._connected = false;
|
||||
this._connecting = false;
|
||||
this._connected = false;
|
||||
this.emit("disconnect");
|
||||
});
|
||||
|
@ -27,7 +27,7 @@ export class WebBLEDevice extends EventEmitter implements IBLEDevice {
|
||||
this._uuid = device.device.id;
|
||||
this._name = device.device.name;
|
||||
device.device.addEventListener("gattserverdisconnected", () => {
|
||||
this._connected = false;
|
||||
this._connecting = false;
|
||||
this._connected = false;
|
||||
this.emit("disconnect");
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user