Closed bolbola closed 10 years ago
It sounds like it's more likely to be the third party controller having a slightly different mapping.
The mapping is done here: https://github.com/andrew/node-xbox-controller/blob/master/lib/xbox.js#L8 for the buttons, triggers and sticks, where there is a bitwise position and block from the binary value emitted over the serial port, so you might need to put some extra logging in to see which values you need to tweak to get it to work.
How do you determine the bitwise for the sticks? Moving the right stick on the y axis causes a range from 00-ff on the 7'th block with the stick sitting stationary being 7f and causes the 6th block to turn to 0 when it hits the highest y axis point. Which value would I use there?
The sticks are a bit different to most of the other values, as they provide 16 bit signed values (little endian), so you have to convert the unsigned 8 bit values of the block, as I do here: https://github.com/andrew/node-xbox-controller/blob/master/lib/xbox.js#L165
I seem to have everything working properly now, except the d-pad which is a bit buggy, but I don't care too much about the d-pad. Thanks for the help!
For reference to anyone with a "HoriUnnamedBlueSolo" controller with vendor id:7085 Product id:64001
var buttons = {
'dup': {
'block':11,
'bitwise':0x04
},
'ddown':{
'block':11,
'bitwise':0x14
},
'dleft':{
'block':11,
'bitwise':0x12
},
'dright':{
'block':11,
'bitwise':0x28
},
'start':{
'block': 10,
'bitwise':0x80
},
'back':{
'block': 10,
'bitwise':0x40
},
'leftstick':{
'block':11,
'bitwise': 0x2
},
'rightstick':{
'block':11,
'bitwise':0x1
},
'leftshoulder':{
'block':10,
'bitwise':0x10
},
'rightshoulder':{
'block':10,
'bitwise':0x20
},
'xboxbutton':{
},
'a':{
'block': 10,
'bitwise': 0x1
},
'b':{
'block': 10,
'bitwise': 0x2
},
'x':{
'block': 10,
'bitwise': 0x4
},
'y':{
'block': 10,
'bitwise': 0x8
}
};
var triggers = {
'left':{
'block': 9
},
'right':{
'block': 9
}
};
var leftx = uint8Toint16(data[0], data[1]);
var lefty = uint8Toint16(data[2], data[3]);
var rightx = uint8Toint16(data[4], data[5]);
var righty = uint8Toint16(data[6], data[7]);
Awesome, glad you sorted that out, maybe there is a way we can make it so you can pass in a custom mapping function to the constructor object.
I'm working on making one, so far I have managed to get the buttons and triggers mapping.
I'm having a very similar issue to this. I'm getting really strange results using just the example in the README.
@bolbola What exactly do you mean by "aftermarket" and any progress on supporting custom mappings/profiles?
@andrew Exactly what type of controller are you using as I'm currently using the Xbox 360 Controller for Windows.
I use a wired official xbox 360 controller on a mac, although my :rabbit: chewed the cable recently so I can't test much at the moment.
I recently managed to compile node-hid on windows since it could not detect my controller on ubuntu and so I tried out some test code with xbox-controller and am getting strange results. For example moving the right trigger down gives me left:move in the y-axis from 32k to 0 and right trigger from -32k to 0, the left joystick only works in the right direction, but that only triggers a:press and b:release. Could this be a result of the operating system or because the controller is aftermarket? How could I attempt to reassign the button actions?