Boost motor partial support on PUP hub

This commit is contained in:
Nathan Kunicki 2018-07-31 13:37:11 +01:00
parent 0e00bfd653
commit 7e36b96ad0
4 changed files with 20 additions and 17 deletions

View File

@ -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 | <a href="https://brickset.com/sets/45300-1/">45300</a> | | WeDo 2.0 Motion Sensor | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</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> | | 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* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> | | Boost Color and Distance Sensor | Sensor | *Partial* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | No | <a href="https://brickset.com/sets/17101-1/">17101</a> | | Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | *Partial* | <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 | 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 LED Lights | Light | Unknown | Unknown | Unknown | <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> |
@ -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. * 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 ### Usage

View File

@ -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 | <a href="https://brickset.com/sets/45300-1/">45300</a> | | WeDo 2.0 Motion Sensor | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</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> | | 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* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> | | Boost Color and Distance Sensor | Sensor | *Partial* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | No | <a href="https://brickset.com/sets/17101-1/">17101</a> | | Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | *Partial* | <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 | 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 LED Lights | Light | Unknown | Unknown | Unknown | <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> |
@ -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. * 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 ### Usage

2
hub.ts
View File

@ -216,7 +216,7 @@ export class Hub extends EventEmitter {
if (port.connected) { if (port.connected) {
port.type = type; port.type = type;
if (this.autoSubscribe) { 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. * Emits when a motor or sensor is attached to the Hub.
* @event Hub#attach * @event Hub#attach

View File

@ -120,7 +120,7 @@ export class LPF2Hub extends Hub {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const portObj = this._ports[port]; const portObj = this._ports[port];
if (time) { 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; 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);
@ -129,16 +129,25 @@ export class LPF2Hub extends Hub {
return resolve(); return resolve();
}; };
} else { } 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); this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
setTimeout(() => { 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); this._writeMessage(Consts.BLECharacteristics.BOOST_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)]); 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); this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data);
return resolve(); return resolve();
} }
@ -180,8 +189,6 @@ export class LPF2Hub extends Hub {
private _writeMessage (uuid: string, message: Buffer, callback?: () => void) { private _writeMessage (uuid: string, message: Buffer, callback?: () => void) {
console.log("OUT");
console.log(message);
const characteristic = this._characteristics[uuid]; const characteristic = this._characteristics[uuid];
if (characteristic) { if (characteristic) {
characteristic.write(message, false, callback); characteristic.write(message, false, callback);
@ -191,9 +198,6 @@ export class LPF2Hub extends Hub {
private _parseMessage (data?: Buffer) { private _parseMessage (data?: Buffer) {
console.log("IN");
console.log(data);
if (data) { if (data) {
this._incomingData = Buffer.concat([this._incomingData, 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; port.connected = (data[4] === 1 || data[4] === 2) ? true : false;
this._registerDeviceAttachment(port, data[5]); this._registerDeviceAttachment(port, data[5]);
console.log(port);
} }