From 9ddafe4e04a3da3ada6f46635080e7ab319d96be Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Mon, 23 Jul 2018 21:29:18 +0100 Subject: [PATCH] WeDo 2.0 motor now works with PU hub --- ABOUT.md | 2 +- README.md | 2 +- lpf2hub.ts | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/ABOUT.md b/ABOUT.md index b8e110c..fd74ee0 100644 --- a/ABOUT.md +++ b/ABOUT.md @@ -23,7 +23,7 @@ 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 | No | Yes | Yes | 60197
60198 | +| Powered Up Train Motor | Motor | Yes | 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 a29e0cd..bbb9a75 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ 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 | No | Yes | Yes | 60197
60198 | +| Powered Up Train Motor | Motor | Yes | 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/lpf2hub.ts b/lpf2hub.ts index 7f7277c..91a81a5 100644 --- a/lpf2hub.ts +++ b/lpf2hub.ts @@ -115,11 +115,7 @@ export class LPF2Hub extends Hub { public setMotorSpeed (port: string, speed: number, time: number) { return new Promise((resolve, reject) => { const portObj = this._ports[port]; - 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) { + 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); @@ -128,7 +124,7 @@ export class LPF2Hub extends Hub { return resolve(); }; } else { - const data = Buffer.from([0x0a, 0x00, 0x81, portObj.value, 0x11, 0x01, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); + const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data); return resolve(); }