|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionA lot can be found for interfacing a Wii-mote, but almost nothing could be found for accessing the new PS3 controller. This is not yet a complete highly re-usable library. Instead it looks more like a hack. But it does provide the eager programmer a way to communicate with a PS3 controller. The biggest trick is the mapping of the received data-block to a nice and easy struct. I made a variable for all buttons, so even the combined bits in a BYTE are mapped to a 'bool'. The PS3 controller does get recognized by Windows, but before the controller reacts on our request, the following driver should be installed. (Tested under Windows XP and Windows Vista). BackgroundSome info I found was using delphi SixAxis on Windows. Some info I found was mad for accessing a USB temperature device from Cyprus Using the HID class eases the job of writing USB device drivers. For a big explanation on the USB-HID calls, look at the last link. Using the CodeWhen the application is started it will register for device-connection events. When a PS3 controller is connected the ' For demo purposes I also made a ' One nice thing about typedef struct tagPS3_data
{
BYTE ReportID;
union {
struct{
BYTE LAnalogX;
BYTE LAnalogY;
BYTE dummy[46];
bool Triangle:1;
bool Circle:1;
bool Cross:1;
bool Cube:1;
bool L2:1;
bool R2:1;
bool L1:1;
bool R1:1;
};
BYTE data[49];
};
} PS3_data;
Three of the features used are
A second feature is the abilty to use the struct in a union. So you can map two structs to the same location, without the need to give this struct a name.
Why did I use this? Because now it is possible to fill the complete structure using a Another interesting code snippet is the use of Every call to iPos += sprintf(&buffer[iPos],"test %d\r\n", 0 );
The This as results in the following void PS3_data::Format ( char* buffer )
{
int iPos = 0;
iPos += sprintf(&buffer[iPos],"LeftJoy:%d-%d RightPad:%d %d %d %d\r\n",
LAnalogX,LAnalogY,Triangle,Circle,Cross,Cube);
int id=0;
int idMax=45;
for ( ; id<=idMax;id++) iPos += sprintf(&buffer[iPos],"%02d:%d\r\n", id,
data[id]);
}
Points of InterestWhen looking at the code, you will not think of me as a rocket scientist. But I hope you will see a way to include this in your own test applications. My goal is to add some sort of filter driver, which makes the device identify itself as a DirectX controller. Which it already does, but the motion sensors are not coupled to DirectInput values. It actually is not a SIX axis, but more like a NINETHEEN axis, since all joypad/firebuttons are all pressure sensitive buttons, so all are actually floating values of 0-255. History11 feb. 2008 - Initial version. 14 feb. 2008 - Added some code explanation. Added link to SixAxisDriver.exe
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||