rdepena / node-dualshock-controller

Eventing API layer over HID for the Sony DualShock 3 and DualShock 4 controllers
208 stars 46 forks source link

Support multiple controllers (#68) #85

Closed marxarelli closed 2 years ago

marxarelli commented 4 years ago

Removed use of global config module in favor of Config objects that can be encapsulated by each Controller instance, allowing distinct instantiations of the latter and avoiding race conditions should instantiation take place within async events.

Introduced optional index option that specifies which of the discovered HID devices (matched vendor and product ID) to use for the given controller config. Note that discovered controllers are sorted by device path before assignment to ensure consistency in selection.

Exposed Controller as part of the core module to make multiple instantiation seem more clear. However, the original dualShock entry-point function was left for backwards compatibility.

Example:

var ds = require('dualshock-controller');

var
  ds1 = new ds.Controller({ config: "dualshock4", index: 0 }),
  ds2 = new ds.Controller({ config: "dualshock4", index: 1 }),
  ds3 = new ds.Controller({ config: "dualshock3", index: 0 });