From 4cfee19b5afa18f86c37d39cbed4c2629f980266 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Thu, 2 Aug 2018 11:57:22 +0100 Subject: [PATCH] Port AB supported on PUPHub, setName on LPF2 hubs --- DOCS.md | 8 ++++---- README.md | 8 ++++---- lpf2hub.ts | 3 ++- puphub.ts | 7 +++++++ wedo2smarthub.ts | 3 ++- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/DOCS.md b/DOCS.md index ab78ac2..ed3a0dc 100644 --- a/DOCS.md +++ b/DOCS.md @@ -156,7 +156,7 @@ Set the name of the Hub. | Param | Type | Description | | --- | --- | --- | -| name | string | New name of the hub (ASCII characters only). | +| name | string | New name of the hub (14 characters or less, ASCII only). | @@ -504,7 +504,7 @@ Set the name of the Hub. | Param | Type | Description | | --- | --- | --- | -| name | string | New name of the hub (ASCII characters only). | +| name | string | New name of the hub (14 characters or less, ASCII only). | @@ -783,7 +783,7 @@ Set the name of the Hub. | Param | Type | Description | | --- | --- | --- | -| name | string | New name of the hub (ASCII characters only). | +| name | string | New name of the hub (14 characters or less, ASCII only). | @@ -1030,7 +1030,7 @@ Set the name of the Hub. | Param | Type | Description | | --- | --- | --- | -| name | string | New name of the hub (ASCII characters only). | +| name | string | New name of the hub (14 characters or less, ASCII only). | diff --git a/README.md b/README.md index cd9c60b..fe8f531 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ Set the name of the Hub. | Param | Type | Description | | --- | --- | --- | -| name | string | New name of the hub (ASCII characters only). | +| name | string | New name of the hub (14 characters or less, ASCII only). | @@ -554,7 +554,7 @@ Set the name of the Hub. | Param | Type | Description | | --- | --- | --- | -| name | string | New name of the hub (ASCII characters only). | +| name | string | New name of the hub (14 characters or less, ASCII only). | @@ -833,7 +833,7 @@ Set the name of the Hub. | Param | Type | Description | | --- | --- | --- | -| name | string | New name of the hub (ASCII characters only). | +| name | string | New name of the hub (14 characters or less, ASCII only). | @@ -1080,7 +1080,7 @@ Set the name of the Hub. | Param | Type | Description | | --- | --- | --- | -| name | string | New name of the hub (ASCII characters only). | +| name | string | New name of the hub (14 characters or less, ASCII only). | diff --git a/lpf2hub.ts b/lpf2hub.ts index 2517a59..967cecc 100644 --- a/lpf2hub.ts +++ b/lpf2hub.ts @@ -50,7 +50,7 @@ export class LPF2Hub extends Hub { /** * Set the name of the Hub. * @method LPF2Hub#setName - * @param {string} name New name of the hub (ASCII characters only). + * @param {string} name New name of the hub (14 characters or less, ASCII only). * @returns {Promise} Resolved upon successful issuance of command. */ public setName (name: string) { @@ -61,6 +61,7 @@ export class LPF2Hub extends Hub { let data = Buffer.from([0x00, 0x00, 0x01, 0x01, 0x01]); data = Buffer.concat([data, Buffer.from(name, "ascii")]); data[0] = data.length; + // Send this twice, as sometimes the first time doesn't take this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._name = name; diff --git a/puphub.ts b/puphub.ts index 2e5551c..8bb2453 100644 --- a/puphub.ts +++ b/puphub.ts @@ -84,6 +84,13 @@ export class PUPHub extends LPF2Hub { if (portObj.id !== "AB" && speed instanceof Array) { throw new Error(`Port ${portObj.id} can only accept a single speed`); } + if (portObj.id === "AB") { + const portObjA = this._portLookup("A"); + const portObjB = this._portLookup("B"); + if (portObjA.type !== portObjB.type) { + throw new Error(`Port ${portObj.id} requires both motors be of the same type`); + } + } return new Promise((resolve, reject) => { if (time) { let data = null; diff --git a/wedo2smarthub.ts b/wedo2smarthub.ts index 5cacf23..bafc27d 100644 --- a/wedo2smarthub.ts +++ b/wedo2smarthub.ts @@ -56,7 +56,7 @@ export class WeDo2SmartHub extends Hub { /** * Set the name of the Hub. * @method WeDo2SmartHub#setName - * @param {string} name New name of the hub (ASCII characters only). + * @param {string} name New name of the hub (14 characters or less, ASCII only). * @returns {Promise} Resolved upon successful issuance of command. */ public setName (name: string) { @@ -65,6 +65,7 @@ export class WeDo2SmartHub extends Hub { } return new Promise((resolve, reject) => { const data = Buffer.from(name, "ascii"); + // Send this twice, as sometimes the first time doesn't take this._writeMessage(Consts.BLECharacteristics.WEDO2_NAME_ID, data); this._writeMessage(Consts.BLECharacteristics.WEDO2_NAME_ID, data); this._name = name;