Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Commit f556b3a

Browse files
committed
Added ability to specify a different name for the controller
1 parent d854d9f commit f556b3a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ Control left and right rumble motors:
7272

7373
Where the strengths are between 0 and 255.
7474

75+
## Third Party Controllers
76+
77+
If you have a third party controller with a different name you can specify the name when creating the controller:
78+
79+
var xbox = new XboxController('flight stick')
80+
7581
## Copyright
7682

7783
Copyright (c) 2013 Andrew Nesbitt. See [LICENSE](https://github.com/andrew/node-xbox-controller/blob/master/LICENSE) for details.

lib/xbox.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ function uint8Toint16(low, high) {
8787
return int16View[0];
8888
}
8989

90-
function XboxController()
90+
function XboxController(name)
9191
{
92+
this.name = name || 'controller';
9293
this.position = 0;
9394

9495
for (var key in buttons) {
@@ -111,7 +112,7 @@ util.inherits(XboxController, events.EventEmitter);
111112
XboxController.prototype.loadController = function() {
112113

113114
HID.devices().forEach((function(d) {
114-
if(typeof d === 'object' && d.product.toLowerCase().indexOf('controller') !== -1) {
115+
if(typeof d === 'object' && d.product.toLowerCase().indexOf(this.name) !== -1) {
115116
this.hid = new HID.HID(d.path);
116117
console.log( chalk.green('notice: '), 'Xbox controller connected.' );
117118
}

0 commit comments

Comments
 (0)