joystick name++

This commit is contained in:
Mathias Panzenböck
2014-02-16 06:55:19 +01:00
parent 961a1d8d50
commit 7d2da6204d
2 changed files with 12 additions and 11 deletions

View File

@ -19,14 +19,6 @@ JoyPad::JoyPad( int i, int dev, QObject *parent )
debug_mesg("Valid file handle, setting up handlers and reading axis configs...\n");
open(dev);
debug_mesg("done resetting and setting up device index %d\n", i);
char id[256];
memset(id, 0, sizeof(id));
if (ioctl(joydev, JSIOCGNAME(sizeof(id)), id) < 0) {
deviceId = "Unknown";
}
else {
deviceId = id;
}
} else {
debug_mesg("This joypad does not have a valid file handle, not setting up event listeners\n");
}
@ -70,6 +62,15 @@ void JoyPad::open(int dev) {
close();
joydev = dev;
char id[256];
memset(id, 0, sizeof(id));
if (ioctl(joydev, JSIOCGNAME(sizeof(id)), id) < 0) {
deviceId = "Unknown";
}
else {
deviceId = id;
}
//read in the number of axes / buttons
axisCount = 0;
ioctl (joydev, JSIOCGAXES, &axisCount);
@ -176,7 +177,7 @@ bool JoyPad::readConfig( QTextStream &stream ) {
//only actually writes something if this JoyPad is NON DEFAULT.
void JoyPad::write( QTextStream &stream ) {
if (!axes.empty() || !buttons.empty()) {
stream << getName() << " {\n";
stream << "Joystick " << index << " {\n";
foreach (Axis *axis, axes) {
axis->write(stream);
}

View File

@ -46,8 +46,8 @@ class JoyPad : public QObject {
bool isDefault();
//read the dimensions on the real joystick and use them
void open( int dev );
//generates a name ("Joystick 1")
QString getName() const { return QString("Joystick %1").arg(index+1);}
const QString& getDeviceId() const { return deviceId; }
QString getName() const { return QString("Joystick %1 (%2)").arg(index+1).arg(deviceId); }
int getIndex() const { return index; }
private: