From 96cd8ad68c025781c049dd00450dcff627f5c2ca Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Thu, 21 Jun 2018 11:38:04 +0100 Subject: [PATCH] Added support for more buttons (useful for remote) --- README.md | 10 ++++++---- boosthub.ts | 5 +++-- wedo2hub.ts | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 70cc829..55f2f83 100644 --- a/README.md +++ b/README.md @@ -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. -### "button" (state) +### "button" (button, state) Emits when a button is pressed. **Kind**: event emitted by [BoostHub](#BoostHub) | Param | Type | Description | | --- | --- | --- | +| button | string | | | state | number | A number representing one of the button state consts. | @@ -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. -### "button" (state) +### "button" (button, state) Emits when a button is pressed. **Kind**: event emitted by [WeDo2Hub](#WeDo2Hub) | Param | Type | Description | | --- | --- | --- | +| button | string | | | state | number | A number representing one of the button state consts. | diff --git a/boosthub.ts b/boosthub.ts index ab10d0a..ee17ed2 100644 --- a/boosthub.ts +++ b/boosthub.ts @@ -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; } } diff --git a/wedo2hub.ts b/wedo2hub.ts index 90b9ee6..06b7210 100644 --- a/wedo2hub.ts +++ b/wedo2hub.ts @@ -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; }