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

Commit d896462

Browse files
committed
Add LED support and fix packages with npm
1 parent 7d26099 commit d896462

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

lib/xbox.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var buttons = {
99
'dup': {
1010
'block': 2,
1111
'bitwise': 0x01
12-
},
12+
},
1313
'ddown':{
1414
'block': 2,
1515
'bitwise': 0x02
@@ -93,7 +93,7 @@ function XboxController()
9393
var device
9494
devices.forEach((function(d) {
9595
if(typeof d === 'object' && d.product.toLowerCase().indexOf('controller') !== -1) {
96-
96+
9797
device = new HID.HID(d.path)
9898
}
9999
}).bind(this))
@@ -143,15 +143,15 @@ XboxController.prototype.interpretData = function(error, data) {
143143

144144
var leftx = uint8Toint16(data[6], data[7])
145145
var lefty = uint8Toint16(data[8], data[9])
146-
146+
147147
if(leftx ^ this.leftx | lefty ^ this.lefty){
148148
if (leftx > -1*dead && leftx < dead ){
149149
leftx = 0
150150
}
151151
if (lefty > -1*dead && lefty < dead ){
152152
lefty = 0
153153
}
154-
154+
155155
this.emit('left:move', {x: leftx, y: lefty})
156156
this.leftx = leftx
157157
this.lefty = lefty
@@ -175,4 +175,33 @@ XboxController.prototype.interpretData = function(error, data) {
175175
this.hid.read(this.interpretData.bind(this));
176176
}
177177

178+
/*
179+
180+
Pattern Description
181+
0x00 All off
182+
0x01 All blinking
183+
0x02 1 flashes, then on
184+
0x03 2 flashes, then on
185+
0x04 3 flashes, then on
186+
0x05 4 flashes, then on
187+
0x06 1 on
188+
0x07 2 on
189+
0x08 3 on
190+
0x09 4 on
191+
0x0A Rotating (e.g. 1-2-4-3)
192+
0x0B Blinking*
193+
0x0C Slow blinking*
194+
0x0D Alternating (e.g. 1+4-2+3), then back to previous*
195+
196+
*/
197+
// input one of the patterns above
198+
XboxController.prototype.setLed = function(hex) {
199+
try{
200+
this.hid.write( [0x01, 0x03, hex ] );
201+
}
202+
catch ( ex ){
203+
console.log( 'error: '.red, 'Xbox cant set LED to HEX ' + hex );
204+
}
205+
}
206+
178207
module.exports = XboxController

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
],
2121
"main": "./lib/xbox.js",
2222
"dependencies": {
23-
"node-hid": ">0",
24-
"colors" : ">0"
23+
"node-hid": ">=0",
24+
"colors" : ">=0"
2525
},
2626
"scripts" : {
2727
"test" : "node ./tests/test.js"

0 commit comments

Comments
 (0)