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:
John Toman
2009-09-02 22:42:11 +00:00
committed by virtuoussin13
parent 965ff791c3
commit 0b9132b0f0
5 changed files with 36 additions and 28 deletions

View File

@ -25,10 +25,5 @@
#define NAME "QJoyPad 4.0" #define NAME "QJoyPad 4.0"
#define MOUSE_OFFSET 400 #define MOUSE_OFFSET 400
#ifdef _DEBUG
#define DEBUG(str) printf(str);
#else
#define DEBUG
#endif
#endif #endif

View File

@ -2,7 +2,7 @@
#define JOY_ERROR_H #define JOY_ERROR_H
#include <qmessagebox.h> #include <qmessagebox.h>
#include <stdarg.h>
//a nice simple way of throwing up an error message if something goes wrong. //a nice simple way of throwing up an error message if something goes wrong.
static void error(QString type, QString message ) { static void error(QString type, QString message ) {
@ -10,4 +10,16 @@ static void error(QString type, QString message ) {
message, QMessageBox::Ok, Qt::NoButton); 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 #endif

View File

@ -6,24 +6,26 @@
#include <poll.h> #include <poll.h>
#include <QApplication> #include <QApplication>
JoyPad::JoyPad( int i, int dev ) { 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, //remember the index,
index = i; index = i;
//load data from the joystick device, if available. //load data from the joystick device, if available.
joydevFileHandle = NULL; joydevFileHandle = NULL;
if(dev > 0) { 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); 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. //there is no JoyPadWidget yet.
jpw = NULL; jpw = NULL;
DEBUG("Done constructing the joypad device\n"); debug_mesg("Done constructing the joypad device %d\n", i);
} }
void JoyPad::resetToDev(int dev ) { void JoyPad::resetToDev(int dev ) {
DEBUG("resetting to dev\n"); debug_mesg("resetting to dev\n");
//remember the device file descriptor //remember the device file descriptor
joydev = dev; joydev = dev;
@ -49,20 +51,20 @@ void JoyPad::resetToDev(int dev ) {
read_struct.events = POLLIN; read_struct.events = POLLIN;
char buf[10]; char buf[10];
while(poll(&read_struct, 1, 5)!=0) { while(poll(&read_struct, 1, 5)!=0) {
DEBUG("reading junk data\n"); debug_mesg("reading junk data\n");
read(joydev, buf, 10); read(joydev, buf, 10);
} }
setupJoyDeviceListener(dev); setupJoyDeviceListener(dev);
DEBUG("done resetting to dev\n"); debug_mesg("done resetting to dev\n");
} }
void JoyPad::setupJoyDeviceListener(int dev) { void JoyPad::setupJoyDeviceListener(int dev) {
DEBUG("Setting up joyDeviceListeners\n"); debug_mesg("Setting up joyDeviceListeners\n");
joydevFileHandle = new QSocketNotifier(dev, QSocketNotifier::Read, this); joydevFileHandle = new QSocketNotifier(dev, QSocketNotifier::Read, this);
connect(joydevFileHandle, SIGNAL(activated(int)), this, SLOT(handleJoyEvents(int))); connect(joydevFileHandle, SIGNAL(activated(int)), this, SLOT(handleJoyEvents(int)));
joydevFileException = new QSocketNotifier(dev, QSocketNotifier::Exception, this); joydevFileException = new QSocketNotifier(dev, QSocketNotifier::Exception, this);
connect(joydevFileException, SIGNAL(activated(int)), this, SLOT(errorRead(int))); 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() { 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 //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. //Button or Axis was pressed and let them decide what to do with it.
if (msg.type & JS_EVENT_AXIS) { if (msg.type & JS_EVENT_AXIS) {
//printf("DEBUG: passing on an axis event\n"); debug_mesg("DEBUG: passing on an axis event\n");
//printf("DEBUG: %d %d\n", msg.number, msg.value); debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
Axes[msg.number]->jsevent(msg.value); Axes[msg.number]->jsevent(msg.value);
} }
else { else {
//printf("DEBUG: passing on a button event\n"); debug_mesg("DEBUG: passing on a button event\n");
//printf("DEBUG: %d %d\n", msg.number, msg.value); debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
Buttons[msg.number]->jsevent(msg.value); Buttons[msg.number]->jsevent(msg.value);
} }
} }
@ -273,7 +275,7 @@ void JoyPad::unsetDev() {
} }
void JoyPad::errorRead(int fd) { 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->blockSignals(true);
joydevFileHandle->setEnabled(false); joydevFileHandle->setEnabled(false);
close(joydev); close(joydev);
@ -287,5 +289,5 @@ void JoyPad::errorRead(int fd) {
joydevFileException = NULL; joydevFileException = NULL;
} }
joydev = -1; joydev = -1;
DEBUG("Done disabling\n"); debug_mesg("Done disabling device with fd %d\n", fd);
} }

View File

@ -316,7 +316,7 @@ void LayoutManager::fillPopup() {
} }
void LayoutManager::updateJoyDevs() { void LayoutManager::updateJoyDevs() {
DEBUG("updating joydevs\n"); debug_mesg("updating joydevs\n");
QString devdir = DEVDIR; QString devdir = DEVDIR;
//reset all joydevs to sentinal value (-1) //reset all joydevs to sentinal value (-1)
@ -355,13 +355,14 @@ void LayoutManager::updateJoyDevs() {
read_struct.events = POLLIN; read_struct.events = POLLIN;
char buf[10]; char buf[10];
while(poll(&read_struct, 1, 5)!=0) { while(poll(&read_struct, 1, 5)!=0) {
DEBUG("reading junk data\n"); debug_mesg("reading junk data\n");
read(joydev, buf, 10); read(joydev, buf, 10);
} }
joypad = new JoyPad( index, joydev ); joypad = new JoyPad( index, joydev );
joypads.insert(index,joypad); joypads.insert(index,joypad);
} }
else { else {
debug_mesg("found previously open joypad with index %d, ignoring", index);
joypad = joypads[index]; joypad = joypads[index];
joypad->resetToDev(joydev); joypad->resetToDev(joydev);
} }
@ -376,12 +377,10 @@ void LayoutManager::updateJoyDevs() {
//when it's all done, rebuild the popup menu so it displays the correct //when it's all done, rebuild the popup menu so it displays the correct
//information. //information.
fillPopup(); fillPopup();
//the actual update process is handled by main.cpp, we just need to signal
//ourselves to do it.
if(le) { if(le) {
le->updateJoypadWidgets(); le->updateJoypadWidgets();
} }
DEBUG("done updating joydevs\n"); debug_mesg("done updating joydevs\n");
} }
void LayoutManager::leWindowClosed() { void LayoutManager::leWindowClosed() {

View File

@ -163,11 +163,11 @@ void LayoutEdit::windowActivationChange( bool oldActive ) {
QHashIterator<int, JoyPad*> it( available ); QHashIterator<int, JoyPad*> it( available );
while (it.hasNext()) while (it.hasNext())
{ {
DEBUG("iterating and releasing\n"); debug_mesg("iterating and releasing\n");
it.next(); it.next();
it.value()->release(); it.value()->release();
} }
DEBUG("done releasing!\n"); debug_mesg("done releasing!\n");
} }
void LayoutEdit::closeEvent(QCloseEvent *event) { void LayoutEdit::closeEvent(QCloseEvent *event) {
lm->leWindowClosed(); lm->leWindowClosed();