From 7e36b96ad06c3bf4820fc5cb0e5daa465b1646e8 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Tue, 31 Jul 2018 13:37:11 +0100 Subject: [PATCH] Boost motor partial support on PUP hub --- ABOUT.md | 6 +++--- README.md | 6 +++--- hub.ts | 2 +- lpf2hub.ts | 23 +++++++++++++---------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ABOUT.md b/ABOUT.md index 7698c26..109269c 100644 --- a/ABOUT.md +++ b/ABOUT.md @@ -22,7 +22,7 @@ While most LPF2 components and Hubs are compatible with each other, there are ex | WeDo 2.0 Motion Sensor | Sensor | Yes | Yes | Yes | 45300 | | WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | 45300
76112 | | Boost Color and Distance Sensor | Sensor | *Partial* | Yes | Yes | 17101 | -| Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | No | 17101 | +| Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | *Partial* | 17101 | | Powered Up Train Motor | Motor | Yes | Yes | Yes | 60197
60198 | | Powered Up LED Lights | Light | Unknown | Unknown | Unknown | 88005 | @@ -31,9 +31,9 @@ While most LPF2 components and Hubs are compatible with each other, there are ex * The Boost Color and Distance sensor only works in color mode with the WeDo 2.0 Smart Hub. -* When used with the WeDo 2.0 Smart Hub, the Boost Interactive Motor does not support rotating the motor by angle or by time. Only constant speed is supported. However angle detection is supported. +* When used with the WeDo 2.0 Smart Hub, the Boost Interactive Motor does not support rotating the motor by angle. -* The Boost Interactive Motor does not currently function with the Powered Up Hub. +* When used with the Powered Up Hub, the Boost Interactive Motor does not support rotating the motor by angle. It also does not support rotation detection. ### Usage diff --git a/README.md b/README.md index ff48855..76961be 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ While most LPF2 components and Hubs are compatible with each other, there are ex | WeDo 2.0 Motion Sensor | Sensor | Yes | Yes | Yes | 45300 | | WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | 45300
76112 | | Boost Color and Distance Sensor | Sensor | *Partial* | Yes | Yes | 17101 | -| Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | No | 17101 | +| Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | *Partial* | 17101 | | Powered Up Train Motor | Motor | Yes | Yes | Yes | 60197
60198 | | Powered Up LED Lights | Light | Unknown | Unknown | Unknown | 88005 | @@ -31,9 +31,9 @@ While most LPF2 components and Hubs are compatible with each other, there are ex * The Boost Color and Distance sensor only works in color mode with the WeDo 2.0 Smart Hub. -* When used with the WeDo 2.0 Smart Hub, the Boost Interactive Motor does not support rotating the motor by angle or by time. Only constant speed is supported. However angle detection is supported. +* When used with the WeDo 2.0 Smart Hub, the Boost Interactive Motor does not support rotating the motor by angle. -* The Boost Interactive Motor does not currently function with the Powered Up Hub. +* When used with the Powered Up Hub, the Boost Interactive Motor does not support rotating the motor by angle. It also does not support rotation detection. ### Usage diff --git a/hub.ts b/hub.ts index 2d0f5e7..4b38fad 100644 --- a/hub.ts +++ b/hub.ts @@ -216,7 +216,7 @@ export class Hub extends EventEmitter { if (port.connected) { port.type = type; if (this.autoSubscribe) { - // this._activatePortDevice(port.value, type, this._getModeForDeviceType(type), 0x00); + this._activatePortDevice(port.value, type, this._getModeForDeviceType(type), 0x00); /** * Emits when a motor or sensor is attached to the Hub. * @event Hub#attach diff --git a/lpf2hub.ts b/lpf2hub.ts index a420244..f36c4fe 100644 --- a/lpf2hub.ts +++ b/lpf2hub.ts @@ -120,7 +120,7 @@ export class LPF2Hub extends Hub { return new Promise((resolve, reject) => { const portObj = this._ports[port]; if (time) { - if (portObj.type === Consts.Devices.BOOST_INTERACTIVE_MOTOR || portObj.type === Consts.Devices.BOOST_MOVE_HUB_MOTOR) { + if (this.type !== Consts.Hubs.POWERED_UP_HUB && (portObj.type === Consts.Devices.BOOST_INTERACTIVE_MOTOR || portObj.type === Consts.Devices.BOOST_MOVE_HUB_MOTOR)) { 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); @@ -129,16 +129,25 @@ export class LPF2Hub extends Hub { return resolve(); }; } else { - const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); + let data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); + if (this.type === Consts.Hubs.POWERED_UP_HUB && portObj.type === Consts.Devices.BOOST_INTERACTIVE_MOTOR) { + data = Buffer.from([0x07, 0x00, 0x81, portObj.value, 0x11, 0x02, this._mapSpeed(speed)]); + } this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data); setTimeout(() => { - const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); + let data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); + if (this.type === Consts.Hubs.POWERED_UP_HUB && portObj.type === Consts.Devices.BOOST_INTERACTIVE_MOTOR) { + data = Buffer.from([0x07, 0x00, 0x81, portObj.value, 0x11, 0x02, 0x00]); + } this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data); return resolve(); }, time); } } else { - const data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); + let data = Buffer.from([0x08, 0x00, 0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); + if (this.type === Consts.Hubs.POWERED_UP_HUB && portObj.type === Consts.Devices.BOOST_INTERACTIVE_MOTOR) { + data = Buffer.from([0x07, 0x00, 0x81, portObj.value, 0x11, 0x02, this._mapSpeed(speed)]); + } this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data); return resolve(); } @@ -180,8 +189,6 @@ export class LPF2Hub extends Hub { private _writeMessage (uuid: string, message: Buffer, callback?: () => void) { - console.log("OUT"); - console.log(message); const characteristic = this._characteristics[uuid]; if (characteristic) { characteristic.write(message, false, callback); @@ -191,9 +198,6 @@ export class LPF2Hub extends Hub { private _parseMessage (data?: Buffer) { - console.log("IN"); - console.log(data); - if (data) { this._incomingData = Buffer.concat([this._incomingData, data]); } @@ -270,7 +274,6 @@ export class LPF2Hub extends Hub { port.connected = (data[4] === 1 || data[4] === 2) ? true : false; this._registerDeviceAttachment(port, data[5]); - console.log(port); }