Compatible with Powered Up Hub and Remote
This commit is contained in:
parent
184df80120
commit
73e7f89f6f
4
ABOUT.md
4
ABOUT.md
@ -23,8 +23,8 @@ While most LPF2 components and Hubs are compatible with each other, there are ex
|
|||||||
| WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> |
|
| WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> |
|
||||||
| Boost Color and Distance Sensor | Sensor | *Partial (<a href="#compatibility-note-1">1</a>)* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
|
| Boost Color and Distance Sensor | Sensor | *Partial (<a href="#compatibility-note-1">1</a>)* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
|
||||||
| Boost Interactive Motor | Motor/Sensor | *Partial (<a href="#compatibility-note-2">2</a>)* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
|
| Boost Interactive Motor | Motor/Sensor | *Partial (<a href="#compatibility-note-2">2</a>)* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
|
||||||
| Powered Up Train Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
|
| Powered Up Train Motor | Motor | No | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
|
||||||
| Powered Up LED Lights | Light | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
|
| Powered Up LED Lights | Light | Unknown | Unknown | Unknown | <a href="https://brickset.com/sets/88005-1/">88005</a> |
|
||||||
|
|
||||||
<a name="compatibility-note-1"></a><sub>(1) Only color mode is supported on the WeDo 2.0 Smart Hub at this point.</sub>
|
<a name="compatibility-note-1"></a><sub>(1) Only color mode is supported on the WeDo 2.0 Smart Hub at this point.</sub>
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ While most LPF2 components and Hubs are compatible with each other, there are ex
|
|||||||
| WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> |
|
| WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> |
|
||||||
| Boost Color and Distance Sensor | Sensor | *Partial (<a href="#compatibility-note-1">1</a>)* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
|
| Boost Color and Distance Sensor | Sensor | *Partial (<a href="#compatibility-note-1">1</a>)* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
|
||||||
| Boost Interactive Motor | Motor/Sensor | *Partial (<a href="#compatibility-note-2">2</a>)* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
|
| Boost Interactive Motor | Motor/Sensor | *Partial (<a href="#compatibility-note-2">2</a>)* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
|
||||||
| Powered Up Train Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
|
| Powered Up Train Motor | Motor | No | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
|
||||||
| Powered Up LED Lights | Light | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
|
| Powered Up LED Lights | Light | Unknown | Unknown | Unknown | <a href="https://brickset.com/sets/88005-1/">88005</a> |
|
||||||
|
|
||||||
<a name="compatibility-note-1"></a><sub>(1) Only color mode is supported on the WeDo 2.0 Smart Hub at this point.</sub>
|
<a name="compatibility-note-1"></a><sub>(1) Only color mode is supported on the WeDo 2.0 Smart Hub at this point.</sub>
|
||||||
|
|
||||||
|
18
consts.ts
18
consts.ts
@ -9,13 +9,15 @@ export enum Hubs {
|
|||||||
export enum Devices {
|
export enum Devices {
|
||||||
UNKNOWN = 0,
|
UNKNOWN = 0,
|
||||||
BASIC_MOTOR = 1,
|
BASIC_MOTOR = 1,
|
||||||
|
TRAIN_MOTOR = 2,
|
||||||
BOOST_LED = 22,
|
BOOST_LED = 22,
|
||||||
WEDO2_TILT = 34,
|
WEDO2_TILT = 34,
|
||||||
WEDO2_DISTANCE = 35,
|
WEDO2_DISTANCE = 35,
|
||||||
BOOST_DISTANCE = 37,
|
BOOST_DISTANCE = 37,
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -35,14 +37,16 @@ export enum Colors {
|
|||||||
|
|
||||||
export enum ButtonStates {
|
export enum ButtonStates {
|
||||||
PRESSED = 0,
|
PRESSED = 0,
|
||||||
RELEASED = 1
|
RELEASED = 1,
|
||||||
|
UP = 2,
|
||||||
|
DOWN = 3,
|
||||||
|
STOP = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum BLENames {
|
export enum BLEManufacturerData {
|
||||||
WEDO2_SMART_HUB_NAME = "LPF2 Smart Hub 2 I/O",
|
BOOST_MOVE_HUB_ID = 64,
|
||||||
BOOST_MOVE_HUB_NAME = "LEGO Move Hub",
|
POWERED_UP_HUB_ID = 65,
|
||||||
POWERED_UP_HUB_NAME = "HUB NO.4",
|
POWERED_UP_REMOTE_ID = 66
|
||||||
POWERED_UP_REMOTE_NAME = "Handset"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum BLEServices {
|
export enum BLEServices {
|
||||||
|
4
hub.ts
4
hub.ts
@ -276,6 +276,8 @@ export class Hub extends EventEmitter {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case Consts.Devices.BASIC_MOTOR:
|
case Consts.Devices.BASIC_MOTOR:
|
||||||
return 0x02;
|
return 0x02;
|
||||||
|
case Consts.Devices.TRAIN_MOTOR:
|
||||||
|
return 0x02;
|
||||||
case Consts.Devices.BOOST_INTERACTIVE_MOTOR:
|
case Consts.Devices.BOOST_INTERACTIVE_MOTOR:
|
||||||
return 0x02;
|
return 0x02;
|
||||||
case Consts.Devices.BOOST_MOVE_HUB_MOTOR:
|
case Consts.Devices.BOOST_MOVE_HUB_MOTOR:
|
||||||
@ -284,6 +286,8 @@ 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:
|
||||||
|
return 0x00;
|
||||||
default:
|
default:
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
48
lpf2hub.ts
48
lpf2hub.ts
@ -31,21 +31,25 @@ export class LPF2Hub extends Hub {
|
|||||||
|
|
||||||
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(peripheral, autoSubscribe);
|
||||||
switch (peripheral.advertisement.localName) {
|
switch (peripheral.advertisement.manufacturerData[3]) {
|
||||||
case Consts.BLENames.POWERED_UP_HUB_NAME:
|
case Consts.BLEManufacturerData.POWERED_UP_HUB_ID:
|
||||||
{
|
{
|
||||||
this.type = Consts.Hubs.POWERED_UP_HUB;
|
this.type = Consts.Hubs.POWERED_UP_HUB;
|
||||||
this._ports = {
|
this._ports = {
|
||||||
"A": new Port("A", 55),
|
"A": new Port("A", 0),
|
||||||
"B": new Port("B", 56),
|
"B": new Port("B", 1),
|
||||||
"AB": new Port("AB", 57)
|
"AB": new Port("AB", 57)
|
||||||
};
|
};
|
||||||
debug("Discovered Powered Up Hub");
|
debug("Discovered Powered Up Hub");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Consts.BLENames.POWERED_UP_REMOTE_NAME:
|
case Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID:
|
||||||
{
|
{
|
||||||
this.type = Consts.Hubs.POWERED_UP_REMOTE;
|
this.type = Consts.Hubs.POWERED_UP_REMOTE;
|
||||||
|
this._ports = {
|
||||||
|
"LEFT": new Port("LEFT", 0),
|
||||||
|
"RIGHT": new Port("RIGHT", 1)
|
||||||
|
};
|
||||||
debug("Discovered Powered Up Remote");
|
debug("Discovered Powered Up Remote");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -69,7 +73,7 @@ export class LPF2Hub extends Hub {
|
|||||||
|
|
||||||
public connect () {
|
public connect () {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
debug("Connecting to Boost Move Hub");
|
debug("Connecting to Hub");
|
||||||
await super.connect();
|
await super.connect();
|
||||||
const characteristic = this._characteristics[Consts.BLECharacteristics.BOOST_ALL];
|
const characteristic = this._characteristics[Consts.BLECharacteristics.BOOST_ALL];
|
||||||
this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this));
|
this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this));
|
||||||
@ -111,7 +115,11 @@ export class LPF2Hub extends Hub {
|
|||||||
public setMotorSpeed (port: string, speed: number, time: number) {
|
public setMotorSpeed (port: string, speed: number, time: number) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const portObj = this._ports[port];
|
const portObj = this._ports[port];
|
||||||
if (time) {
|
if (portObj.type === Consts.Devices.TRAIN_MOTOR) {
|
||||||
|
const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
|
||||||
|
this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
|
||||||
|
return resolve();
|
||||||
|
} else if (time) {
|
||||||
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);
|
||||||
@ -359,6 +367,32 @@ 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:
|
||||||
|
{
|
||||||
|
switch (data[4]) {
|
||||||
|
case 0x01:
|
||||||
|
{
|
||||||
|
this.emit("button", port.id, Consts.ButtonStates.UP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 0xff:
|
||||||
|
{
|
||||||
|
this.emit("button", port.id, Consts.ButtonStates.DOWN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 0x7f:
|
||||||
|
{
|
||||||
|
this.emit("button", port.id, Consts.ButtonStates.STOP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 0x00:
|
||||||
|
{
|
||||||
|
this.emit("button", port.id, Consts.ButtonStates.RELEASED);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user