Gave some consts better names
This commit is contained in:
parent
0fee67c438
commit
7d7a7377c7
13
DOCS.md
13
DOCS.md
@ -657,7 +657,6 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
* ["distance" (port, distance)](#LPF2Hub+event_distance)
|
||||
* ["color" (port, color)](#LPF2Hub+event_color)
|
||||
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
|
||||
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
|
||||
* ["attach" (port, type)](#Hub+event_attach)
|
||||
* ["detach" (port)](#Hub+event_detach)
|
||||
|
||||
@ -864,18 +863,6 @@ Emits when a tilt sensor is activated.
|
||||
| x | <code>number</code> | |
|
||||
| y | <code>number</code> | |
|
||||
|
||||
<a name="LPF2Hub+event_rotate"></a>
|
||||
|
||||
### "rotate" (port, rotation)
|
||||
Emits when a rotation sensor is activated.
|
||||
|
||||
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
|
||||
|
||||
| Param | Type |
|
||||
| --- | --- |
|
||||
| port | <code>string</code> |
|
||||
| rotation | <code>number</code> |
|
||||
|
||||
<a name="Hub+event_attach"></a>
|
||||
|
||||
### "attach" (port, type)
|
||||
|
13
README.md
13
README.md
@ -707,7 +707,6 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
* ["distance" (port, distance)](#LPF2Hub+event_distance)
|
||||
* ["color" (port, color)](#LPF2Hub+event_color)
|
||||
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
|
||||
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
|
||||
* ["attach" (port, type)](#Hub+event_attach)
|
||||
* ["detach" (port)](#Hub+event_detach)
|
||||
|
||||
@ -914,18 +913,6 @@ Emits when a tilt sensor is activated.
|
||||
| x | <code>number</code> | |
|
||||
| y | <code>number</code> | |
|
||||
|
||||
<a name="LPF2Hub+event_rotate"></a>
|
||||
|
||||
### "rotate" (port, rotation)
|
||||
Emits when a rotation sensor is activated.
|
||||
|
||||
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
|
||||
|
||||
| Param | Type |
|
||||
| --- | --- |
|
||||
| port | <code>string</code> |
|
||||
| rotation | <code>number</code> |
|
||||
|
||||
<a name="Hub+event_attach"></a>
|
||||
|
||||
### "attach" (port, type)
|
||||
|
@ -19,7 +19,7 @@ export class BoostMoveHub extends LPF2Hub {
|
||||
|
||||
|
||||
public static IsBoostMoveHub (peripheral: Peripheral) {
|
||||
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.BOOST_MOVE_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID);
|
||||
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID);
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ export class BoostMoveHub extends LPF2Hub {
|
||||
color = 0;
|
||||
}
|
||||
const data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
@ -82,22 +82,22 @@ export class BoostMoveHub extends LPF2Hub {
|
||||
portObj.busy = true;
|
||||
const data = Buffer.from([0x0c, 0x00, 0x81, portObj.value, 0x11, 0x09, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
|
||||
data.writeUInt16LE(time > 65535 ? 65535 : time, 6);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
portObj.finished = () => {
|
||||
return resolve();
|
||||
};
|
||||
} else {
|
||||
const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
setTimeout(() => {
|
||||
const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
}, time);
|
||||
}
|
||||
} else {
|
||||
const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
}
|
||||
});
|
||||
@ -119,7 +119,7 @@ export class BoostMoveHub extends LPF2Hub {
|
||||
const data = Buffer.from([0x0e, 0x00, 0x81, portObj.value, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x7f, 0x03]);
|
||||
data.writeUInt32LE(angle, 6);
|
||||
data.writeUInt8(this._mapSpeed(speed), 10);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
portObj.finished = () => {
|
||||
return resolve();
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ export enum Devices {
|
||||
BOOST_INTERACTIVE_MOTOR = 38,
|
||||
BOOST_MOVE_HUB_MOTOR = 39,
|
||||
BOOST_TILT = 40,
|
||||
REMOTE_BUTTON = 55
|
||||
POWERED_UP_REMOTE_BUTTON = 55
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ export enum BLEManufacturerData {
|
||||
|
||||
export enum BLEServices {
|
||||
WEDO2_SMART_HUB = "000015231212efde1523785feabcd123",
|
||||
BOOST_MOVE_HUB = "000016231212efde1623785feabcd123"
|
||||
LPF2_HUB = "000016231212efde1623785feabcd123"
|
||||
}
|
||||
|
||||
|
||||
@ -67,5 +67,5 @@ export enum BLECharacteristics {
|
||||
WEDO2_PORT_TYPE_WRITE = "000015631212efde1523785feabcd123", // "1563"
|
||||
WEDO2_MOTOR_VALUE_WRITE = "000015651212efde1523785feabcd123", // "1565"
|
||||
WEDO2_NAME_ID = "000015241212efde1523785feabcd123", // "1524"
|
||||
BOOST_ALL = "000016241212efde1623785feabcd123"
|
||||
LPF2_ALL = "000016241212efde1623785feabcd123"
|
||||
}
|
||||
|
2
hub.ts
2
hub.ts
@ -324,7 +324,7 @@ export class Hub extends EventEmitter {
|
||||
return (this.type === Consts.Hubs.WEDO2_SMART_HUB ? 0x00 : 0x08);
|
||||
case Consts.Devices.BOOST_TILT:
|
||||
return 0x04;
|
||||
case Consts.Devices.REMOTE_BUTTON:
|
||||
case Consts.Devices.POWERED_UP_REMOTE_BUTTON:
|
||||
return 0x00;
|
||||
default:
|
||||
return 0x00;
|
||||
|
14
lpf2hub.ts
14
lpf2hub.ts
@ -37,23 +37,23 @@ export class LPF2Hub extends Hub {
|
||||
public connect () {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
await super.connect();
|
||||
const characteristic = this._characteristics[Consts.BLECharacteristics.BOOST_ALL];
|
||||
const characteristic = this._characteristics[Consts.BLECharacteristics.LPF2_ALL];
|
||||
this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this));
|
||||
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
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x05, 0x00, 0x01, 0x02, 0x02])); // Activate button reports
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x0a, 0x00, 0x41, 0x3b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate current reports
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x0a, 0x00, 0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected _activatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) {
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, Buffer.from([0x0a, 0x00, 0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x01]), callback);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x0a, 0x00, 0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x01]), callback);
|
||||
}
|
||||
|
||||
|
||||
protected _deactivatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) {
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, Buffer.from([0x0a, 0x00, 0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), callback);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x0a, 0x00, 0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), callback);
|
||||
}
|
||||
|
||||
|
||||
@ -281,7 +281,7 @@ export class LPF2Hub extends Hub {
|
||||
this.emit("tilt", port.id, tiltX, tiltY);
|
||||
break;
|
||||
}
|
||||
case Consts.Devices.REMOTE_BUTTON:
|
||||
case Consts.Devices.POWERED_UP_REMOTE_BUTTON:
|
||||
{
|
||||
switch (data[4]) {
|
||||
case 0x01:
|
||||
|
12
puphub.ts
12
puphub.ts
@ -21,13 +21,13 @@ export class PUPHub extends LPF2Hub {
|
||||
// We set JSDoc to ignore these events as a Powered Up Remote will never emit them.
|
||||
|
||||
/**
|
||||
* @event PUPRemote#rotate
|
||||
* @event PUPHub#rotate
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
|
||||
public static IsPUPHub (peripheral: Peripheral) {
|
||||
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.BOOST_MOVE_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_HUB_ID);
|
||||
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_HUB_ID);
|
||||
}
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ export class PUPHub extends LPF2Hub {
|
||||
color = 0;
|
||||
}
|
||||
const data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
@ -84,15 +84,15 @@ export class PUPHub extends LPF2Hub {
|
||||
const portObj = this._ports[port];
|
||||
if (time) {
|
||||
const data = Buffer.from([0x0a, 0x00, 0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
setTimeout(() => {
|
||||
const data = Buffer.from([0x0a, 0x00, 0x81, portObj.value, 0x11, 0x60, 0x00, 0x00, 0x00, 0x00]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
}, time);
|
||||
} else {
|
||||
const data = Buffer.from([0x0a, 0x00, 0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
}
|
||||
});
|
||||
|
@ -52,7 +52,7 @@ export class PUPRemote extends LPF2Hub {
|
||||
|
||||
|
||||
public static IsPUPRemote (peripheral: Peripheral) {
|
||||
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.BOOST_MOVE_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID);
|
||||
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID);
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ export class PUPRemote extends LPF2Hub {
|
||||
color = 0;
|
||||
}
|
||||
const data = Buffer.from([0x08, 0x00, 0x81, 0x34, 0x11, 0x51, 0x00, color]);
|
||||
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user