From f782317468e699dd802b45083207787b45bde6b4 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Wed, 1 Aug 2018 10:23:58 +0100 Subject: [PATCH] Better motor control, better documentation --- DOCS.md | 192 ++++------------------------------------------------- README.md | 192 ++++------------------------------------------------- hub.ts | 1 + lpf2hub.ts | 5 +- 4 files changed, 26 insertions(+), 364 deletions(-) diff --git a/DOCS.md b/DOCS.md index 25a5c5a..f9695ed 100644 --- a/DOCS.md +++ b/DOCS.md @@ -3,11 +3,9 @@
LPF2EventEmitter
-
LPF2HubHub
+
LPF2HubHub
-
WeDo2HubHub
-
-
HubEventEmitter
+
WeDo2HubHub
@@ -20,8 +18,8 @@ * [LPF2](#LPF2) ⇐ EventEmitter * [.scan()](#LPF2+scan) * [.stop()](#LPF2+stop) - * [.getConnectedHubByUUID(uuid)](#LPF2+getConnectedHubByUUID) ⇒ [Hub](#Hub) \| null - * [.getConnectedHubs()](#LPF2+getConnectedHubs) ⇒ [Array.<Hub>](#Hub) + * [.getConnectedHubByUUID(uuid)](#LPF2+getConnectedHubByUUID) ⇒ Hub \| null + * [.getConnectedHubs()](#LPF2+getConnectedHubs) ⇒ Array.<Hub> * ["discover" (hub)](#LPF2+event_discover) @@ -38,7 +36,7 @@ Stop scanning for LPF2 Hub devices. **Kind**: instance method of [LPF2](#LPF2) -### lpF2.getConnectedHubByUUID(uuid) ⇒ [Hub](#Hub) \| null +### lpF2.getConnectedHubByUUID(uuid) ⇒ Hub \| null Retrieve a LPF2 Hub by UUID. **Kind**: instance method of [LPF2](#LPF2) @@ -49,7 +47,7 @@ Retrieve a LPF2 Hub by UUID. -### lpF2.getConnectedHubs() ⇒ [Array.<Hub>](#Hub) +### lpF2.getConnectedHubs() ⇒ Array.<Hub> Retrieve a list of LPF2 Hubs. **Kind**: instance method of [LPF2](#LPF2) @@ -66,11 +64,11 @@ Emits when a LPF2 Hub device is found. -## LPF2Hub ⇐ [Hub](#Hub) +## LPF2Hub ⇐ Hub **Kind**: global class -**Extends**: [Hub](#Hub) +**Extends**: Hub -* [LPF2Hub](#LPF2Hub) ⇐ [Hub](#Hub) +* [LPF2Hub](#LPF2Hub) ⇐ Hub * [new LPF2Hub()](#new_LPF2Hub_new) * [.name](#Hub+name) * [.uuid](#Hub+uuid) @@ -348,11 +346,11 @@ Emits when an attached motor or sensor is detached from the Hub. -## WeDo2Hub ⇐ [Hub](#Hub) +## WeDo2Hub ⇐ Hub **Kind**: global class -**Extends**: [Hub](#Hub) +**Extends**: Hub -* [WeDo2Hub](#WeDo2Hub) ⇐ [Hub](#Hub) +* [WeDo2Hub](#WeDo2Hub) ⇐ Hub * [new WeDo2Hub()](#new_WeDo2Hub_new) * [.name](#Hub+name) * [.uuid](#Hub+uuid) @@ -642,169 +640,3 @@ Emits when an attached motor or sensor is detached from the Hub. | --- | --- | | port | string | - - -## Hub ⇐ EventEmitter -**Kind**: global class -**Extends**: EventEmitter - -* [Hub](#Hub) ⇐ EventEmitter - * [.name](#Hub+name) - * [.uuid](#Hub+uuid) - * [.rssi](#Hub+rssi) - * [.batteryLevel](#Hub+batteryLevel) - * [.current](#Hub+current) - * [.connect()](#Hub+connect) ⇒ Promise - * [.disconnect()](#Hub+disconnect) ⇒ Promise - * [.subscribe(port, [mode])](#Hub+subscribe) ⇒ Promise - * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ Promise - * [.sleep(delay)](#Hub+sleep) ⇒ Promise - * [.wait(commands)](#Hub+wait) ⇒ Promise - * ["attach" (port, type)](#Hub+event_attach) - * ["detach" (port)](#Hub+event_detach) - - - -### hub.name -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| name | string | Name of the hub | - - - -### hub.uuid -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| uuid | string | UUID of the hub | - - - -### hub.rssi -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| rssi | number | Signal strength of the hub | - - - -### hub.batteryLevel -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| batteryLevel | number | Battery level of the hub (Percentage between 0-100) | - - - -### hub.current -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| current | number | Current usage of the hub (Amps) | - - - -### hub.connect() ⇒ Promise -Connect to the Hub. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved upon successful connect. - - -### hub.disconnect() ⇒ Promise -Disconnect the Hub. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved upon successful disconnect. - - -### hub.subscribe(port, [mode]) ⇒ Promise -Subscribe to sensor notifications on a given port. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved upon successful issuance of command. - -| Param | Type | Description | -| --- | --- | --- | -| port | string | | -| [mode] | number | The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen. | - - - -### hub.unsubscribe(port) ⇒ Promise -Unsubscribe to sensor notifications on a given port. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved upon successful issuance of command. - -| Param | Type | -| --- | --- | -| port | string | - - - -### hub.sleep(delay) ⇒ Promise -Sleep a given amount of time. - -This is a helper method to make it easier to add delays into a chain of commands. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved after the delay is finished. - -| Param | Type | Description | -| --- | --- | --- | -| delay | number | How long to sleep (in milliseconds). | - - - -### hub.wait(commands) ⇒ Promise -Wait until a given list of concurrently running commands are complete. - -This is a helper method to make it easier to wait for concurrent commands to complete. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved after the commands are finished. - -| Param | Type | Description | -| --- | --- | --- | -| commands | Array.<Promise.<any>> | Array of executing commands. | - - - -### "attach" (port, type) -Emits when a motor or sensor is attached to the Hub. - -**Kind**: event emitted by [Hub](#Hub) - -| Param | Type | Description | -| --- | --- | --- | -| port | string | | -| type | number | A number representing one of the peripheral consts. | - - - -### "detach" (port) -Emits when an attached motor or sensor is detached from the Hub. - -**Kind**: event emitted by [Hub](#Hub) - -| Param | Type | -| --- | --- | -| port | string | - diff --git a/README.md b/README.md index 89d3800..e8f7d42 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,9 @@ Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian R
LPF2EventEmitter
-
LPF2HubHub
+
LPF2HubHub
-
WeDo2HubHub
-
-
HubEventEmitter
+
WeDo2HubHub
@@ -70,8 +68,8 @@ Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian R * [LPF2](#LPF2) ⇐ EventEmitter * [.scan()](#LPF2+scan) * [.stop()](#LPF2+stop) - * [.getConnectedHubByUUID(uuid)](#LPF2+getConnectedHubByUUID) ⇒ [Hub](#Hub) \| null - * [.getConnectedHubs()](#LPF2+getConnectedHubs) ⇒ [Array.<Hub>](#Hub) + * [.getConnectedHubByUUID(uuid)](#LPF2+getConnectedHubByUUID) ⇒ Hub \| null + * [.getConnectedHubs()](#LPF2+getConnectedHubs) ⇒ Array.<Hub> * ["discover" (hub)](#LPF2+event_discover) @@ -88,7 +86,7 @@ Stop scanning for LPF2 Hub devices. **Kind**: instance method of [LPF2](#LPF2) -### lpF2.getConnectedHubByUUID(uuid) ⇒ [Hub](#Hub) \| null +### lpF2.getConnectedHubByUUID(uuid) ⇒ Hub \| null Retrieve a LPF2 Hub by UUID. **Kind**: instance method of [LPF2](#LPF2) @@ -99,7 +97,7 @@ Retrieve a LPF2 Hub by UUID. -### lpF2.getConnectedHubs() ⇒ [Array.<Hub>](#Hub) +### lpF2.getConnectedHubs() ⇒ Array.<Hub> Retrieve a list of LPF2 Hubs. **Kind**: instance method of [LPF2](#LPF2) @@ -116,11 +114,11 @@ Emits when a LPF2 Hub device is found. -## LPF2Hub ⇐ [Hub](#Hub) +## LPF2Hub ⇐ Hub **Kind**: global class -**Extends**: [Hub](#Hub) +**Extends**: Hub -* [LPF2Hub](#LPF2Hub) ⇐ [Hub](#Hub) +* [LPF2Hub](#LPF2Hub) ⇐ Hub * [new LPF2Hub()](#new_LPF2Hub_new) * [.name](#Hub+name) * [.uuid](#Hub+uuid) @@ -398,11 +396,11 @@ Emits when an attached motor or sensor is detached from the Hub. -## WeDo2Hub ⇐ [Hub](#Hub) +## WeDo2Hub ⇐ Hub **Kind**: global class -**Extends**: [Hub](#Hub) +**Extends**: Hub -* [WeDo2Hub](#WeDo2Hub) ⇐ [Hub](#Hub) +* [WeDo2Hub](#WeDo2Hub) ⇐ Hub * [new WeDo2Hub()](#new_WeDo2Hub_new) * [.name](#Hub+name) * [.uuid](#Hub+uuid) @@ -692,169 +690,3 @@ Emits when an attached motor or sensor is detached from the Hub. | --- | --- | | port | string | - - -## Hub ⇐ EventEmitter -**Kind**: global class -**Extends**: EventEmitter - -* [Hub](#Hub) ⇐ EventEmitter - * [.name](#Hub+name) - * [.uuid](#Hub+uuid) - * [.rssi](#Hub+rssi) - * [.batteryLevel](#Hub+batteryLevel) - * [.current](#Hub+current) - * [.connect()](#Hub+connect) ⇒ Promise - * [.disconnect()](#Hub+disconnect) ⇒ Promise - * [.subscribe(port, [mode])](#Hub+subscribe) ⇒ Promise - * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ Promise - * [.sleep(delay)](#Hub+sleep) ⇒ Promise - * [.wait(commands)](#Hub+wait) ⇒ Promise - * ["attach" (port, type)](#Hub+event_attach) - * ["detach" (port)](#Hub+event_detach) - - - -### hub.name -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| name | string | Name of the hub | - - - -### hub.uuid -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| uuid | string | UUID of the hub | - - - -### hub.rssi -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| rssi | number | Signal strength of the hub | - - - -### hub.batteryLevel -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| batteryLevel | number | Battery level of the hub (Percentage between 0-100) | - - - -### hub.current -**Kind**: instance property of [Hub](#Hub) -**Read only**: true -**Properties** - -| Name | Type | Description | -| --- | --- | --- | -| current | number | Current usage of the hub (Amps) | - - - -### hub.connect() ⇒ Promise -Connect to the Hub. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved upon successful connect. - - -### hub.disconnect() ⇒ Promise -Disconnect the Hub. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved upon successful disconnect. - - -### hub.subscribe(port, [mode]) ⇒ Promise -Subscribe to sensor notifications on a given port. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved upon successful issuance of command. - -| Param | Type | Description | -| --- | --- | --- | -| port | string | | -| [mode] | number | The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen. | - - - -### hub.unsubscribe(port) ⇒ Promise -Unsubscribe to sensor notifications on a given port. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved upon successful issuance of command. - -| Param | Type | -| --- | --- | -| port | string | - - - -### hub.sleep(delay) ⇒ Promise -Sleep a given amount of time. - -This is a helper method to make it easier to add delays into a chain of commands. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved after the delay is finished. - -| Param | Type | Description | -| --- | --- | --- | -| delay | number | How long to sleep (in milliseconds). | - - - -### hub.wait(commands) ⇒ Promise -Wait until a given list of concurrently running commands are complete. - -This is a helper method to make it easier to wait for concurrent commands to complete. - -**Kind**: instance method of [Hub](#Hub) -**Returns**: Promise - Resolved after the commands are finished. - -| Param | Type | Description | -| --- | --- | --- | -| commands | Array.<Promise.<any>> | Array of executing commands. | - - - -### "attach" (port, type) -Emits when a motor or sensor is attached to the Hub. - -**Kind**: event emitted by [Hub](#Hub) - -| Param | Type | Description | -| --- | --- | --- | -| port | string | | -| type | number | A number representing one of the peripheral consts. | - - - -### "detach" (port) -Emits when an attached motor or sensor is detached from the Hub. - -**Kind**: event emitted by [Hub](#Hub) - -| Param | Type | -| --- | --- | -| port | string | - diff --git a/hub.ts b/hub.ts index de866ed..b1b17cf 100644 --- a/hub.ts +++ b/hub.ts @@ -11,6 +11,7 @@ const debug = Debug("hub"); /** * @class Hub + * @ignore * @extends EventEmitter */ export class Hub extends EventEmitter { diff --git a/lpf2hub.ts b/lpf2hub.ts index 942185a..5cd6f2d 100644 --- a/lpf2hub.ts +++ b/lpf2hub.ts @@ -93,15 +93,12 @@ export class LPF2Hub extends Hub { */ public setLEDColor (color: number | boolean) { return new Promise((resolve, reject) => { - let data = Buffer.from([0x05, 0x00, 0x01, 0x02, 0x02]); - this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data); if (color === false) { color = 0; } + let data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]); if (this.type === Consts.Hubs.POWERED_UP_REMOTE) { data = Buffer.from([0x08, 0x00, 0x81, 0x34, 0x11, 0x51, 0x00, color]); - } else { - data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]); } this._writeMessage(Consts.BLECharacteristics.BOOST_ALL, data); return resolve();