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

@ -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);
}