Battery level and current of lpf2 hubs
This commit is contained in:
parent
d917f9cb12
commit
a20fbe7d70
180
DOCS.md
180
DOCS.md
@ -72,6 +72,11 @@ Emits when a LPF2 Hub device is found.
|
||||
|
||||
* [LPF2Hub](#LPF2Hub) ⇐ [<code>Hub</code>](#Hub)
|
||||
* [new LPF2Hub()](#new_LPF2Hub_new)
|
||||
* [.name](#Hub+name)
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.current](#Hub+current)
|
||||
* [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.setMotorSpeed(port, speed, [time])](#LPF2Hub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.setMotorAngle(port, angle, [speed])](#LPF2Hub+setMotorAngle) ⇒ <code>Promise</code>
|
||||
@ -94,6 +99,61 @@ Emits when a LPF2 Hub device is found.
|
||||
### new LPF2Hub()
|
||||
The LPF2Hub is emitted if the discovered device is either a Boost Move Hub, Powered Up Hub, or Powered Up Remote.
|
||||
|
||||
<a name="Hub+name"></a>
|
||||
|
||||
### lpF2Hub.name
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | Name of the hub |
|
||||
|
||||
<a name="Hub+uuid"></a>
|
||||
|
||||
### lpF2Hub.uuid
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| uuid | <code>string</code> | UUID of the hub |
|
||||
|
||||
<a name="Hub+rssi"></a>
|
||||
|
||||
### lpF2Hub.rssi
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| rssi | <code>number</code> | Signal strength of the hub |
|
||||
|
||||
<a name="Hub+batteryLevel"></a>
|
||||
|
||||
### lpF2Hub.batteryLevel
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="Hub+current"></a>
|
||||
|
||||
### lpF2Hub.current
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| current | <code>number</code> | Current usage of the hub (Amps) |
|
||||
|
||||
<a name="LPF2Hub+setLEDColor"></a>
|
||||
|
||||
### lpF2Hub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
@ -294,6 +354,11 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
|
||||
* [WeDo2Hub](#WeDo2Hub) ⇐ [<code>Hub</code>](#Hub)
|
||||
* [new WeDo2Hub()](#new_WeDo2Hub_new)
|
||||
* [.name](#Hub+name)
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.current](#Hub+current)
|
||||
* [.setLEDColor(color)](#WeDo2Hub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.setLEDRGB(red, green, blue)](#WeDo2Hub+setLEDRGB) ⇒ <code>Promise</code>
|
||||
* [.setMotorSpeed(port, speed, [time])](#WeDo2Hub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
@ -317,6 +382,61 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
### new WeDo2Hub()
|
||||
The WeDo2Hub is emitted if the discovered device is a WeDo 2.0 Smart Hub.
|
||||
|
||||
<a name="Hub+name"></a>
|
||||
|
||||
### weDo2Hub.name
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | Name of the hub |
|
||||
|
||||
<a name="Hub+uuid"></a>
|
||||
|
||||
### weDo2Hub.uuid
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| uuid | <code>string</code> | UUID of the hub |
|
||||
|
||||
<a name="Hub+rssi"></a>
|
||||
|
||||
### weDo2Hub.rssi
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| rssi | <code>number</code> | Signal strength of the hub |
|
||||
|
||||
<a name="Hub+batteryLevel"></a>
|
||||
|
||||
### weDo2Hub.batteryLevel
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="Hub+current"></a>
|
||||
|
||||
### weDo2Hub.current
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| current | <code>number</code> | Current usage of the hub (Amps) |
|
||||
|
||||
<a name="WeDo2Hub+setLEDColor"></a>
|
||||
|
||||
### weDo2Hub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
@ -529,6 +649,11 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
**Extends**: <code>EventEmitter</code>
|
||||
|
||||
* [Hub](#Hub) ⇐ <code>EventEmitter</code>
|
||||
* [.name](#Hub+name)
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.current](#Hub+current)
|
||||
* [.connect()](#Hub+connect) ⇒ <code>Promise</code>
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
@ -538,6 +663,61 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
* ["attach" (port, type)](#Hub+event_attach)
|
||||
* ["detach" (port)](#Hub+event_detach)
|
||||
|
||||
<a name="Hub+name"></a>
|
||||
|
||||
### hub.name
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | Name of the hub |
|
||||
|
||||
<a name="Hub+uuid"></a>
|
||||
|
||||
### hub.uuid
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| uuid | <code>string</code> | UUID of the hub |
|
||||
|
||||
<a name="Hub+rssi"></a>
|
||||
|
||||
### hub.rssi
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| rssi | <code>number</code> | Signal strength of the hub |
|
||||
|
||||
<a name="Hub+batteryLevel"></a>
|
||||
|
||||
### hub.batteryLevel
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="Hub+current"></a>
|
||||
|
||||
### hub.current
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| current | <code>number</code> | Current usage of the hub (Amps) |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
### hub.connect() ⇒ <code>Promise</code>
|
||||
|
180
README.md
180
README.md
@ -122,6 +122,11 @@ Emits when a LPF2 Hub device is found.
|
||||
|
||||
* [LPF2Hub](#LPF2Hub) ⇐ [<code>Hub</code>](#Hub)
|
||||
* [new LPF2Hub()](#new_LPF2Hub_new)
|
||||
* [.name](#Hub+name)
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.current](#Hub+current)
|
||||
* [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.setMotorSpeed(port, speed, [time])](#LPF2Hub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.setMotorAngle(port, angle, [speed])](#LPF2Hub+setMotorAngle) ⇒ <code>Promise</code>
|
||||
@ -144,6 +149,61 @@ Emits when a LPF2 Hub device is found.
|
||||
### new LPF2Hub()
|
||||
The LPF2Hub is emitted if the discovered device is either a Boost Move Hub, Powered Up Hub, or Powered Up Remote.
|
||||
|
||||
<a name="Hub+name"></a>
|
||||
|
||||
### lpF2Hub.name
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | Name of the hub |
|
||||
|
||||
<a name="Hub+uuid"></a>
|
||||
|
||||
### lpF2Hub.uuid
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| uuid | <code>string</code> | UUID of the hub |
|
||||
|
||||
<a name="Hub+rssi"></a>
|
||||
|
||||
### lpF2Hub.rssi
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| rssi | <code>number</code> | Signal strength of the hub |
|
||||
|
||||
<a name="Hub+batteryLevel"></a>
|
||||
|
||||
### lpF2Hub.batteryLevel
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="Hub+current"></a>
|
||||
|
||||
### lpF2Hub.current
|
||||
**Kind**: instance property of [<code>LPF2Hub</code>](#LPF2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| current | <code>number</code> | Current usage of the hub (Amps) |
|
||||
|
||||
<a name="LPF2Hub+setLEDColor"></a>
|
||||
|
||||
### lpF2Hub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
@ -344,6 +404,11 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
|
||||
* [WeDo2Hub](#WeDo2Hub) ⇐ [<code>Hub</code>](#Hub)
|
||||
* [new WeDo2Hub()](#new_WeDo2Hub_new)
|
||||
* [.name](#Hub+name)
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.current](#Hub+current)
|
||||
* [.setLEDColor(color)](#WeDo2Hub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.setLEDRGB(red, green, blue)](#WeDo2Hub+setLEDRGB) ⇒ <code>Promise</code>
|
||||
* [.setMotorSpeed(port, speed, [time])](#WeDo2Hub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
@ -367,6 +432,61 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
### new WeDo2Hub()
|
||||
The WeDo2Hub is emitted if the discovered device is a WeDo 2.0 Smart Hub.
|
||||
|
||||
<a name="Hub+name"></a>
|
||||
|
||||
### weDo2Hub.name
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | Name of the hub |
|
||||
|
||||
<a name="Hub+uuid"></a>
|
||||
|
||||
### weDo2Hub.uuid
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| uuid | <code>string</code> | UUID of the hub |
|
||||
|
||||
<a name="Hub+rssi"></a>
|
||||
|
||||
### weDo2Hub.rssi
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| rssi | <code>number</code> | Signal strength of the hub |
|
||||
|
||||
<a name="Hub+batteryLevel"></a>
|
||||
|
||||
### weDo2Hub.batteryLevel
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="Hub+current"></a>
|
||||
|
||||
### weDo2Hub.current
|
||||
**Kind**: instance property of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| current | <code>number</code> | Current usage of the hub (Amps) |
|
||||
|
||||
<a name="WeDo2Hub+setLEDColor"></a>
|
||||
|
||||
### weDo2Hub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
@ -579,6 +699,11 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
**Extends**: <code>EventEmitter</code>
|
||||
|
||||
* [Hub](#Hub) ⇐ <code>EventEmitter</code>
|
||||
* [.name](#Hub+name)
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.current](#Hub+current)
|
||||
* [.connect()](#Hub+connect) ⇒ <code>Promise</code>
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
@ -588,6 +713,61 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
* ["attach" (port, type)](#Hub+event_attach)
|
||||
* ["detach" (port)](#Hub+event_detach)
|
||||
|
||||
<a name="Hub+name"></a>
|
||||
|
||||
### hub.name
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | Name of the hub |
|
||||
|
||||
<a name="Hub+uuid"></a>
|
||||
|
||||
### hub.uuid
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| uuid | <code>string</code> | UUID of the hub |
|
||||
|
||||
<a name="Hub+rssi"></a>
|
||||
|
||||
### hub.rssi
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| rssi | <code>number</code> | Signal strength of the hub |
|
||||
|
||||
<a name="Hub+batteryLevel"></a>
|
||||
|
||||
### hub.batteryLevel
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="Hub+current"></a>
|
||||
|
||||
### hub.current
|
||||
**Kind**: instance property of [<code>Hub</code>](#Hub)
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| current | <code>number</code> | Current usage of the hub (Amps) |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
### hub.connect() ⇒ <code>Promise</code>
|
||||
|
59
hub.ts
59
hub.ts
@ -19,22 +19,69 @@ export class Hub extends EventEmitter {
|
||||
public autoSubscribe: boolean = true;
|
||||
public useSpeedMap: boolean = true;
|
||||
public type: Consts.Hubs = Consts.Hubs.UNKNOWN;
|
||||
public uuid: string;
|
||||
public name: string;
|
||||
|
||||
protected _ports: {[port: string]: Port} = {};
|
||||
protected _characteristics: {[uuid: string]: Characteristic} = {};
|
||||
|
||||
protected _name: string;
|
||||
protected _batteryLevel: number = 100;
|
||||
protected _current: number = 0;
|
||||
|
||||
private _peripheral: Peripheral;
|
||||
private _uuid: string;
|
||||
private _rssi: number = -100;
|
||||
private _batteryLevel: number = 100;
|
||||
|
||||
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
||||
super();
|
||||
this.autoSubscribe = !!autoSubscribe;
|
||||
this._peripheral = peripheral;
|
||||
this.uuid = peripheral.uuid;
|
||||
this.name = peripheral.advertisement.localName;
|
||||
this._uuid = peripheral.uuid;
|
||||
this._name = peripheral.advertisement.localName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {string} name Name of the hub
|
||||
*/
|
||||
public get name () {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {string} uuid UUID of the hub
|
||||
*/
|
||||
public get uuid () {
|
||||
return this._uuid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {number} rssi Signal strength of the hub
|
||||
*/
|
||||
public get rssi () {
|
||||
return this._rssi;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {number} batteryLevel Battery level of the hub (Percentage between 0-100)
|
||||
*/
|
||||
public get batteryLevel () {
|
||||
return this._batteryLevel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {number} current Current usage of the hub (Amps)
|
||||
*/
|
||||
public get current () {
|
||||
return this._current;
|
||||
}
|
||||
|
||||
|
||||
@ -57,8 +104,6 @@ export class Hub extends EventEmitter {
|
||||
if (!err) {
|
||||
if (this._rssi !== rssi) {
|
||||
this._rssi = rssi;
|
||||
debug(`RSSI change ${rssi}`);
|
||||
self.emit("rssiChange", rssi);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
30
lpf2hub.ts
30
lpf2hub.ts
@ -76,7 +76,9 @@ export class LPF2Hub extends Hub {
|
||||
await super.connect();
|
||||
const characteristic = this._characteristics[Consts.BLECharacteristics.BOOST_ALL];
|
||||
this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this));
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, Buffer.from([0x05, 0x00, 0x01, 0x02, 0x02]));
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, Buffer.from([0x05, 0x00, 0x01, 0x02, 0x02])); // Activate button reports
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, Buffer.from([0x0a, 0x00, 0x41, 0x3b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate current reports
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, Buffer.from([0x0a, 0x00, 0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
|
||||
debug("Connect completed");
|
||||
return resolve();
|
||||
});
|
||||
@ -296,8 +298,34 @@ export class LPF2Hub extends Hub {
|
||||
}
|
||||
|
||||
|
||||
private _padMessage (data: Buffer, len: number) {
|
||||
if (data.length < len) {
|
||||
data = Buffer.concat([data, Buffer.alloc(len - data.length)]);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private _parseSensorMessage (data: Buffer) {
|
||||
|
||||
if (data[3] === 0x3c) { // Voltage
|
||||
data = this._padMessage(data, 6);
|
||||
let batteryLevel = (data.readUInt16LE(4) / 4096) * 100;
|
||||
if (this.type === Consts.Hubs.POWERED_UP_REMOTE) {
|
||||
batteryLevel = (100 / 5.1) * ((data.readUInt16LE(4) / 4096) * 100);
|
||||
}
|
||||
this._batteryLevel = Math.floor(batteryLevel);
|
||||
return;
|
||||
} else if (data[3] === 0x3b) { // Current
|
||||
data = this._padMessage(data, 6);
|
||||
let current = data.readUInt16LE(4) / 4096;
|
||||
if (this.type === Consts.Hubs.POWERED_UP_REMOTE) {
|
||||
current = data.readUInt16LE(4) / 1000000;
|
||||
}
|
||||
this._current = current;
|
||||
return;
|
||||
}
|
||||
|
||||
const port = this._getPortForPortNumber(data[3]);
|
||||
|
||||
if (!port) {
|
||||
|
@ -166,7 +166,7 @@ export class WeDo2Hub extends Hub {
|
||||
private _parseSensorMessage (data: Buffer) {
|
||||
|
||||
|
||||
if (data[0] === 1) {
|
||||
if (data[0] === 0x01) {
|
||||
/**
|
||||
* Emits when a button is pressed.
|
||||
* @event WeDo2Hub#button
|
||||
@ -175,7 +175,7 @@ export class WeDo2Hub extends Hub {
|
||||
*/
|
||||
this.emit("button", "GREEN", Consts.ButtonStates.PRESSED);
|
||||
return;
|
||||
} else if (data[0] === 0) {
|
||||
} else if (data[0] === 0x00) {
|
||||
this.emit("button", "GREEN", Consts.ButtonStates.RELEASED);
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user