threaded linux driver
This commit is contained in:
@@ -32,6 +32,7 @@ InputHandler_Linux_Joystick::InputHandler_Linux_Joystick()
|
||||
* the same device; keep track of device IDs so we don't open the same joystick
|
||||
* twice. */
|
||||
set< pair<int,int> > devices;
|
||||
bool bFoundAnyJoysticks = false;
|
||||
|
||||
for(int i = 0; i < NUM_JOYSTICKS; ++i)
|
||||
{
|
||||
@@ -66,19 +67,42 @@ InputHandler_Linux_Joystick::InputHandler_Linux_Joystick()
|
||||
m_sDescription[i] = szName;
|
||||
|
||||
LOG->Info("Opened %s", Paths[i]);
|
||||
bFoundAnyJoysticks = true;
|
||||
}
|
||||
}
|
||||
|
||||
m_bShutdown = false;
|
||||
|
||||
if( bFoundAnyJoysticks )
|
||||
{
|
||||
m_InputThread.SetName( "Joystick thread" );
|
||||
m_InputThread.Create( InputThread_Start, this );
|
||||
}
|
||||
}
|
||||
|
||||
InputHandler_Linux_Joystick::~InputHandler_Linux_Joystick()
|
||||
{
|
||||
if( m_InputThread.IsCreated() )
|
||||
{
|
||||
m_bShutdown = true;
|
||||
LOG->Trace( "Shutting down joystick thread ..." );
|
||||
m_InputThread.Wait();
|
||||
LOG->Trace( "Joystick thread shut down." );
|
||||
}
|
||||
|
||||
for(int i = 0; i < NUM_JOYSTICKS; ++i)
|
||||
if(fds[i] != -1) close(fds[i]);
|
||||
}
|
||||
|
||||
void InputHandler_Linux_Joystick::Update(float fDeltaTime)
|
||||
int InputHandler_Linux_Joystick::InputThread_Start( void *p )
|
||||
{
|
||||
while(1)
|
||||
((InputHandler_Linux_Joystick *) p)->InputThread();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InputHandler_Linux_Joystick::InputThread()
|
||||
{
|
||||
while( !m_bShutdown )
|
||||
{
|
||||
fd_set fdset;
|
||||
FD_ZERO(&fdset);
|
||||
@@ -96,10 +120,12 @@ void InputHandler_Linux_Joystick::Update(float fDeltaTime)
|
||||
if(max_fd == -1)
|
||||
break;
|
||||
|
||||
struct timeval zero = {0,0};
|
||||
if ( select(max_fd+1, &fdset, NULL, NULL, &zero) <= 0 )
|
||||
break;
|
||||
struct timeval zero = {0,100000};
|
||||
if( select(max_fd+1, &fdset, NULL, NULL, &zero) <= 0 )
|
||||
continue;
|
||||
RageTimer now;
|
||||
|
||||
printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
|
||||
for(int i = 0; i < NUM_JOYSTICKS; ++i)
|
||||
{
|
||||
if( fds[i] == -1 )
|
||||
@@ -127,15 +153,15 @@ void InputHandler_Linux_Joystick::Update(float fDeltaTime)
|
||||
// In 2.6.11 using an EMS USB2, the event number for P1 Tri (the first button)
|
||||
// is being reported as 32 instead of 0. Correct for this.
|
||||
wrap( iNum, 32 ); // max number of joystick buttons. Make this a constant?
|
||||
ButtonPressed(DeviceInput(id, JOY_BUTTON_1 + iNum), event.value);
|
||||
ButtonPressed( DeviceInput(id, JOY_BUTTON_1 + iNum, 0, now), event.value );
|
||||
break;
|
||||
}
|
||||
|
||||
case JS_EVENT_AXIS: {
|
||||
JoystickButton neg = (JoystickButton)(JOY_LEFT+2*event.number);
|
||||
JoystickButton pos = (JoystickButton)(JOY_RIGHT+2*event.number);
|
||||
ButtonPressed(DeviceInput(id, neg), event.value < -16000);
|
||||
ButtonPressed(DeviceInput(id, pos), event.value > +16000);
|
||||
ButtonPressed(DeviceInput(id, neg, 0, now), event.value < -16000);
|
||||
ButtonPressed(DeviceInput(id, pos, 0, now), event.value > +16000);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user