Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion controllerConfiguration/buttons.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"rb": 5,
"back": 6,
"start": 7,
"start": 7,
"xboxButton": 8,
"leftstickpress": 9,
"rightstickpress": 10,
Expand Down
20 changes: 20 additions & 0 deletions controllerConfiguration/sticks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,25 @@

"axisX": 3,
"axisY": 4
},

"leftTriggerCoordinates": {
"x": 0,

"axisX": 2
},

"rightTriggerCoordinates": {
"x": 4,

"axisX": 5
},

"crossCoordinates": {
"x": 0,
"y": 2,

"axisX": 6,
"axisY": 7
}
}
40 changes: 36 additions & 4 deletions lib/linux-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,31 @@ function LinuxConnector(opts) {
console.log(chalk.green('Notice:'), 'Xbox controller connected');

this.leftStick = new Stick({
reference : 'leftStick',
controller: this.controller,
isLinux: true
});

this.rightStick = new Stick({
reference: 'RIGHT',
reference : 'rightStick',
controller: this.controller,
isLinux: true
});

this.leftTrigger = new Stick({
reference : 'leftTrigger',
controller: this.controller,
isLinux: true
});

this.rightTrigger = new Stick({
reference: 'rightTrigger',
controller: this.controller,
isLinux: true
});

this.cross = new Stick({
reference : 'cross',
controller: this.controller,
isLinux: true
});
Expand All @@ -68,9 +87,22 @@ function LinuxConnector(opts) {
}.bind(this));

this.xboxJoystick.on('axis', function (data) {

this.leftStick.fireStickEvents(data);
this.rightStick.fireStickEvents(data);
// Xbox
// axis 0 LS.x left is -32767
// axis 1 LS.y top is -32767
// axis 2 LT.x released is -32767
// axis 3 RS.x left is -32767
// axis 4 RS.y top is -32767
// axis 5 LT.x released is -32767
// axis 6 CR.x left is -32767
// axis 7 CR.y top is -32767
// console.log(data.number + ' → ' + data.value);

if(data.number == 0 || data.number == 1) this.leftStick.fireStickEvents(data);
if(data.number == 2) this.leftTrigger.fireStickEvents(data);
if(data.number == 3 || data.number == 4) this.rightStick.fireStickEvents(data);
if(data.number == 5) this.rightTrigger.fireStickEvents(data);
if(data.number == 6 || data.number == 7) this.cross.fireStickEvents(data);
}.bind(this));
}.bind(this);

Expand Down
48 changes: 21 additions & 27 deletions lib/stick.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ function Stick(opts) {
this.controller = (opts && opts.controller) || null;
this.isLinux = (opts && opts.isLinux) || false;
this.lastMoveEvent = null;

if (this.reference == 'RIGHT') {
this.HIDCoordinates = sticks.rightStickCoordinates;
}else{
this.HIDCoordinates = sticks.leftStickCoordinates;
}
this.HIDCoordinates = sticks[this.reference + 'Coordinates'];
}

Stick.prototype.fireStickEvents = function (data) {
Expand All @@ -28,7 +23,7 @@ Stick.prototype.fireStickEvents = function (data) {
var _emitStickEvents = function (data) {
var xbox = this.controller,
position, btnRef;

if(this.isLinux){
position = this._getLinuxAxisPosition(data);
}else{
Expand All @@ -37,14 +32,14 @@ Stick.prototype.fireStickEvents = function (data) {

btnRef = this.reference.toLowerCase();

xbox.emit(btnRef + 'stickMove', position);
xbox.emit('anyStickMove', {ref:btnRef,position:position})
xbox.emit(btnRef + 'Move', position);

if (this.lastMoveEvent) {

if (this.lastMoveEvent.axis == 'x' && (position.x != 'none' && position.x != this.lastMoveEvent.bufferValue)) {
xbox.emit(this.lastMoveEvent.name + ':release');

this.lastMoveEvent = null;
}else if (this.lastMoveEvent.axis == 'y' && (position.y != 'none' && position.y != this.lastMoveEvent.bufferValue)){
xbox.emit(this.lastMoveEvent.name + ':release');

Expand All @@ -53,35 +48,35 @@ Stick.prototype.fireStickEvents = function (data) {
}

if(position.x == 255){
setLastMoveEvent(btnRef + 'stickRight', 255, 'x');
setLastMoveEvent(btnRef + 'Right', 255, 'x');

xbox.emit(btnRef + 'stickRight');
xbox.emit(btnRef + 'Right');
}else{
xbox.emit(btnRef + 'stickRight:none');
xbox.emit(btnRef + 'Right:none');
}

if(position.x === 0){
setLastMoveEvent(btnRef + 'stickLeft', 0, 'x');
setLastMoveEvent(btnRef + 'Left', 0, 'x');

xbox.emit(btnRef + 'stickLeft');
xbox.emit(btnRef + 'Left');
}else{
xbox.emit(btnRef + 'stickLeft:none');
xbox.emit(btnRef + 'Left:none');
}

if(position.y == 255){
setLastMoveEvent(btnRef + 'stickDown', 255, 'y');
setLastMoveEvent(btnRef + 'Down', 255, 'y');

xbox.emit(btnRef + 'stickDown');
xbox.emit(btnRef + 'Down');
}else{
xbox.emit(btnRef + 'stickDown:none');
xbox.emit(btnRef + 'Down:none');
}

if(position.y === 0){
setLastMoveEvent(btnRef + 'stickUp', 0, 'y');
setLastMoveEvent(btnRef + 'Up', 0, 'y');

xbox.emit(btnRef + 'stickUp');
xbox.emit(btnRef + 'Up');
}else{
xbox.emit(btnRef + 'stickUp:none');
xbox.emit(btnRef + 'Up:none');
}
}.bind(this);

Expand All @@ -107,18 +102,17 @@ Stick.prototype._getDirectionalPosition = function (data) {
* @private
*/
Stick.prototype._getLinuxAxisPosition = function (data) {
var reduceData = 128 - (Math.floor(data.value / 256) * -1),
var reduceData = Math.round(data.value / 256),
x, y;

if (this.HIDCoordinates.axisX == data.number) {
x = reduceData;
}else if(this.HIDCoordinates.axisY == data.number){
y = reduceData;
y = reduceData !== 0 ? -1*reduceData : 0;
}

return {
x: (x || x === 0) ? x : 'none',
y: (y || y === 0) ? y : 'none'
x: (x)||x===0 ? x : undefined,
y: (y)||y===0 ? y : undefined
};
};

Expand Down
Loading