PlayStation Controller Integration

03 Mar 2012

Hey guys, I'm looking at the code here: http://mbed.org/users/simon/programs/PlayStationController/16mhs4 and I'm trying to understand this line:

00048         printf("Digital %02X %02X   Analog %02X %02X %02X %02X\n", response[3], response[4], 
                      response[5], response[6], response[7], response[8]);

I'm thinking there are 16 buttons on the controller with 2 analog sticks, so I should be receiving 16 button states and 4 stick values (left & right stick in x & y direction). How can I interpret the above 6 variables to represent this? Thanks!

03 Mar 2012

Hello,

as I understand this is similiar to USB Gamepad report. In the code above is first printed state of digital buttons and then for sticks values.

This means that response[3] and response[4] includes state of all buttons - each bit in both bytes represents state of one button. So 8 bits in response[3] and 8 bits in response[4] represents state of all buttons.

Using for example if(response[3] &0x1){ do something} to check and base any action for specified button press.

You will use 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 to check each specified bit for status 0 or 1. 0x1 checks 8th bit (most right), 0x80 checks first bit(most left one)

response[5], response[6], response[7] and response[8] store status of all sticks axes in 0 - 255 or 0x00 - 0xFF hex with 127 or 0x80 hex for center. May they are ordered as x, y, z, rz.

03 Mar 2012

Thank you so much for the clarification! The only part I don't comprehend is what is z, rz? I figured it would be Left X, Left Y, Right X, Right Y. Thanks again.

03 Mar 2012

BTW maybe last four bits in response[4] are reserved for Dpad as for USB gamepads. If You connect gamepad and read data outputed to terminal until moving analog stick and will see something like this 00 0F 80 80 80 FF (in hex)

it means that last four bits in response[4] are reserved for Dpad (F in second value menas DPAD not pressed in center position) the zero before F means no of four buttons stored in same byte as DPD is not pressed. First two zeros means no button stored in response[3] is pressed.

Four times 80 means analog sticks in center - I used FF as last value instead of 80 to understand that FF (255 dec) means right stick is moved down. Depends if data in array is ordered x, y, z, rz.

Hope this will help You and please excuse my english. Not my origin language.

03 Mar 2012

Z is same as X and RZ is same as Y but used to name axes on right stick until X and Y is used to name axes on left stick.

03 Mar 2012

That's exactly what I needed, thank you so much!

23 Mar 2012

I'm trying to also interface the mbed with the ps2. How is your project going? Do let me know if it was successful as there aren't many encouraging threads that shown success with it.

23 Mar 2012

Hey Joey, currently I haven't gotten a full working demo. My project is getting 5+ controllers to work on an Xbox 360. I have Keyboard/Mouse and Wiimote already working, but now I'm working on N64, PS2, and an IR remote. So although I altered the example code, I have not confirmed it working. Sorry I can't be of much help at the time.