Added support for more buttons (useful for remote)

This commit is contained in:
Nathan Kunicki 2018-06-21 11:38:04 +01:00
parent b8998751e6
commit 96cd8ad68c
3 changed files with 12 additions and 8 deletions

View File

@ -51,7 +51,7 @@ Emits when a LPF2 Hub device is found.
* [.connect([callback])](#Hub+connect)
* [.subscribe(port, [mode])](#Hub+subscribe)
* [.unsubscribe(port)](#Hub+unsubscribe)
* ["button" (state)](#BoostHub+event_button)
* ["button" (button, state)](#BoostHub+event_button)
* ["distance" (port, distance)](#BoostHub+event_distance)
* ["color" (port, color)](#BoostHub+event_color)
* ["tilt" (port, x, y)](#BoostHub+event_tilt)
@ -134,13 +134,14 @@ Unsubscribe to sensor notifications on a given port.
<a name="BoostHub+event_button"></a>
### "button" (state)
### "button" (button, state)
Emits when a button is pressed.
**Kind**: event emitted by [<code>BoostHub</code>](#BoostHub)
| Param | Type | Description |
| --- | --- | --- |
| button | <code>string</code> | |
| state | <code>number</code> | A number representing one of the button state consts. |
<a name="BoostHub+event_distance"></a>
@ -205,7 +206,7 @@ Emits when a rotation sensor is activated.
* [.connect([callback])](#Hub+connect)
* [.subscribe(port, [mode])](#Hub+subscribe)
* [.unsubscribe(port)](#Hub+unsubscribe)
* ["button" (state)](#WeDo2Hub+event_button)
* ["button" (button, state)](#WeDo2Hub+event_button)
* ["distance" (port, distance)](#WeDo2Hub+event_distance)
* ["color" (port, color)](#WeDo2Hub+event_color)
* ["tilt" (port, x, y)](#WeDo2Hub+event_tilt)
@ -287,13 +288,14 @@ Unsubscribe to sensor notifications on a given port.
<a name="WeDo2Hub+event_button"></a>
### "button" (state)
### "button" (button, state)
Emits when a button is pressed.
**Kind**: event emitted by [<code>WeDo2Hub</code>](#WeDo2Hub)
| Param | Type | Description |
| --- | --- | --- |
| button | <code>string</code> | |
| state | <code>number</code> | A number representing one of the button state consts. |
<a name="WeDo2Hub+event_distance"></a>

View File

@ -220,12 +220,13 @@ export class BoostHub extends Hub {
/**
* Emits when a button is pressed.
* @event BoostHub#button
* @param {string} button
* @param {number} state A number representing one of the button state consts.
*/
this.emit("button", Consts.ButtonStates.PRESSED);
this.emit("button", "GREEN", Consts.ButtonStates.PRESSED);
return;
} else if (data[5] === 0) {
this.emit("button", Consts.ButtonStates.RELEASED);
this.emit("button", "GREEN", Consts.ButtonStates.RELEASED);
return;
}
}

View File

@ -169,12 +169,13 @@ export class WeDo2Hub extends Hub {
/**
* Emits when a button is pressed.
* @event WeDo2Hub#button
* @param {string} button
* @param {number} state A number representing one of the button state consts.
*/
this.emit("button", Consts.ButtonStates.PRESSED);
this.emit("button", "GREEN", Consts.ButtonStates.PRESSED);
return;
} else if (data[0] === 0) {
this.emit("button", Consts.ButtonStates.RELEASED);
this.emit("button", "GREEN", Consts.ButtonStates.RELEASED);
return;
}