node-poweredup
node-poweredup copied to clipboard
RemoteHub "button" event doesn't work!
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
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 => ... );
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.