diff --git a/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp b/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp index 82760260e4..7899df267c 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp @@ -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 > 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; } diff --git a/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.h b/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.h index 3d19c153e2..74d75a3fc5 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.h +++ b/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.h @@ -2,20 +2,25 @@ #define INPUT_HANDLER_LINUX_JOYSTICK_H 1 #include "InputHandler.h" +#include "RageThreads.h" class InputHandler_Linux_Joystick: public InputHandler { public: enum { NUM_JOYSTICKS = 4 }; - void Update(float fDeltaTime); InputHandler_Linux_Joystick(); ~InputHandler_Linux_Joystick(); void GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut); private: + static int InputThread_Start( void *p ); + void InputThread(); + int fds[NUM_JOYSTICKS]; CString m_sDescription[NUM_JOYSTICKS]; + RageThread m_InputThread; + bool m_bShutdown; }; #define USE_INPUT_HANDLER_LINUX_JOYSTICK