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

Use path as identifier for controller passed to HID.HID

Open lukekarrys opened this issue 11 years ago • 9 comments

For a couple reasons:

  1. This seems like the preferred way, at least according to the node-hid docs: https://github.com/node-hid/node-hid#opening-a-device
  2. Opens up the possibility for multiple controller support, since paths are unique (at least in my tests with Retrolink SNES controllers). Although that would require a few more changes (which I think would be very cool).

I think this wouldn't require too much code after #6 since we already can look through the output from HID.devices.

I can have a PR for this sometime soon (with a multicontroller example), but wanted to make sure there was interest first.

lukekarrys avatar Jun 05 '14 15:06 lukekarrys

Multiple controller support would be :sparkles:, I think what you're describing is basically how the https://github.com/andrew/node-xbox-controller library works as well if you need another example.

andrew avatar Jun 05 '14 16:06 andrew

Thanks @andrew, and yeah this is pretty close to what I was thinking. As for proposed multicontroller support, here's what I was thinking for possible syntax:

Option1: Have the user manage it themselves

var snes1 = new GamePad('snes').connect();
var snes2 = new GamePad('snes', { usedPaths: snes1.getPath() }).connect();

Option 2: pass an array to the constructor

var snes = new GamePad(['snes', 'snes']);
snes.connect();
snes[0].on('a:press', console.log);
snes[1].on('a:press', console.log);

Option 2 would require a lot more changes under the hood, but then node-gamepad could keep track of what paths have already been used. Or tell me both of these are bad, and there's something better :smile:

lukekarrys avatar Jun 05 '14 16:06 lukekarrys

Great idea for multi-controller support! I'm not sold on the idea of passing an array in simply because they really should be separate objects.

Just thinking through a few different options here:

Option A:

Have GamePad detect any controllers that are found and store meta information about each controller...

var detectedControllers = GamePad.detectControllers();
var playerOne = new GamePad( detectedControllers.snes[0].path );
var playerTwo = new GamePad( detectedControllers.snes[1].path );
var ps3 = new GamePad( detectedControllers.ps3.path );

Option B:

Do they really need to specify which controller they want to use? This feature would be really cool but it also scares me (potentially something extra we'd have to support).

var controllers = GamePad.loadControllers();
controllers.snes[0].on( 'connected', callback );
controllers.snes[1].on( 'connected', callback );
controllers.ps3.on( 'connected', callback );

carldanley avatar Jun 12 '14 07:06 carldanley

I like Option B. It is something extra to support, but I think it'd very useful as a kind of auto-setup feature. Any other opinions/options? I might try to take a stab at this in the coming week.

lukekarrys avatar Jun 16 '14 20:06 lukekarrys

Any update on this? I would like support for multiple controllers.

mikeytdan avatar Aug 29 '14 03:08 mikeytdan

hey @mikeytdan: yes! when I get back from Boston, I'll test the code I have against multiple controllers and PR it for others to test. I only have a PS4 controller with me atm.

carldanley avatar Aug 29 '14 14:08 carldanley

Thanks! I can't wait to hear how the testing goes.

mikeytdan avatar Aug 30 '14 02:08 mikeytdan

@carldanley Let me know if you need help testing or anything. I have multiple controllers (2 SNES and 2 N64) and would be happy to help. I've had a todo task in my "later" folder for this for 2 months :grin:

lukekarrys avatar Aug 30 '14 18:08 lukekarrys

@lukekarrys I'll def. need your help with testing the double controllers :)

carldanley avatar Aug 31 '14 05:08 carldanley