adds a better debug output function should clean up a lot of 'statement has no effect' warnings
git-svn-id: svn://svn.code.sf.net/p/qjoypad/code/trunk@114 c05e91a0-76c8-4ec0-b377-ef19ce7cc080
This commit is contained in:
		
				
					committed by
					
						
						virtuoussin13
					
				
			
			
				
	
			
			
			
						parent
						
							965ff791c3
						
					
				
				
					commit
					0b9132b0f0
				
			@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								src/error.h
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/error.h
									
									
									
									
									
								
							@@ -2,7 +2,7 @@
 | 
			
		||||
#define JOY_ERROR_H
 | 
			
		||||
 | 
			
		||||
#include <qmessagebox.h>
 | 
			
		||||
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
//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
 | 
			
		||||
 
 | 
			
		||||
@@ -6,24 +6,26 @@
 | 
			
		||||
#include <poll.h>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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() {
 | 
			
		||||
 
 | 
			
		||||
@@ -163,11 +163,11 @@ void LayoutEdit::windowActivationChange( bool oldActive ) {
 | 
			
		||||
    QHashIterator<int, JoyPad*> 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();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user