Mouse to joystick translation – Call Of Duty Modern Warfare 2

COD MW2 has a totally different behavior regarding the position to rotation speed relation.

Following chart gives the rotation speed (degrees per second) given the absolute position of z.
The joystick sensibility is set to the highest position.


The rotation speed is continuous and goes from low to very high values, so that the mouse to joystick translation is very easy to do: a simple x3 multiplier is sufficient.

The acceleration looks like the mouse acceleration that is performed under windows xp (described there).

Mouse to joystick translation – FARCRY2 – part 2

It was explained in part 1 that absolute positions 1 to 82 give a linear rotation speed (from 0 to about 50°/s), and position 83 a high rotation speed (450°/s for z, 200°/s for rz).

Following chart gives the rotation speed for a given virtual position of z that goes from 0 to 645. That gives a linear speed from 0 to 450°/s. Virtual positions from 83 to 644 have to be created.

Blue dots are speeds that are achieved by real positions with a standard ps3 controller.
Red line is obtained with a simple linear regression.

Each mouse packet applies a rotation speed over a time that is the inverse of the mouse frequency (for ex 100Hz => 10ms).

A rotation speed for a virtual position between 83 and 644 may be generated “in average”.

For example, if a speed of 450°/s is applied (virtual position 645=real position 83) over 5ms, and 0°/s is applied (real position 0) over 5ms, the average speed that is obtained over 10ms is 225°/s (virtual position 321).

0+83 makes crappy movements, that technique actually works great with 82+83

I realized afterward that it is similar to PWM.

Mouse to joystick translation – FARCRY2 – part 1

(x,y) speed of the mouse has to be mapped to a (z,rz) rotation speed.

z and rz are in the range [0..255] with [83..173] as dead zone (128 is the center).

Following chart gives the rotation speed (degrees per second) given the absolute position of z.

This probably may change with the game (values are for Farcry).


This is quite linear except for the max position (83). The max speed that is in the linear area (position 82, about 50°/s) is not fast enough to only use the linear area. The speed of the max position is so fast (about 450°/s) that it shouldn’t be used over a long time.

There is the same behavior for rz, except that the speed of the max position is about 200°/s).

A heuristic has to be found to trigger the max position use.

The HID descriptor

The HID descriptor defines:
– 4 axis (x, y, z, rz)
– 1 hat switch
– 12 buttons

There are 13 buttons on a ps3 controller.
PS3 button is not very useful, omitting it allows avoiding padding.

/* Usage Page (Generic Desktop)*/ 0x05, 0x01,
/*Usage (Joystick)*/ 0x09, 0x04,
/*Collection (Application)*/ 0xA1, 0x01,
/*Collection (Logical)*/ 0xA1, 0x02,
/*Logical Minimum (0)*/ 0x15, 0x00,
/*Logical Maximum (255)*/ 0x26, 0xFF, 0x00,
/*Physical Minimum (0)*/ 0x35, 0x00,
/*Physical Maximum (255)*/ 0x46, 0xFF, 0x00,
/*Report Size (8)*/ 0x75, 0x08,
/*Report Count (4)*/ 0x95, 0x04,
/*Usage (X)*/ 0x09, 0x30,
/*Usage (Y)*/ 0x09, 0x31,
/*Usage (Z)*/ 0x09, 0x32,
/*Usage (Rz)*/ 0x09, 0x35,
/*Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit)*/ 0x81, 0x02,
/*Logical Maximum (7)*/ 0x25, 0x07,
/*Physical Maximum (315)*/ 0x46, 0x3B, 0x01,
/*Report Size (4)*/ 0x75, 0x04,
/*Report Count (1)*/ 0x95, 0x01,
/*Unit (Eng Rot: Degree)*/ 0x65, 0x14,
/*Usage (Hat Switch)*/ 0x09, 0x39,
/*Input (Data,Var,Abs,NWrp,Lin,Pref,Null,Bit)*/ 0x81, 0x42,
/*Unit (None)*/ 0x65, 0x00,
/*Logical Maximum (1)*/ 0x25, 0x01,
/*Physical Maximum (1)*/ 0x45, 0x01,
/*Report Size (1)*/ 0x75, 0x01,
/*Report Count (12)*/ 0x95, 0x0C,
/*Usage Page (Button)*/ 0x05, 0x09,
/*Usage Minimum (Button 1)*/ 0x19, 0x01,
/*Usage Maximum (Button 12)*/ 0x29, 0x0C,
/*Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit)*/ 0x81, 0x02,
/*End Collection*/ 0xC0,
/*End Collection*/ 0xC0

Mouse-Keyboard to PS3 Joystick adapter
Above screenshot shows the result of this hid device with jstest-gtk as joystick calibration program (axis 4-5 are not relevant).

Coming soon…

The first diy project I want to share is a mouse and keyboard to ps3 converter.

The hardware part is made of a usb development board called “Teensy++”:
Teensy++ 2.0
It is available at: http://www.pjrc.com/teensy/

The mouse and the keyboard are directly wired on pins of the Teensy++ (both are ps/2 devices).

The Teensy++ is connected to the ps3 and acts as a standard ps3 usb hid controller.

The software part is mostly code written by Rick for its XBOX360 controller:

http://richard-burke.dyndns.org/wordpress/pan-galactic-gargantuan-gargle-brain-aka-xbox-360-usb-controller/

Conception steps:
1/ I modified the usb hid keyboard example available at http://www.pjrc.com/teensy/usb_keyboard.html so as to make a usb hid joystick recognized by the ps3.
2/ I transplanted it into Rick’s code.
3/ I wrapped mouse and keyboard buttons to joystick buttons.
4/ I wrapped x and y mouse movements to joystick z and rz axis.
5/ I made some calibration tests to adapt mouse movements to thumbstick movements.

Step 5 is not yet finished, I’m working on improvements.

I will share all hardware and software details as soon as possible. As my controller is working, I currently spend a lot of my free time playing farcry with it 😉