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
|
* the same device; keep track of device IDs so we don't open the same joystick
|
||||||
* twice. */
|
* twice. */
|
||||||
set< pair<int,int> > devices;
|
set< pair<int,int> > devices;
|
||||||
|
bool bFoundAnyJoysticks = false;
|
||||||
|
|
||||||
for(int i = 0; i < NUM_JOYSTICKS; ++i)
|
for(int i = 0; i < NUM_JOYSTICKS; ++i)
|
||||||
{
|
{
|
||||||
@@ -66,19 +67,42 @@ InputHandler_Linux_Joystick::InputHandler_Linux_Joystick()
|
|||||||
m_sDescription[i] = szName;
|
m_sDescription[i] = szName;
|
||||||
|
|
||||||
LOG->Info("Opened %s", Paths[i]);
|
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()
|
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)
|
for(int i = 0; i < NUM_JOYSTICKS; ++i)
|
||||||
if(fds[i] != -1) close(fds[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_set fdset;
|
||||||
FD_ZERO(&fdset);
|
FD_ZERO(&fdset);
|
||||||
@@ -96,10 +120,12 @@ void InputHandler_Linux_Joystick::Update(float fDeltaTime)
|
|||||||
if(max_fd == -1)
|
if(max_fd == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
struct timeval zero = {0,0};
|
struct timeval zero = {0,100000};
|
||||||
if ( select(max_fd+1, &fdset, NULL, NULL, &zero) <= 0 )
|
if( select(max_fd+1, &fdset, NULL, NULL, &zero) <= 0 )
|
||||||
break;
|
continue;
|
||||||
|
RageTimer now;
|
||||||
|
|
||||||
|
printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
|
||||||
for(int i = 0; i < NUM_JOYSTICKS; ++i)
|
for(int i = 0; i < NUM_JOYSTICKS; ++i)
|
||||||
{
|
{
|
||||||
if( fds[i] == -1 )
|
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)
|
// 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.
|
// is being reported as 32 instead of 0. Correct for this.
|
||||||
wrap( iNum, 32 ); // max number of joystick buttons. Make this a constant?
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case JS_EVENT_AXIS: {
|
case JS_EVENT_AXIS: {
|
||||||
JoystickButton neg = (JoystickButton)(JOY_LEFT+2*event.number);
|
JoystickButton neg = (JoystickButton)(JOY_LEFT+2*event.number);
|
||||||
JoystickButton pos = (JoystickButton)(JOY_RIGHT+2*event.number);
|
JoystickButton pos = (JoystickButton)(JOY_RIGHT+2*event.number);
|
||||||
ButtonPressed(DeviceInput(id, neg), event.value < -16000);
|
ButtonPressed(DeviceInput(id, neg, 0, now), event.value < -16000);
|
||||||
ButtonPressed(DeviceInput(id, pos), event.value > +16000);
|
ButtonPressed(DeviceInput(id, pos, 0, now), event.value > +16000);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,20 +2,25 @@
|
|||||||
#define INPUT_HANDLER_LINUX_JOYSTICK_H 1
|
#define INPUT_HANDLER_LINUX_JOYSTICK_H 1
|
||||||
|
|
||||||
#include "InputHandler.h"
|
#include "InputHandler.h"
|
||||||
|
#include "RageThreads.h"
|
||||||
|
|
||||||
|
|
||||||
class InputHandler_Linux_Joystick: public InputHandler
|
class InputHandler_Linux_Joystick: public InputHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum { NUM_JOYSTICKS = 4 };
|
enum { NUM_JOYSTICKS = 4 };
|
||||||
void Update(float fDeltaTime);
|
|
||||||
InputHandler_Linux_Joystick();
|
InputHandler_Linux_Joystick();
|
||||||
~InputHandler_Linux_Joystick();
|
~InputHandler_Linux_Joystick();
|
||||||
void GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut);
|
void GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static int InputThread_Start( void *p );
|
||||||
|
void InputThread();
|
||||||
|
|
||||||
int fds[NUM_JOYSTICKS];
|
int fds[NUM_JOYSTICKS];
|
||||||
CString m_sDescription[NUM_JOYSTICKS];
|
CString m_sDescription[NUM_JOYSTICKS];
|
||||||
|
RageThread m_InputThread;
|
||||||
|
bool m_bShutdown;
|
||||||
};
|
};
|
||||||
#define USE_INPUT_HANDLER_LINUX_JOYSTICK
|
#define USE_INPUT_HANDLER_LINUX_JOYSTICK
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user