diff --git a/ABOUT.md b/ABOUT.md
index 3178d40..b8e110c 100644
--- a/ABOUT.md
+++ b/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 | 45300
76112 |
| Boost Color and Distance Sensor | Sensor | *Partial (1)* | Yes | Yes | 17101 |
| Boost Interactive Motor | Motor/Sensor | *Partial (2)* | Yes | Yes | 17101 |
-| Powered Up Train Motor | Motor | Yes | Yes | Yes | 60197
60198 |
-| Powered Up LED Lights | Light | Yes | Yes | Yes | 88005 |
+| Powered Up Train Motor | Motor | No | Yes | Yes | 60197
60198 |
+| Powered Up LED Lights | Light | Unknown | Unknown | Unknown | 88005 |
(1) Only color mode is supported on the WeDo 2.0 Smart Hub at this point.
diff --git a/README.md b/README.md
index e80cdb8..a29e0cd 100644
--- a/README.md
+++ b/README.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 | 45300
76112 |
| Boost Color and Distance Sensor | Sensor | *Partial (1)* | Yes | Yes | 17101 |
| Boost Interactive Motor | Motor/Sensor | *Partial (2)* | Yes | Yes | 17101 |
-| Powered Up Train Motor | Motor | Yes | Yes | Yes | 60197
60198 |
-| Powered Up LED Lights | Light | Yes | Yes | Yes | 88005 |
+| Powered Up Train Motor | Motor | No | Yes | Yes | 60197
60198 |
+| Powered Up LED Lights | Light | Unknown | Unknown | Unknown | 88005 |
(1) Only color mode is supported on the WeDo 2.0 Smart Hub at this point.
diff --git a/consts.ts b/consts.ts
index 0bdf702..601ed75 100644
--- a/consts.ts
+++ b/consts.ts
@@ -9,13 +9,15 @@ export enum Hubs {
export enum Devices {
UNKNOWN = 0,
BASIC_MOTOR = 1,
+ TRAIN_MOTOR = 2,
BOOST_LED = 22,
WEDO2_TILT = 34,
WEDO2_DISTANCE = 35,
BOOST_DISTANCE = 37,
BOOST_INTERACTIVE_MOTOR = 38,
BOOST_MOVE_HUB_MOTOR = 39,
- BOOST_TILT = 40
+ BOOST_TILT = 40,
+ REMOTE_BUTTON = 55
}
@@ -35,14 +37,16 @@ export enum Colors {
export enum ButtonStates {
PRESSED = 0,
- RELEASED = 1
+ RELEASED = 1,
+ UP = 2,
+ DOWN = 3,
+ STOP = 4
}
-export enum BLENames {
- WEDO2_SMART_HUB_NAME = "LPF2 Smart Hub 2 I/O",
- BOOST_MOVE_HUB_NAME = "LEGO Move Hub",
- POWERED_UP_HUB_NAME = "HUB NO.4",
- POWERED_UP_REMOTE_NAME = "Handset"
+export enum BLEManufacturerData {
+ BOOST_MOVE_HUB_ID = 64,
+ POWERED_UP_HUB_ID = 65,
+ POWERED_UP_REMOTE_ID = 66
}
export enum BLEServices {
diff --git a/hub.ts b/hub.ts
index 6ecee48..3d92d2e 100644
--- a/hub.ts
+++ b/hub.ts
@@ -276,6 +276,8 @@ export class Hub extends EventEmitter {
switch (type) {
case Consts.Devices.BASIC_MOTOR:
return 0x02;
+ case Consts.Devices.TRAIN_MOTOR:
+ return 0x02;
case Consts.Devices.BOOST_INTERACTIVE_MOTOR:
return 0x02;
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);
case Consts.Devices.BOOST_TILT:
return 0x04;
+ case Consts.Devices.REMOTE_BUTTON:
+ return 0x00;
default:
return 0x00;
}
diff --git a/lpf2hub.ts b/lpf2hub.ts
index cdb31a4..7f7277c 100644
--- a/lpf2hub.ts
+++ b/lpf2hub.ts
@@ -31,21 +31,25 @@ export class LPF2Hub extends Hub {
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
super(peripheral, autoSubscribe);
- switch (peripheral.advertisement.localName) {
- case Consts.BLENames.POWERED_UP_HUB_NAME:
+ switch (peripheral.advertisement.manufacturerData[3]) {
+ case Consts.BLEManufacturerData.POWERED_UP_HUB_ID:
{
this.type = Consts.Hubs.POWERED_UP_HUB;
this._ports = {
- "A": new Port("A", 55),
- "B": new Port("B", 56),
+ "A": new Port("A", 0),
+ "B": new Port("B", 1),
"AB": new Port("AB", 57)
};
debug("Discovered Powered Up Hub");
break;
}
- case Consts.BLENames.POWERED_UP_REMOTE_NAME:
+ case Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID:
{
this.type = Consts.Hubs.POWERED_UP_REMOTE;
+ this._ports = {
+ "LEFT": new Port("LEFT", 0),
+ "RIGHT": new Port("RIGHT", 1)
+ };
debug("Discovered Powered Up Remote");
break;
}
@@ -69,7 +73,7 @@ export class LPF2Hub extends Hub {
public connect () {
return new Promise(async (resolve, reject) => {
- debug("Connecting to Boost Move Hub");
+ debug("Connecting to Hub");
await super.connect();
const characteristic = this._characteristics[Consts.BLECharacteristics.BOOST_ALL];
this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this));
@@ -111,7 +115,11 @@ export class LPF2Hub extends Hub {
public setMotorSpeed (port: string, speed: number, time: number) {
return new Promise((resolve, reject) => {
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;
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);
@@ -359,6 +367,32 @@ export class LPF2Hub extends Hub {
this.emit("tilt", port.id, tiltX, tiltY);
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;
+ }
}
}