Attached is the modified PlayStation 2 object and demo.
Here's the output from the demo with the analog buttons turned on and with the square, circle and right arrow buttons pressed.
Code:
Press "d" to enter digital mode.
Digital mode will turn off the analog buttons.
Press "a" to enter analog mode.
Press "b" to change to analog button mode.
If not all ready in analog mode this option will change
the controller to analog mode.
Mode: Analog Joysticks and analog buttons in use.
Left Right
x:108 y:138 x:133 y:131
Buttons: Sq X O Tri R1 L1 R2 L2
Digital: 1 0 1 0 0 0 0 0
Analog: 126 0 66 0 0 0 0 0
Buttons: < v > ^ St JR JL Sel
Digital: 0 0 1 0 0 0 0 0
Analog: 0 0 57 0
Raw: $5FDF5A79,$8A6C8385,$00000038,$7E004200,$00000000
All Buttons: 01111111011111
Last debug message: Turned on analog buttons.
Last action:
programName = dwdPs2Demo120424g
There aren't any methods to convert the raw data to joystick values. These conversions are done in PASM with the results written to hub RAM.
The parent object needs seven longs and 34 bytes to hold the controller information.
Code:
VAR
' Keep below in order and together.
long psData[5], allDigitalButtons, debugLong
' Keep above in order and together.
' Keep below in order and together.
byte rightX, rightY, leftX, leftY
byte digitalButton[Ps2#_NumberOfControllerButtons]
byte analogButton[Ps2#_NumberOfAnalogButtons], mode, dataSize
' Keep above in order and together.
Once the PS2 object has been started, it doesn't need to be called again except to change modes. The controller is continuously polled with the new data continuously written to hub RAM.
The demo will start out in digital mode (boring); you'll need to press "b" on the keyboard to turn on the analog buttons.
I tried to add comments to explain how to use the object. One thing to keep in mind is that there are three different sets of button data being written to the hub.
Here's a quote from the comments.
Code:
The bits representing the button states are ordered
differently than the bytes measuring the pressure of
the analog buttons. The program uses the same button
order for both the digital buttons and the analog
readings from those buttons.
This reordering of the pressure data should make it
easier to use with the digital button data.
The button states are reported three different ways.
The state of all 16 buttons are written to a long with
each button being represented by one bit. A low value
in the button's bit position indicates a button press.
The second set of button data is an array of 16 bytes.
The normal state of these bytes is zero. A button
press with cause a one to be written to the corresponding
byte.
The third set of button data is held in a 12 byte array.
The bytes in this array contain the pressure reading
for each button. These reading vary from zero (for
no pressure) to 255 (full pressure).
I personally think it's pretty cool these buttons will output analog values and I look forward to using these buttons to control aspects of a robot.
Hopefully some of you will find it useful.
Let me know if any of you have questions or suggestions for improvement.
I do play to add control to the Dual Shock motors. I will also likely add a way of locking the controller in the various modes.
Bookmarks