Adds support for the Sony Playstation PS2 controllers.
Thanks to 'Dunk' for his contributions, testing and patience. Other thanks to Bill Porter.
These controllers come with a 9 pin plug - which you will need to cut off and replace with your own header pin sockets. Alternatively you can find adaptors to plug into the joystick.
You will need to provide connections for 'ground' and 'power' - to power the device. The jury is out as to whether it should be 3.3V or 5V.
The other connections are the common SPI bus lines: MISO, MOSI and SCK and the Select wire needs to be connected to a digital I/O used to select the device.
The grey wire is optional depending on whether you want to use the rumble motors. If you want to use them then connect it to an unregulated supply voltage between 7.2v and 9v.
You can of course add as many controllers as you like - each controller requires its own unique Select pin but otherwise the connections are the same for every controller.
When sharing the hardware SPI bus with an ISP programmer it is recommended that you add a pull up resistor on the Select line of the controller so that it doesn't interfere with the programmer when programming. Alternatively: only have either the controller or the programmer plugged in at any one time. If you are programming via a bootloader then this doesn't apply.
NB The controller is slightly flakey - so, for now, only use a software SPI bus as the hardware bus seems to work too fast for the controller.
In Project Designer you must must add the controller to an existing SPI Bus
If you wish to use the joysticks then you must place the controller into analog mode. This gives access to both the left and right joysticks as well as virtual joysticks using the D-pad buttons on the left and the shape buttons on the right.
Each joystick has two values: X and Y.
Here is an example for the Axon and Axon II assuming you have called it 'controller' in Project Designer:-
//In appInitSoftware we will calibrate the controller
In our main loop we read the controller:-
// We can now test the buttons
// and the joysticks
- buttonDown - Return TRUE if the button has just been pressed or FALSE if it was already pressed or is not pressed at all.
- buttonHeld - Return TRUE if the button continues to be held down.
- buttonPressed - Return TRUE if the button is currently pressed.
- buttonPressure - Return a value representing how hard a button has been pressed.
- buttonsChanged - Returns information on which buttons have changed state since the previous call to read the controller.
- buttonsRaw - Return the status of all 16 buttons.
- buttonUp - Return TRUE if the button has just been released or FALSE if it was already released or is still held down.
- calibrate - Calibrate the joysticks on the controller.
- isAnalogMode - Returns TRUE if the controller is already in analogue mode.
- joystick - Read a joystick value relative to its centre point including any dead zone.
- joystickRaw - Reads the raw value from a joystick.
- read - Read the values from the controller and store them.
- setAnalogMode - Activates the joysticks.
- setRumble - Turn each of the rumble motors on or off.