Gave some consts better names

This commit is contained in:
Nathan Kunicki 2018-08-01 11:38:29 +01:00
parent 0fee67c438
commit 7d7a7377c7
8 changed files with 26 additions and 52 deletions

13
DOCS.md
View File

@ -657,7 +657,6 @@ Emits when an attached motor or sensor is detached from the Hub.
* ["distance" (port, distance)](#LPF2Hub+event_distance) * ["distance" (port, distance)](#LPF2Hub+event_distance)
* ["color" (port, color)](#LPF2Hub+event_color) * ["color" (port, color)](#LPF2Hub+event_color)
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt) * ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
* ["attach" (port, type)](#Hub+event_attach) * ["attach" (port, type)](#Hub+event_attach)
* ["detach" (port)](#Hub+event_detach) * ["detach" (port)](#Hub+event_detach)
@ -864,18 +863,6 @@ Emits when a tilt sensor is activated.
| x | <code>number</code> | | | x | <code>number</code> | |
| y | <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> <a name="Hub+event_attach"></a>
### "attach" (port, type) ### "attach" (port, type)

View File

@ -707,7 +707,6 @@ Emits when an attached motor or sensor is detached from the Hub.
* ["distance" (port, distance)](#LPF2Hub+event_distance) * ["distance" (port, distance)](#LPF2Hub+event_distance)
* ["color" (port, color)](#LPF2Hub+event_color) * ["color" (port, color)](#LPF2Hub+event_color)
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt) * ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
* ["attach" (port, type)](#Hub+event_attach) * ["attach" (port, type)](#Hub+event_attach)
* ["detach" (port)](#Hub+event_detach) * ["detach" (port)](#Hub+event_detach)
@ -914,18 +913,6 @@ Emits when a tilt sensor is activated.
| x | <code>number</code> | | | x | <code>number</code> | |
| y | <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> <a name="Hub+event_attach"></a>
### "attach" (port, type) ### "attach" (port, type)

View File

@ -19,7 +19,7 @@ export class BoostMoveHub extends LPF2Hub {
public static IsBoostMoveHub (peripheral: Peripheral) { 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; color = 0;
} }
const data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]); 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(); return resolve();
}); });
} }
@ -82,22 +82,22 @@ export class BoostMoveHub extends LPF2Hub {
portObj.busy = true; portObj.busy = true;
const data = Buffer.from([0x0c, 0x00, 0x81, portObj.value, 0x11, 0x09, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); 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); data.writeUInt16LE(time > 65535 ? 65535 : time, 6);
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data); this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
return resolve(); return resolve();
}; };
} else { } else {
const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); 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(() => { setTimeout(() => {
const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); 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(); return resolve();
}, time); }, time);
} }
} else { } else {
const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); 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(); 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]); const data = Buffer.from([0x0e, 0x00, 0x81, portObj.value, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x7f, 0x03]);
data.writeUInt32LE(angle, 6); data.writeUInt32LE(angle, 6);
data.writeUInt8(this._mapSpeed(speed), 10); data.writeUInt8(this._mapSpeed(speed), 10);
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data); this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
return resolve(); return resolve();
}; };

View File

@ -17,7 +17,7 @@ export enum Devices {
BOOST_INTERACTIVE_MOTOR = 38, BOOST_INTERACTIVE_MOTOR = 38,
BOOST_MOVE_HUB_MOTOR = 39, BOOST_MOVE_HUB_MOTOR = 39,
BOOST_TILT = 40, BOOST_TILT = 40,
REMOTE_BUTTON = 55 POWERED_UP_REMOTE_BUTTON = 55
} }
@ -51,7 +51,7 @@ export enum BLEManufacturerData {
export enum BLEServices { export enum BLEServices {
WEDO2_SMART_HUB = "000015231212efde1523785feabcd123", 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_PORT_TYPE_WRITE = "000015631212efde1523785feabcd123", // "1563"
WEDO2_MOTOR_VALUE_WRITE = "000015651212efde1523785feabcd123", // "1565" WEDO2_MOTOR_VALUE_WRITE = "000015651212efde1523785feabcd123", // "1565"
WEDO2_NAME_ID = "000015241212efde1523785feabcd123", // "1524" WEDO2_NAME_ID = "000015241212efde1523785feabcd123", // "1524"
BOOST_ALL = "000016241212efde1623785feabcd123" LPF2_ALL = "000016241212efde1623785feabcd123"
} }

2
hub.ts
View File

@ -324,7 +324,7 @@ export class Hub extends EventEmitter {
return (this.type === Consts.Hubs.WEDO2_SMART_HUB ? 0x00 : 0x08); return (this.type === Consts.Hubs.WEDO2_SMART_HUB ? 0x00 : 0x08);
case Consts.Devices.BOOST_TILT: case Consts.Devices.BOOST_TILT:
return 0x04; return 0x04;
case Consts.Devices.REMOTE_BUTTON: case Consts.Devices.POWERED_UP_REMOTE_BUTTON:
return 0x00; return 0x00;
default: default:
return 0x00; return 0x00;

View File

@ -37,23 +37,23 @@ export class LPF2Hub extends Hub {
public connect () { public connect () {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
await super.connect(); 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._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.LPF2_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.LPF2_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([0x0a, 0x00, 0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
return resolve(); return resolve();
}); });
} }
protected _activatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) { 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) { 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); this.emit("tilt", port.id, tiltX, tiltY);
break; break;
} }
case Consts.Devices.REMOTE_BUTTON: case Consts.Devices.POWERED_UP_REMOTE_BUTTON:
{ {
switch (data[4]) { switch (data[4]) {
case 0x01: case 0x01:

View File

@ -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. // We set JSDoc to ignore these events as a Powered Up Remote will never emit them.
/** /**
* @event PUPRemote#rotate * @event PUPHub#rotate
* @ignore * @ignore
*/ */
public static IsPUPHub (peripheral: Peripheral) { 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; color = 0;
} }
const data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]); 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(); return resolve();
}); });
} }
@ -84,15 +84,15 @@ export class PUPHub extends LPF2Hub {
const portObj = this._ports[port]; const portObj = this._ports[port];
if (time) { if (time) {
const data = Buffer.from([0x0a, 0x00, 0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]); 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(() => { setTimeout(() => {
const data = Buffer.from([0x0a, 0x00, 0x81, portObj.value, 0x11, 0x60, 0x00, 0x00, 0x00, 0x00]); 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(); return resolve();
}, time); }, time);
} else { } else {
const data = Buffer.from([0x0a, 0x00, 0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]); 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(); return resolve();
} }
}); });

View File

@ -52,7 +52,7 @@ export class PUPRemote extends LPF2Hub {
public static IsPUPRemote (peripheral: Peripheral) { 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; color = 0;
} }
const data = Buffer.from([0x08, 0x00, 0x81, 0x34, 0x11, 0x51, 0x00, color]); 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(); return resolve();
}); });
} }