From a702601034b328284ab5805e551d5e018c988a18 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 5 Apr 2004 22:16:26 +0000 Subject: [PATCH] updates (we still don't use this yet) --- .../InputHandler_Linux_Joystick.cpp | 36 +++++++++++++++++-- .../InputHandler_Linux_Joystick.h | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp b/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp index 0aed445b48..754be1f3e9 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp @@ -7,13 +7,18 @@ #include #include -#include +#include +#include #include +#include + static const char *Paths[InputHandler_Linux_Joystick::NUM_JOYSTICKS] = { "/dev/js0", "/dev/js1", + "/dev/input/js0", + "/dev/input/js1", }; InputHandler_Linux_Joystick::InputHandler_Linux_Joystick() @@ -21,9 +26,33 @@ InputHandler_Linux_Joystick::InputHandler_Linux_Joystick() for(int i = 0; i < NUM_JOYSTICKS; ++i) fds[i] = -1; + /* We check both eg. /dev/js0 and /dev/input/js0. If both exist, they're probably + * the same device; keep track of device IDs so we don't open the same joystick + * twice. */ + set< pair > devices; + for(int i = 0; i < NUM_JOYSTICKS; ++i) { - fds[i] = open(Paths[i], O_RDONLY); + struct stat st; + if( stat( Paths[i], &st ) == -1 ) + { + if( errno != ENOENT ) + LOG->Warn( "Couldn't stat %s: %s", Paths[i], strerror(errno) ); + continue; + } + + if( !S_ISCHR( st.st_mode ) ) + { + LOG->Warn( "Ignoring %s: not a character device", Paths[i] ); + continue; + } + + pair dev( major(st.st_rdev), minor(st.st_rdev) ); + if( devices.find(dev) != devices.end() ) + continue; /* dupe */ + devices.insert( dev ); + + fds[i] = open( Paths[i], O_RDONLY ); if(fds[i] != -1) LOG->Info("Opened %s", Paths[i]); @@ -62,6 +91,9 @@ void InputHandler_Linux_Joystick::Update(float fDeltaTime) for(int i = 0; i < NUM_JOYSTICKS; ++i) { + if( fds[i] == -1 ) + continue; + if(!FD_ISSET(fds[i], &fdset)) continue; diff --git a/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.h b/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.h index a20ea86b01..0e57a62c50 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.h +++ b/stepmania/src/arch/InputHandler/InputHandler_Linux_Joystick.h @@ -7,7 +7,7 @@ class InputHandler_Linux_Joystick: public InputHandler { public: - enum { NUM_JOYSTICKS = 2 }; + enum { NUM_JOYSTICKS = 4 }; void Update(float fDeltaTime); InputHandler_Linux_Joystick(); ~InputHandler_Linux_Joystick();