diff --git a/src/constant.h b/src/constant.h index ac09a3a..3cea77a 100644 --- a/src/constant.h +++ b/src/constant.h @@ -25,10 +25,5 @@ #define NAME "QJoyPad 4.0" #define MOUSE_OFFSET 400 -#ifdef _DEBUG -#define DEBUG(str) printf(str); -#else -#define DEBUG -#endif #endif diff --git a/src/error.h b/src/error.h index df70408..6188815 100644 --- a/src/error.h +++ b/src/error.h @@ -2,7 +2,7 @@ #define JOY_ERROR_H #include - +#include //a nice simple way of throwing up an error message if something goes wrong. static void error(QString type, QString message ) { @@ -10,4 +10,16 @@ static void error(QString type, QString message ) { message, QMessageBox::Ok, Qt::NoButton); } +#ifdef _DEBUG +static void debug_mesg(const char *fmt, ...) { + va_list ap; + va_start(ap, NULL); + vprintf(fmt, ap); + va_end(ap); +} +#else +static void debug_mesg(...) { + return; +} +#endif #endif diff --git a/src/joypad.cpp b/src/joypad.cpp index 5232351..d44834c 100644 --- a/src/joypad.cpp +++ b/src/joypad.cpp @@ -6,24 +6,26 @@ #include #include JoyPad::JoyPad( int i, int dev ) { - DEBUG("Constructing the joypad device\n"); + debug_mesg("Constructing the joypad device with index %d and fd %d\n", i, dev); //remember the index, index = i; //load data from the joystick device, if available. joydevFileHandle = NULL; if(dev > 0) { - DEBUG("Valid file handle, setting up handlers and reading axis configs...\n"); + debug_mesg("Valid file handle, setting up handlers and reading axis configs...\n"); resetToDev(dev); - DEBUG("done resetting and setting up\n"); + debug_mesg("done resetting and setting up device index %d\n", i); + } else { + debug_mesg("This joypad does not have a valid file handle, not setting up event listeners\n"); } //there is no JoyPadWidget yet. jpw = NULL; - DEBUG("Done constructing the joypad device\n"); + debug_mesg("Done constructing the joypad device %d\n", i); } void JoyPad::resetToDev(int dev ) { - DEBUG("resetting to dev\n"); + debug_mesg("resetting to dev\n"); //remember the device file descriptor joydev = dev; @@ -49,20 +51,20 @@ void JoyPad::resetToDev(int dev ) { read_struct.events = POLLIN; char buf[10]; while(poll(&read_struct, 1, 5)!=0) { - DEBUG("reading junk data\n"); + debug_mesg("reading junk data\n"); read(joydev, buf, 10); } setupJoyDeviceListener(dev); - DEBUG("done resetting to dev\n"); + debug_mesg("done resetting to dev\n"); } void JoyPad::setupJoyDeviceListener(int dev) { - DEBUG("Setting up joyDeviceListeners\n"); + debug_mesg("Setting up joyDeviceListeners\n"); 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 joyDeviceListeners\n"); + debug_mesg("Done setting up joyDeviceListeners\n"); } void JoyPad::toDefault() { @@ -226,13 +228,13 @@ void JoyPad::jsevent( js_event msg ) { //otherwise, lets create us a fake event! Pass on the event to whichever //Button or Axis was pressed and let them decide what to do with it. if (msg.type & JS_EVENT_AXIS) { - //printf("DEBUG: passing on an axis event\n"); - //printf("DEBUG: %d %d\n", msg.number, msg.value); + debug_mesg("DEBUG: passing on an axis event\n"); + debug_mesg("DEBUG: %d %d\n", msg.number, msg.value); Axes[msg.number]->jsevent(msg.value); } else { - //printf("DEBUG: passing on a button event\n"); - //printf("DEBUG: %d %d\n", msg.number, msg.value); + debug_mesg("DEBUG: passing on a button event\n"); + debug_mesg("DEBUG: %d %d\n", msg.number, msg.value); Buttons[msg.number]->jsevent(msg.value); } } @@ -273,7 +275,7 @@ void JoyPad::unsetDev() { } void JoyPad::errorRead(int fd) { - DEBUG("There was an error reading off of the device, disabling\n"); + debug_mesg("There was an error reading off of the device with fd %d, disabling\n", fd); joydevFileHandle->blockSignals(true); joydevFileHandle->setEnabled(false); close(joydev); @@ -287,5 +289,5 @@ void JoyPad::errorRead(int fd) { joydevFileException = NULL; } joydev = -1; - DEBUG("Done disabling\n"); + debug_mesg("Done disabling device with fd %d\n", fd); } diff --git a/src/layout.cpp b/src/layout.cpp index 7bc26c8..c74628b 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -316,7 +316,7 @@ void LayoutManager::fillPopup() { } void LayoutManager::updateJoyDevs() { - DEBUG("updating joydevs\n"); + debug_mesg("updating joydevs\n"); QString devdir = DEVDIR; //reset all joydevs to sentinal value (-1) @@ -355,13 +355,14 @@ void LayoutManager::updateJoyDevs() { read_struct.events = POLLIN; char buf[10]; while(poll(&read_struct, 1, 5)!=0) { - DEBUG("reading junk data\n"); + debug_mesg("reading junk data\n"); read(joydev, buf, 10); } joypad = new JoyPad( index, joydev ); joypads.insert(index,joypad); } else { + debug_mesg("found previously open joypad with index %d, ignoring", index); joypad = joypads[index]; joypad->resetToDev(joydev); } @@ -376,12 +377,10 @@ void LayoutManager::updateJoyDevs() { //when it's all done, rebuild the popup menu so it displays the correct //information. fillPopup(); - //the actual update process is handled by main.cpp, we just need to signal - //ourselves to do it. if(le) { le->updateJoypadWidgets(); } - DEBUG("done updating joydevs\n"); + debug_mesg("done updating joydevs\n"); } void LayoutManager::leWindowClosed() { diff --git a/src/layout_edit.cpp b/src/layout_edit.cpp index 6024321..0c22387 100644 --- a/src/layout_edit.cpp +++ b/src/layout_edit.cpp @@ -163,11 +163,11 @@ void LayoutEdit::windowActivationChange( bool oldActive ) { QHashIterator it( available ); while (it.hasNext()) { - DEBUG("iterating and releasing\n"); + debug_mesg("iterating and releasing\n"); it.next(); it.value()->release(); } - DEBUG("done releasing!\n"); + debug_mesg("done releasing!\n"); } void LayoutEdit::closeEvent(QCloseEvent *event) { lm->leWindowClosed();