Port AB supported on PUPHub, setName on LPF2 hubs
This commit is contained in:
parent
2a5b5a47b9
commit
4cfee19b5a
8
DOCS.md
8
DOCS.md
@ -156,7 +156,7 @@ Set the name of the Hub.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (ASCII characters only). |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="WeDo2SmartHub+setLEDColor"></a>
|
||||
|
||||
@ -504,7 +504,7 @@ Set the name of the Hub.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (ASCII characters only). |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
@ -783,7 +783,7 @@ Set the name of the Hub.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (ASCII characters only). |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
@ -1030,7 +1030,7 @@ Set the name of the Hub.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (ASCII characters only). |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
|
@ -206,7 +206,7 @@ Set the name of the Hub.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (ASCII characters only). |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="WeDo2SmartHub+setLEDColor"></a>
|
||||
|
||||
@ -554,7 +554,7 @@ Set the name of the Hub.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (ASCII characters only). |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
@ -833,7 +833,7 @@ Set the name of the Hub.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (ASCII characters only). |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
@ -1080,7 +1080,7 @@ Set the name of the Hub.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (ASCII characters only). |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user