nathankellenicki / node-poweredup

A Javascript module to interface with LEGO Powered Up components.
https://nathankellenicki.github.io/node-poweredup/
MIT License
477 stars 59 forks source link

RemoteHub "button" event doesn't work! #173

Closed DJj123dj closed 4 months ago

DJj123dj commented 1 year ago

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

highflying commented 1 year ago

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 => ... );
DJj123dj commented 1 year ago

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