From 30ed817389cf2705314b27b2ad9118c80387056a Mon Sep 17 00:00:00 2001 From: John Toman Date: Sat, 15 Aug 2009 19:36:28 +0000 Subject: [PATCH] adds a new compile time option for debugging output, brings the timeout for reading junk data back into line between joypad.cpp and layout.cpp, and adds in read exception handling when setupjoydevs is called (previously only set up in the joypad constructor) git-svn-id: svn://svn.code.sf.net/p/qjoypad/code/trunk@101 c05e91a0-76c8-4ec0-b377-ef19ce7cc080 --- src/constant.h | 5 +++++ src/joypad.cpp | 10 +++++++++- src/layout.cpp | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/constant.h b/src/constant.h index fd05ec9..e33c763 100644 --- a/src/constant.h +++ b/src/constant.h @@ -25,5 +25,10 @@ #define NAME "QJoyPad 4.0-pre" #define MOUSE_OFFSET 400 +#ifdef _DEBUG +#define DEBUG(str) printf(str); +#else +#define DEBUG +#endif #endif diff --git a/src/joypad.cpp b/src/joypad.cpp index 47ec700..ccda929 100644 --- a/src/joypad.cpp +++ b/src/joypad.cpp @@ -22,6 +22,7 @@ JoyPad::JoyPad( int i, int dev ) { } void JoyPad::resetToDev(int dev ) { + DEBUG("resetting to dev\n"); //remember the device file descriptor joydev = dev; @@ -47,19 +48,24 @@ void JoyPad::resetToDev(int dev ) { read_struct.fd = joydev; read_struct.events = POLLIN; char buf[10]; - while(poll(&read_struct, 1, 2)!=0) { + while(poll(&read_struct, 1, 5)!=0) { printf("reading junk data\n"); read(joydev, buf, 10); } setupJoyDeviceListener(dev); + DEBUG("done resetting to dev\n"); } void JoyPad::setupJoyDeviceListener(int dev) { + DEBUG("Setting up joyDeviceListener\n"); if(joydevFileHandle != NULL) { delete joydevFileHandle; } joydevFileHandle = new QSocketNotifier(dev, QSocketNotifier::Read, this); connect(joydevFileHandle, SIGNAL(activated(int)), this, SLOT(handleJoyEvents(int))); + joydevFileException = new QSocketNotifier(dev, QSocketNotifier::Exception, this); + connect(joydevFileException, SIGNAL(activated(int)), this, SLOT(errorRead(int))) + DEBUG("Done setting up joyDeviceListener\n"); } void JoyPad::toDefault() { @@ -270,6 +276,7 @@ void JoyPad::unsetDev() { } void JoyPad::errorRead(int fd) { + DEBUG("There was an error reading off of the device, disabling\n"); joydevFileHandle->blockSignals(true); joydevFileHandle->setEnabled(false); close(joydev); @@ -283,4 +290,5 @@ void JoyPad::errorRead(int fd) { joydevFileException = NULL; } joydev = -1; + DEBUG("Done disabling\n"); } diff --git a/src/layout.cpp b/src/layout.cpp index d7809b8..6451a7f 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -314,7 +314,9 @@ void LayoutManager::fillPopup() { } void LayoutManager::updateJoyDevs() { + DEBUG("updating joydevs\n"); QString devdir = DEVDIR; + //reset all joydevs to sentinal value (-1) do { QHashIterator it( joypads ); @@ -375,4 +377,5 @@ void LayoutManager::updateJoyDevs() { //the actual update process is handled by main.cpp, we just need to signal //ourselves to do it. //raise(SIGUSR1); + DEBUG("done updating joydevs\n"); }