Added attach/detach events
This commit is contained in:
parent
12e3fdb8b7
commit
ed515d6ec0
75
DOCS.md
75
DOCS.md
@ -86,6 +86,8 @@ Emits when a LPF2 Hub device is found.
|
|||||||
* ["color" (port, color)](#LPF2Hub+event_color)
|
* ["color" (port, color)](#LPF2Hub+event_color)
|
||||||
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
|
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
|
||||||
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
|
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
|
||||||
|
* ["attach" (port, type)](#Hub+event_attach)
|
||||||
|
* ["detach" (port)](#Hub+event_detach)
|
||||||
|
|
||||||
<a name="new_LPF2Hub_new"></a>
|
<a name="new_LPF2Hub_new"></a>
|
||||||
|
|
||||||
@ -261,6 +263,29 @@ Emits when a rotation sensor is activated.
|
|||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| rotation | <code>number</code> |
|
| rotation | <code>number</code> |
|
||||||
|
|
||||||
|
<a name="Hub+event_attach"></a>
|
||||||
|
|
||||||
|
### "attach" (port, type)
|
||||||
|
Emits when a motor or sensor is attached to the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>LPF2Hub</code>](#LPF2Hub)
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| port | <code>string</code> | |
|
||||||
|
| type | <code>number</code> | A number representing one of the peripheral consts. |
|
||||||
|
|
||||||
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
|
### "detach" (port)
|
||||||
|
Emits when an attached motor or sensor is detached from the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>LPF2Hub</code>](#LPF2Hub)
|
||||||
|
|
||||||
|
| Param | Type |
|
||||||
|
| --- | --- |
|
||||||
|
| port | <code>string</code> |
|
||||||
|
|
||||||
<a name="WeDo2Hub"></a>
|
<a name="WeDo2Hub"></a>
|
||||||
|
|
||||||
## WeDo2Hub ⇐ [<code>Hub</code>](#Hub)
|
## WeDo2Hub ⇐ [<code>Hub</code>](#Hub)
|
||||||
@ -283,6 +308,8 @@ Emits when a rotation sensor is activated.
|
|||||||
* ["color" (port, color)](#WeDo2Hub+event_color)
|
* ["color" (port, color)](#WeDo2Hub+event_color)
|
||||||
* ["tilt" (port, x, y)](#WeDo2Hub+event_tilt)
|
* ["tilt" (port, x, y)](#WeDo2Hub+event_tilt)
|
||||||
* ["rotate" (port, rotation)](#WeDo2Hub+event_rotate)
|
* ["rotate" (port, rotation)](#WeDo2Hub+event_rotate)
|
||||||
|
* ["attach" (port, type)](#Hub+event_attach)
|
||||||
|
* ["detach" (port)](#Hub+event_detach)
|
||||||
|
|
||||||
<a name="new_WeDo2Hub_new"></a>
|
<a name="new_WeDo2Hub_new"></a>
|
||||||
|
|
||||||
@ -457,6 +484,29 @@ Emits when a rotation sensor is activated.
|
|||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| rotation | <code>number</code> |
|
| rotation | <code>number</code> |
|
||||||
|
|
||||||
|
<a name="Hub+event_attach"></a>
|
||||||
|
|
||||||
|
### "attach" (port, type)
|
||||||
|
Emits when a motor or sensor is attached to the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| port | <code>string</code> | |
|
||||||
|
| type | <code>number</code> | A number representing one of the peripheral consts. |
|
||||||
|
|
||||||
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
|
### "detach" (port)
|
||||||
|
Emits when an attached motor or sensor is detached from the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||||
|
|
||||||
|
| Param | Type |
|
||||||
|
| --- | --- |
|
||||||
|
| port | <code>string</code> |
|
||||||
|
|
||||||
<a name="Hub"></a>
|
<a name="Hub"></a>
|
||||||
|
|
||||||
## Hub ⇐ <code>EventEmitter</code>
|
## Hub ⇐ <code>EventEmitter</code>
|
||||||
@ -470,6 +520,8 @@ Emits when a rotation sensor is activated.
|
|||||||
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
||||||
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
|
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
|
||||||
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
|
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
|
||||||
|
* ["attach" (port, type)](#Hub+event_attach)
|
||||||
|
* ["detach" (port)](#Hub+event_detach)
|
||||||
|
|
||||||
<a name="Hub+connect"></a>
|
<a name="Hub+connect"></a>
|
||||||
|
|
||||||
@ -538,3 +590,26 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
||||||
|
|
||||||
|
<a name="Hub+event_attach"></a>
|
||||||
|
|
||||||
|
### "attach" (port, type)
|
||||||
|
Emits when a motor or sensor is attached to the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>Hub</code>](#Hub)
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| port | <code>string</code> | |
|
||||||
|
| type | <code>number</code> | A number representing one of the peripheral consts. |
|
||||||
|
|
||||||
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
|
### "detach" (port)
|
||||||
|
Emits when an attached motor or sensor is detached from the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>Hub</code>](#Hub)
|
||||||
|
|
||||||
|
| Param | Type |
|
||||||
|
| --- | --- |
|
||||||
|
| port | <code>string</code> |
|
||||||
|
|
||||||
|
75
README.md
75
README.md
@ -127,6 +127,8 @@ Emits when a LPF2 Hub device is found.
|
|||||||
* ["color" (port, color)](#LPF2Hub+event_color)
|
* ["color" (port, color)](#LPF2Hub+event_color)
|
||||||
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
|
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
|
||||||
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
|
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
|
||||||
|
* ["attach" (port, type)](#Hub+event_attach)
|
||||||
|
* ["detach" (port)](#Hub+event_detach)
|
||||||
|
|
||||||
<a name="new_LPF2Hub_new"></a>
|
<a name="new_LPF2Hub_new"></a>
|
||||||
|
|
||||||
@ -302,6 +304,29 @@ Emits when a rotation sensor is activated.
|
|||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| rotation | <code>number</code> |
|
| rotation | <code>number</code> |
|
||||||
|
|
||||||
|
<a name="Hub+event_attach"></a>
|
||||||
|
|
||||||
|
### "attach" (port, type)
|
||||||
|
Emits when a motor or sensor is attached to the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>LPF2Hub</code>](#LPF2Hub)
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| port | <code>string</code> | |
|
||||||
|
| type | <code>number</code> | A number representing one of the peripheral consts. |
|
||||||
|
|
||||||
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
|
### "detach" (port)
|
||||||
|
Emits when an attached motor or sensor is detached from the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>LPF2Hub</code>](#LPF2Hub)
|
||||||
|
|
||||||
|
| Param | Type |
|
||||||
|
| --- | --- |
|
||||||
|
| port | <code>string</code> |
|
||||||
|
|
||||||
<a name="WeDo2Hub"></a>
|
<a name="WeDo2Hub"></a>
|
||||||
|
|
||||||
## WeDo2Hub ⇐ [<code>Hub</code>](#Hub)
|
## WeDo2Hub ⇐ [<code>Hub</code>](#Hub)
|
||||||
@ -324,6 +349,8 @@ Emits when a rotation sensor is activated.
|
|||||||
* ["color" (port, color)](#WeDo2Hub+event_color)
|
* ["color" (port, color)](#WeDo2Hub+event_color)
|
||||||
* ["tilt" (port, x, y)](#WeDo2Hub+event_tilt)
|
* ["tilt" (port, x, y)](#WeDo2Hub+event_tilt)
|
||||||
* ["rotate" (port, rotation)](#WeDo2Hub+event_rotate)
|
* ["rotate" (port, rotation)](#WeDo2Hub+event_rotate)
|
||||||
|
* ["attach" (port, type)](#Hub+event_attach)
|
||||||
|
* ["detach" (port)](#Hub+event_detach)
|
||||||
|
|
||||||
<a name="new_WeDo2Hub_new"></a>
|
<a name="new_WeDo2Hub_new"></a>
|
||||||
|
|
||||||
@ -498,6 +525,29 @@ Emits when a rotation sensor is activated.
|
|||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| rotation | <code>number</code> |
|
| rotation | <code>number</code> |
|
||||||
|
|
||||||
|
<a name="Hub+event_attach"></a>
|
||||||
|
|
||||||
|
### "attach" (port, type)
|
||||||
|
Emits when a motor or sensor is attached to the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| port | <code>string</code> | |
|
||||||
|
| type | <code>number</code> | A number representing one of the peripheral consts. |
|
||||||
|
|
||||||
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
|
### "detach" (port)
|
||||||
|
Emits when an attached motor or sensor is detached from the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||||
|
|
||||||
|
| Param | Type |
|
||||||
|
| --- | --- |
|
||||||
|
| port | <code>string</code> |
|
||||||
|
|
||||||
<a name="Hub"></a>
|
<a name="Hub"></a>
|
||||||
|
|
||||||
## Hub ⇐ <code>EventEmitter</code>
|
## Hub ⇐ <code>EventEmitter</code>
|
||||||
@ -511,6 +561,8 @@ Emits when a rotation sensor is activated.
|
|||||||
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
||||||
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
|
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
|
||||||
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
|
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
|
||||||
|
* ["attach" (port, type)](#Hub+event_attach)
|
||||||
|
* ["detach" (port)](#Hub+event_detach)
|
||||||
|
|
||||||
<a name="Hub+connect"></a>
|
<a name="Hub+connect"></a>
|
||||||
|
|
||||||
@ -579,3 +631,26 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
||||||
|
|
||||||
|
<a name="Hub+event_attach"></a>
|
||||||
|
|
||||||
|
### "attach" (port, type)
|
||||||
|
Emits when a motor or sensor is attached to the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>Hub</code>](#Hub)
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| port | <code>string</code> | |
|
||||||
|
| type | <code>number</code> | A number representing one of the peripheral consts. |
|
||||||
|
|
||||||
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
|
### "detach" (port)
|
||||||
|
Emits when an attached motor or sensor is detached from the Hub.
|
||||||
|
|
||||||
|
**Kind**: event emitted by [<code>Hub</code>](#Hub)
|
||||||
|
|
||||||
|
| Param | Type |
|
||||||
|
| --- | --- |
|
||||||
|
| port | <code>string</code> |
|
||||||
|
|
||||||
|
13
hub.ts
13
hub.ts
@ -217,10 +217,23 @@ export class Hub extends EventEmitter {
|
|||||||
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.
|
||||||
|
* @event Hub#attach
|
||||||
|
* @param {string} port
|
||||||
|
* @param {number} type A number representing one of the peripheral consts.
|
||||||
|
*/
|
||||||
|
this.emit("attach", port.id, type);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
port.type = Consts.Devices.UNKNOWN;
|
port.type = Consts.Devices.UNKNOWN;
|
||||||
debug(`Port ${port.id} disconnected`);
|
debug(`Port ${port.id} disconnected`);
|
||||||
|
/**
|
||||||
|
* Emits when an attached motor or sensor is detached from the Hub.
|
||||||
|
* @event Hub#detach
|
||||||
|
* @param {string} port
|
||||||
|
*/
|
||||||
|
this.emit("detach", port.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user