diff --git a/boosthub.js b/boosthub.js index 47f2f9f..6a5fd3a 100644 --- a/boosthub.js +++ b/boosthub.js @@ -48,15 +48,28 @@ class BoostHub extends Hub { setLEDColor (color) { const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL]; if (characteristic) { + let data = Buffer.from([0x05, 0x00, 0x01, 0x02, 0x02]); + characteristic.write(data); if (color === false) { color = 0; } - const data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]); + data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]); characteristic.write(data); } } + // setLEDRGB (red, green, blue) { + // const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL]; + // if (characteristic) { + // let data = Buffer.from([0x05, 0x00, 0x01, 0x02, 0x03]); + // characteristic.write(data); + // data = Buffer.from([0x0a, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, red, green, blue]); + // characteristic.write(data); + // } + // } + + setMotorSpeed (port, speed, time) { const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL]; if (characteristic) { diff --git a/wedo2hub.js b/wedo2hub.js index 8fbebef..ea98c5e 100644 --- a/wedo2hub.js +++ b/wedo2hub.js @@ -42,13 +42,29 @@ class WeDo2Hub extends Hub { setLEDColor (color) { - const characteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.MOTOR_VALUE_WRITE]; - if (characteristic) { + const motorCharacteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.MOTOR_VALUE_WRITE]; + const portCharacteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.PORT_TYPE_WRITE]; + if (motorCharacteristic && portCharacteristic) { + let data = Buffer.from([0x06, 0x17, 0x01, 0x01]); + portCharacteristic.write(data); if (color === false) { color = 0; } - const data = Buffer.from([0x06, 0x04, 0x01, color]); - characteristic.write(data); + data = Buffer.from([0x06, 0x04, 0x01, color]); + motorCharacteristic.write(data); + } + } + + + setLEDRGB (red, green, blue) { + const motorCharacteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.MOTOR_VALUE_WRITE]; + const portCharacteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.PORT_TYPE_WRITE]; + if (motorCharacteristic && portCharacteristic) { + let data1 = Buffer.from([0x01, 0x02, 0x06, 0x17, 0x01, 0x02]); + portCharacteristic.write(data1); + let data2 = Buffer.from([0x06, 0x04, 0x03, red, green, blue]); + console.log(data2); + motorCharacteristic.write(data2); } }