Commit 21e4b332 authored by Phillip Castaneda's avatar Phillip Castaneda
Browse files

Adding joy patch - perform more reads per capture

parent d9b8990a
...@@ -31,7 +31,7 @@ restrictions: ...@@ -31,7 +31,7 @@ restrictions:
#include "OISPrereqs.h" #include "OISPrereqs.h"
//! Max number of elements to collect from buffered input //! Max number of elements to collect from buffered input
#define JOY_BUFFERSIZE 10 #define JOY_BUFFERSIZE 64
namespace OIS namespace OIS
{ {
......
...@@ -95,106 +95,109 @@ void LinuxJoyStick::capture() ...@@ -95,106 +95,109 @@ void LinuxJoyStick::capture()
//We are in non blocking mode - we just read once, and try to fill up buffer //We are in non blocking mode - we just read once, and try to fill up buffer
input_event js[JOY_BUFFERSIZE]; input_event js[JOY_BUFFERSIZE];
int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE); while(true)
if( ret <= 0 )
return;
//Determine how many whole events re read up
ret /= sizeof(struct input_event);
for(int i = 0; i < ret; ++i)
{ {
switch(js[i].type) int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE);
{ if( ret < 0 )
case EV_KEY: //Button
{
int button = mButtonMap[js[i].code];
#ifdef OIS_LINUX_JOY_DEBUG
cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl;
#endif
//Check to see whether push or released event...
if(js[i].value)
{
mState.mButtons[button] = true;
if( mBuffered && mListener )
if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return;
}
else
{
mState.mButtons[button] = false;
if( mBuffered && mListener )
if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return;
}
break; break;
}
case EV_ABS: //Absolute Axis //Determine how many whole events re read up
ret /= sizeof(struct input_event);
for(int i = 0; i < ret; ++i)
{ {
//A Stick (BrakeDefine is the highest possible Axis) switch(js[i].type)
if( js[i].code <= ABS_BRAKE )
{ {
int axis = mAxisMap[js[i].code]; case EV_KEY: //Button
assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" ); {
int button = mButtonMap[js[i].code];
axisMoved[axis] = true; #ifdef OIS_LINUX_JOY_DEBUG
cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl;
#endif
//check for rescaling: //Check to see whether push or released event...
if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS ) if(js[i].value)
{ //Scale is perfect {
mState.mAxes[axis].abs = js[i].value; mState.mButtons[button] = true;
if( mBuffered && mListener )
if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return;
} }
else else
{ //Rescale {
float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max); mState.mButtons[button] = false;
mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion)); if( mBuffered && mListener )
if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return;
} }
break;
} }
else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed
{
//Normalise the POV to between 0-7
//Even is X Axis, Odd is Y Axis
unsigned char LinuxPovNumber = js[i].code - 16;
short OIS_POVIndex = POV_MASK[LinuxPovNumber];
//Handle X Axis first (Even) (left right) case EV_ABS: //Absolute Axis
if((LinuxPovNumber & 0x0001) == 0) {
//A Stick (BrakeDefine is the highest possible Axis)
if( js[i].code <= ABS_BRAKE )
{ {
//Why do this? Because, we use a bit field, and when this axis is east, int axis = mAxisMap[js[i].code];
//it can't possibly be west too. So clear out the two X axes, then refil assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" );
//it in with the new direction bit.
//Clear the East/West Bit Flags first axisMoved[axis] = true;
mState.mPOV[OIS_POVIndex].direction &= 0x11110011;
if( js[i].value == -1 ) //Left //check for rescaling:
mState.mPOV[OIS_POVIndex].direction |= Pov::West; if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS )
else if( js[i].value == 1 ) //Right { //Scale is perfect
mState.mPOV[OIS_POVIndex].direction |= Pov::East; mState.mAxes[axis].abs = js[i].value;
}
else
{ //Rescale
float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max);
mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion));
}
} }
//Handle Y Axis (Odd) (up down) else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed
else
{ {
//Clear the North/South Bit Flags first //Normalise the POV to between 0-7
mState.mPOV[OIS_POVIndex].direction &= 0x11111100; //Even is X Axis, Odd is Y Axis
if( js[i].value == -1 ) //Up unsigned char LinuxPovNumber = js[i].code - 16;
mState.mPOV[OIS_POVIndex].direction |= Pov::North; short OIS_POVIndex = POV_MASK[LinuxPovNumber];
else if( js[i].value == 1 ) //Down
mState.mPOV[OIS_POVIndex].direction |= Pov::South; //Handle X Axis first (Even) (left right)
if((LinuxPovNumber & 0x0001) == 0)
{
//Why do this? Because, we use a bit field, and when this axis is east,
//it can't possibly be west too. So clear out the two X axes, then refil
//it in with the new direction bit.
//Clear the East/West Bit Flags first
mState.mPOV[OIS_POVIndex].direction &= 0x11110011;
if( js[i].value == -1 ) //Left
mState.mPOV[OIS_POVIndex].direction |= Pov::West;
else if( js[i].value == 1 ) //Right
mState.mPOV[OIS_POVIndex].direction |= Pov::East;
}
//Handle Y Axis (Odd) (up down)
else
{
//Clear the North/South Bit Flags first
mState.mPOV[OIS_POVIndex].direction &= 0x11111100;
if( js[i].value == -1 ) //Up
mState.mPOV[OIS_POVIndex].direction |= Pov::North;
else if( js[i].value == 1 ) //Down
mState.mPOV[OIS_POVIndex].direction |= Pov::South;
}
if( mBuffered && mListener )
if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false )
return;
} }
break;
if( mBuffered && mListener )
if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false )
return;
} }
break;
}
case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?) case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?)
#ifdef OIS_LINUX_JOY_DEBUG #ifdef OIS_LINUX_JOY_DEBUG
cout << "\nWarning: Relatives axes not supported yet" << endl; cout << "\nWarning: Relatives axes not supported yet" << endl;
#endif #endif
break; break;
default: break; default: break;
}
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment