node-poweredup icon indicating copy to clipboard operation
node-poweredup copied to clipboard

RemoteHub "button" event doesn't work!

Open DJj123dj opened this issue 2 years ago • 2 comments

When I connect a remoteHub to node-poweredup and I check for the button event, it doesn't work correctly. I only get the center button when pressed.

Here is my code:

const PU = require("node-poweredup")
const poweredUP = new PU.PoweredUP()


poweredUP.on("discover", async (hub) => { 
    await hub.connect()
    console.log("connected!")

    hub.on("button",(button,state) => {
        console.log("pressed button",button,state)
    })
})
poweredUP.scan()

I'm using MacOS Monterey on a macbook pro with intel chip. My node.js version is 16.16.0

DJj123dj avatar Dec 03 '22 22:12 DJj123dj

This "button" event is only triggered by pressing the button on the hub, if you're trying to use a button device or controller then you have to access it via the port it is connected to, e.g.

const button = await hub.waitForDeviceAtPort("LEFT");
button.on("remoteButton", event => ... );

highflying avatar Dec 05 '22 09:12 highflying

Thanks it works! I only have one more question: I think that there is something wrong in the documentation, because there it is saying that you need to listen to the "button" event and not the "remoteButton" event. Schermafbeelding 2022-12-05 om 19 50 23

DJj123dj avatar Dec 05 '22 18:12 DJj123dj