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

Commit 37d8690

Browse files
committed
Added support for deadzones in analogue sticks
1 parent 21687d0 commit 37d8690

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Mac OSX driver: http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/O
3939

4040
## TODO
4141

42-
* stick deadzones
4342
* rumble control
4443
* led control
4544

lib/xbox.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var HID = require('node-hid'),
33
colors = require('colors'),
44
events = require('events');
55

6+
var dead = 6000;
67

78
var buttons = {
89
'dup': {
@@ -144,6 +145,13 @@ XboxController.prototype.interpretData = function(error, data) {
144145
var lefty = uint8Toint16(data[8], data[9])
145146

146147
if(leftx ^ this.leftx | lefty ^ this.lefty){
148+
if (leftx > -1*dead && leftx < dead ){
149+
leftx = 0
150+
}
151+
if (lefty > -1*dead && lefty < dead ){
152+
lefty = 0
153+
}
154+
147155
this.emit('left:move', {x: leftx, y: lefty})
148156
this.leftx = leftx
149157
this.lefty = lefty
@@ -153,6 +161,12 @@ XboxController.prototype.interpretData = function(error, data) {
153161
var righty = uint8Toint16(data[12], data[13])
154162

155163
if(rightx ^ this.rightx | righty ^ this.righty){
164+
if (rightx > -1*dead && rightx < dead ){
165+
rightx = 0
166+
}
167+
if (righty > -1*dead && righty < dead ){
168+
righty = 0
169+
}
156170
this.emit('right:move', {x: rightx, y: righty})
157171
this.rightx = rightx
158172
this.righty = righty

0 commit comments

Comments
 (0)