fix scrambeled axis/buttons indices
This commit is contained in:
@ -57,13 +57,14 @@ class Axis : public QObject {
|
|||||||
//recalculates the gradient curve. This should be run every time
|
//recalculates the gradient curve. This should be run every time
|
||||||
//maxSpeed, xZone, or dZone are changed.
|
//maxSpeed, xZone, or dZone are changed.
|
||||||
void adjustGradient();
|
void adjustGradient();
|
||||||
|
int axisIndex() const { return index; }
|
||||||
protected:
|
protected:
|
||||||
int tick;
|
int tick;
|
||||||
//This axis is logically depressed (positive or negative)
|
//This axis is logically depressed (positive or negative)
|
||||||
//if the axis is gradient, this is true even if it is not
|
//if the axis is gradient, this is true even if it is not
|
||||||
//currently generating a keypress at the instant.
|
//currently generating a keypress at the instant.
|
||||||
bool isOn;
|
bool isOn;
|
||||||
//which joystick this actually is
|
//the index of this axis on the joystick
|
||||||
int index;
|
int index;
|
||||||
//actually sends key events. Press is true iff the key
|
//actually sends key events. Press is true iff the key
|
||||||
//is to be depressed as opposed to released.
|
//is to be depressed as opposed to released.
|
||||||
|
@ -36,6 +36,7 @@ class Button : public QObject {
|
|||||||
void setKey(bool mouse, int value);
|
void setKey(bool mouse, int value);
|
||||||
//happens every MSEC (constant.h) milliseconds
|
//happens every MSEC (constant.h) milliseconds
|
||||||
void timerTick( int tick );
|
void timerTick( int tick );
|
||||||
|
int buttonIndex() const { return index; }
|
||||||
protected:
|
protected:
|
||||||
//true iff this button is physically depressed.
|
//true iff this button is physically depressed.
|
||||||
bool isButtonPressed;
|
bool isButtonPressed;
|
||||||
|
@ -23,6 +23,6 @@ inline void debug_mesg(const char *fmt, ...) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
inline void debug_mesg(...) {}
|
inline void debug_mesg(...) {}
|
||||||
#define debug_mesg(...)
|
#define debug_mesg(...) {}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -86,11 +86,11 @@ void JoyPad::open(int dev) {
|
|||||||
//have a real joystick axis mapped to it, and this function suddenly brings
|
//have a real joystick axis mapped to it, and this function suddenly brings
|
||||||
//that axis into use, the key assignment will not be lost because the axis
|
//that axis into use, the key assignment will not be lost because the axis
|
||||||
//will already exist and no new axis will be created.
|
//will already exist and no new axis will be created.
|
||||||
for (int i = 0; i < axisCount; i++) {
|
for (int i = axes.size(); i < axisCount; i++) {
|
||||||
if (axes[i] == 0) axes.insert(i, new Axis( i, this ));
|
axes.append(new Axis( i, this ));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < buttonCount; i++) {
|
for (int i = buttons.size(); i < buttonCount; i++) {
|
||||||
if (buttons[i] == 0) buttons.insert(i, new Button( i, this ));
|
buttons.append(new Button( i, this ));
|
||||||
}
|
}
|
||||||
debug_mesg("Setting up joyDeviceListeners\n");
|
debug_mesg("Setting up joyDeviceListeners\n");
|
||||||
readNotifier = new QSocketNotifier(joydev, QSocketNotifier::Read, this);
|
readNotifier = new QSocketNotifier(joydev, QSocketNotifier::Read, this);
|
||||||
@ -235,14 +235,14 @@ void JoyPad::jsevent(const js_event &msg) {
|
|||||||
if (type == JS_EVENT_AXIS) {
|
if (type == JS_EVENT_AXIS) {
|
||||||
debug_mesg("DEBUG: passing on an axis event\n");
|
debug_mesg("DEBUG: passing on an axis event\n");
|
||||||
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
|
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
|
||||||
Axis *axis = axes[msg.number];
|
if (msg.number < axes.size()) axes[msg.number]->jsevent(msg.value);
|
||||||
if (axis) axis->jsevent(msg.value);
|
else debug_mesg("DEBUG: axis index out of range: %d\n", msg.value);
|
||||||
}
|
}
|
||||||
else if (type == JS_EVENT_BUTTON) {
|
else if (type == JS_EVENT_BUTTON) {
|
||||||
debug_mesg("DEBUG: passing on a button event\n");
|
debug_mesg("DEBUG: passing on a button event\n");
|
||||||
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
|
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
|
||||||
Button *button = buttons[msg.number];
|
if (msg.number < buttons.size()) buttons[msg.number]->jsevent(msg.value);
|
||||||
if (button) button->jsevent(msg.value);
|
else debug_mesg("DEBUG: button index out of range: %d\n", msg.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QHash>
|
#include <QList>
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
|
|
||||||
class JoyPadWidget;
|
class JoyPadWidget;
|
||||||
@ -63,8 +63,8 @@ class JoyPad : public QObject {
|
|||||||
//layouts with different numbers of axes/buttons than the current
|
//layouts with different numbers of axes/buttons than the current
|
||||||
//devices. Note that with the current layout settings, the defined
|
//devices. Note that with the current layout settings, the defined
|
||||||
//buttons that don't actually exist on the device may not be contiguous.
|
//buttons that don't actually exist on the device may not be contiguous.
|
||||||
QHash<int, Axis*> axes;
|
QList<Axis*> axes;
|
||||||
QHash<int, Button*> buttons;
|
QList<Button*> buttons;
|
||||||
//the index of this device (devicenum)
|
//the index of this device (devicenum)
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
@ -91,10 +91,12 @@ void JoyPadWidget::jsevent( const js_event& msg ) {
|
|||||||
//other than a flash :)
|
//other than a flash :)
|
||||||
unsigned int type = msg.type & ~JS_EVENT_INIT;
|
unsigned int type = msg.type & ~JS_EVENT_INIT;
|
||||||
if (type == JS_EVENT_AXIS) {
|
if (type == JS_EVENT_AXIS) {
|
||||||
if (msg.number < axes.count()) axes[msg.number]->jsevent(msg.value);
|
if (msg.number < axes.size()) axes[msg.number]->jsevent(msg.value);
|
||||||
|
else debug_mesg("DEBUG: axis index out of range: %d\n", msg.value);
|
||||||
}
|
}
|
||||||
else if (type == JS_EVENT_BUTTON) {
|
else if (type == JS_EVENT_BUTTON) {
|
||||||
if (msg.number < buttons.count()) buttons[msg.number]->jsevent(msg.value);
|
if (msg.number < buttons.size()) buttons[msg.number]->jsevent(msg.value);
|
||||||
|
else debug_mesg("DEBUG: button index out of range: %d\n", msg.value);
|
||||||
}
|
}
|
||||||
//if we're doing quickset, it needs to know when we do something.
|
//if we're doing quickset, it needs to know when we do something.
|
||||||
if (quickset != NULL) {
|
if (quickset != NULL) {
|
||||||
|
Reference in New Issue
Block a user