mirror of https://github.com/PCSX2/pcsx2.git
USB: Simplify evdev controller mapping
Remove "clever autoconfig" that possibly mapped wrong control to wrong player. Breaks mapping analog stick's single axis to two axes, for now.
This commit is contained in:
parent
2925077169
commit
1f0f584397
|
@ -212,26 +212,12 @@ namespace usb_pad
|
|||
switch (code)
|
||||
{
|
||||
case 0x80 | JOY_STEERING:
|
||||
case ABS_X:
|
||||
mWheelData.steering = device.cfg.inverted[0] ? range - NORM(value, range) : NORM(value, range);
|
||||
break;
|
||||
//case ABS_Y: mWheelData.clutch = NORM(value, 0xFF); break; //no wheel on PS2 has one, afaik
|
||||
//case ABS_RX: mWheelData.axis_rx = NORM(event.value, 0xFF); break;
|
||||
case ABS_RY:
|
||||
//treat_me_like_ABS_RY:
|
||||
mWheelData.throttle = 0xFF;
|
||||
mWheelData.brake = 0xFF;
|
||||
if (value < 0)
|
||||
mWheelData.throttle = NORM2(value, 0xFF);
|
||||
else
|
||||
mWheelData.brake = NORM2(-value, 0xFF);
|
||||
break;
|
||||
case 0x80 | JOY_THROTTLE:
|
||||
case ABS_Z:
|
||||
mWheelData.throttle = device.cfg.inverted[1] ? NORM(value, 0xFF) : 0xFF - NORM(value, 0xFF);
|
||||
break;
|
||||
case 0x80 | JOY_BRAKE:
|
||||
case ABS_RZ:
|
||||
mWheelData.brake = device.cfg.inverted[2] ? NORM(value, 0xFF) : 0xFF - NORM(value, 0xFF);
|
||||
break;
|
||||
|
||||
|
@ -304,7 +290,6 @@ namespace usb_pad
|
|||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
input_event& event = events[i];
|
||||
int code, value;
|
||||
switch (event.type)
|
||||
{
|
||||
case EV_ABS:
|
||||
|
@ -312,7 +297,7 @@ namespace usb_pad
|
|||
if (mType == WT_BUZZ_CONTROLLER)
|
||||
break;
|
||||
|
||||
value = AxisCorrect(device.abs_correct[event.code], event.value);
|
||||
int value = AxisCorrect(device.abs_correct[event.code], event.value);
|
||||
//if (event.code == 0)
|
||||
// event.code, device.axis_map[event.code] & ~0x80, event.value, value);
|
||||
SetAxis(device, event.code, value);
|
||||
|
@ -320,94 +305,17 @@ namespace usb_pad
|
|||
break;
|
||||
case EV_KEY:
|
||||
{
|
||||
code = device.btn_map[event.code] != (uint16_t)-1 ? device.btn_map[event.code] : event.code;
|
||||
uint16_t button = device.btn_map[event.code];
|
||||
if (button == (uint16_t)-1 || !(button & 0x8000))
|
||||
break;
|
||||
|
||||
if (mType == WT_BUZZ_CONTROLLER || mType == WT_KEYBOARDMANIA_CONTROLLER)
|
||||
{
|
||||
if (device.btn_map[event.code] != (uint16_t)-1)
|
||||
{
|
||||
if (event.value)
|
||||
mWheelData.buttons |= 1 << (code & ~0x8000); //on
|
||||
else
|
||||
mWheelData.buttons &= ~(1 << (code & ~0x8000)); //off
|
||||
}
|
||||
button = button & ~0x8000;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
PS2Buttons button = PAD_BUTTON_COUNT;
|
||||
if (code >= (0x8000 | JOY_CROSS) && // user mapped
|
||||
code <= (0x8000 | JOY_L3))
|
||||
{
|
||||
button = (PS2Buttons)(code & ~0x8000);
|
||||
}
|
||||
else if (code >= BTN_TRIGGER && code < BTN_BASE5) // try to guess
|
||||
{
|
||||
button = (PS2Buttons)((code - BTN_TRIGGER) & ~0x8000);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
// Map to xbox360ish controller
|
||||
switch (code)
|
||||
{
|
||||
// Digital hatswitch
|
||||
case 0x8000 | JOY_LEFT:
|
||||
mWheelData.hat_horz = (!event.value ? PAD_HAT_COUNT : PAD_HAT_W);
|
||||
break;
|
||||
case 0x8000 | JOY_RIGHT:
|
||||
mWheelData.hat_horz = (!event.value ? PAD_HAT_COUNT : PAD_HAT_E);
|
||||
break;
|
||||
case 0x8000 | JOY_UP:
|
||||
mWheelData.hat_vert = (!event.value ? PAD_HAT_COUNT : PAD_HAT_N);
|
||||
break;
|
||||
case 0x8000 | JOY_DOWN:
|
||||
mWheelData.hat_vert = (!event.value ? PAD_HAT_COUNT : PAD_HAT_S);
|
||||
break;
|
||||
case BTN_WEST:
|
||||
button = PAD_SQUARE;
|
||||
break;
|
||||
case BTN_NORTH:
|
||||
button = PAD_TRIANGLE;
|
||||
break;
|
||||
case BTN_EAST:
|
||||
button = PAD_CIRCLE;
|
||||
break;
|
||||
case BTN_SOUTH:
|
||||
button = PAD_CROSS;
|
||||
break;
|
||||
case BTN_SELECT:
|
||||
button = PAD_SELECT;
|
||||
break;
|
||||
case BTN_START:
|
||||
button = PAD_START;
|
||||
break;
|
||||
case BTN_TR:
|
||||
button = PAD_R1;
|
||||
break;
|
||||
case BTN_TL:
|
||||
button = PAD_L1;
|
||||
break;
|
||||
case BTN_TR2:
|
||||
button = PAD_R2;
|
||||
break;
|
||||
case BTN_TL2:
|
||||
button = PAD_L2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//if (button != PAD_BUTTON_COUNT)
|
||||
{
|
||||
if (event.value)
|
||||
mWheelData.buttons |= 1 << convert_wt_btn(mType, button); //on
|
||||
else
|
||||
mWheelData.buttons &= ~(1 << convert_wt_btn(mType, button)); //off
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EV_SYN: //TODO useful?
|
||||
{
|
||||
|
@ -476,13 +384,15 @@ namespace usb_pad
|
|||
{
|
||||
if (mUseRawFF)
|
||||
{
|
||||
|
||||
if (mType <= WT_GT_FORCE)
|
||||
{
|
||||
if (data[0] == 0x8 || data[0] == 0xB)
|
||||
return len;
|
||||
if (data[0] == 0xF8 &&
|
||||
/* Allow range changes */
|
||||
!(data[1] == 0x81 || data[1] == 0x02 || data[1] == 0x03))
|
||||
return len; //don't send extended commands
|
||||
}
|
||||
|
||||
std::array<uint8_t, 8> report{0};
|
||||
|
||||
|
@ -495,9 +405,12 @@ namespace usb_pad
|
|||
return len;
|
||||
}
|
||||
|
||||
if (mType <= WT_GT_FORCE)
|
||||
{
|
||||
const ff_data* ffdata = (const ff_data*)data;
|
||||
bool hires = (mType == WT_DRIVING_FORCE_PRO || mType == WT_DRIVING_FORCE_PRO_1102);
|
||||
ParseFFData(ffdata, hires);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
@ -616,7 +529,10 @@ namespace usb_pad
|
|||
continue;
|
||||
}
|
||||
|
||||
int max_buttons = JOY_STEERING;
|
||||
// device.cfg.controls[0..max_buttons] - mapped buttons
|
||||
// device.cfg.controls[max_buttons..etc] - mapped axes
|
||||
int max_buttons = 0;
|
||||
int max_axes = 0;
|
||||
switch (mType)
|
||||
{
|
||||
case WT_BUZZ_CONTROLLER:
|
||||
|
@ -629,6 +545,7 @@ namespace usb_pad
|
|||
break;
|
||||
default:
|
||||
max_buttons = JOY_STEERING;
|
||||
max_axes = 3;
|
||||
LoadMappings(mDevType, mPort, it.id, max_buttons, 3, device.cfg);
|
||||
if (!LoadSetting(mDevType, mPort, APINAME, N_GAIN_ENABLED, b_gain))
|
||||
b_gain = 1;
|
||||
|
@ -660,30 +577,19 @@ namespace usb_pad
|
|||
continue;
|
||||
}
|
||||
|
||||
|
||||
//device.axis_map[i] = device.axes;
|
||||
|
||||
// convert values into 16 bit range
|
||||
CalcAxisCorr(device.abs_correct[i], absinfo);
|
||||
|
||||
//TODO joystick/gamepad is dual analog?
|
||||
if (i == ABS_RZ)
|
||||
{
|
||||
//absinfo.value = AxisCorrect(mAbsCorrect[i], absinfo.value);
|
||||
if (std::abs(absinfo.value) < 200) /* 200 is random, allows for some dead zone */
|
||||
device.is_dualanalog = true;
|
||||
}
|
||||
|
||||
// FIXME axes as buttons
|
||||
for (int k = max_buttons /*JOY_STEERING*/; k < JOY_MAPS_COUNT; k++)
|
||||
for (int k = 0; k < max_axes; k++)
|
||||
{
|
||||
if (i == device.cfg.controls[k])
|
||||
if (i == device.cfg.controls[k + max_buttons])
|
||||
{
|
||||
has_mappings = true;
|
||||
device.axis_map[i] = 0x80 | k;
|
||||
device.axis_map[i] = 0x80 | (k + JOY_STEERING);
|
||||
// TODO Instead of single FF instance, create for every device with X-axis???
|
||||
// and then switch between them according to which device was used recently
|
||||
if (k == JOY_STEERING && !mFFdev && !mUseRawFF)
|
||||
if (k == 0 && !mFFdev && !mUseRawFF)
|
||||
{
|
||||
mFFdev = new EvdevFF(device.cfg.fd, b_gain, gain, b_ac, ac);
|
||||
}
|
||||
|
@ -692,40 +598,16 @@ namespace usb_pad
|
|||
}
|
||||
}
|
||||
|
||||
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i)
|
||||
{
|
||||
if (test_bit(i, keybit))
|
||||
{
|
||||
device.btn_map[i] = -1; //device.buttons;
|
||||
if (i == BTN_GAMEPAD)
|
||||
{
|
||||
device.is_gamepad = true;
|
||||
}
|
||||
for (int k = 0; k < max_buttons; k++)
|
||||
{
|
||||
if (i == device.cfg.controls[k])
|
||||
auto i = device.cfg.controls[k];
|
||||
if (i >= 0 && i <= KEY_MAX)
|
||||
{
|
||||
has_mappings = true;
|
||||
device.btn_map[i] = 0x8000 | k;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < BTN_JOYSTICK; ++i)
|
||||
{
|
||||
if (test_bit(i, keybit))
|
||||
{
|
||||
device.btn_map[i] = -1; //device.buttons;
|
||||
for (int k = 0; k < max_buttons; k++)
|
||||
{
|
||||
if (i == device.cfg.controls[k])
|
||||
{
|
||||
has_mappings = true;
|
||||
device.btn_map[i] = 0x8000 | k;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_mappings)
|
||||
{
|
||||
close(device.cfg.fd);
|
||||
|
|
|
@ -527,7 +527,6 @@ namespace usb_pad
|
|||
{
|
||||
GtkWidget *ro_frame, *rs_cb;
|
||||
GtkWidget *right_vbox, *left_vbox;
|
||||
GtkWidget* button;
|
||||
|
||||
ConfigData cfg{};
|
||||
cfg.dev_type = dev_type;
|
||||
|
@ -614,7 +613,7 @@ namespace usb_pad
|
|||
GtkWidget* hbox = gtk_hbox_new(false, 5);
|
||||
gtk_container_add(GTK_CONTAINER(right_vbox), hbox);
|
||||
|
||||
button = gtk_button_new_with_label("Steering");
|
||||
GtkWidget* button = gtk_button_new_with_label("Steering");
|
||||
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5);
|
||||
g_object_set_data(G_OBJECT(button), CONTROL, reinterpret_cast<gpointer>(JOY_STEERING));
|
||||
g_object_set_data(G_OBJECT(button), CFG, &cfg);
|
||||
|
|
|
@ -201,9 +201,6 @@ namespace usb_pad
|
|||
uint8_t axis_map[ABS_MAX + 1];
|
||||
uint16_t btn_map[KEY_MAX + 1];
|
||||
struct axis_correct abs_correct[ABS_MAX];
|
||||
bool is_gamepad; //xboxish gamepad
|
||||
bool is_dualanalog; // tricky, have to read the AXIS_RZ somehow and
|
||||
// determine if its unpressed value is zero
|
||||
};
|
||||
|
||||
int GtkPadConfigure(int port, const char* dev_type, const char* title, const char* apiname, GtkWindow* parent, ApiCallbacks& apicbs);
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace usb_pad
|
|||
|
||||
static int warned = 0;
|
||||
int caps = 0;
|
||||
DevCon.WriteLn("FFB %02X, %02X, %02X, %02X : %02X, %02X, %02X, %02X\n",
|
||||
DevCon.WriteLn("FFB %02X, %02X, %02X, %02X : %02X, %02X, %02X, %02X",
|
||||
ffdata->cmdslot, ffdata->type, ffdata->u.params[0], ffdata->u.params[1],
|
||||
ffdata->u.params[2], ffdata->u.params[3], ffdata->u.params[4], ffdata->padd0);
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace usb_pad
|
|||
|
||||
std::list<std::string> KeyboardmaniaDevice::ListAPIs()
|
||||
{
|
||||
return {"evdev"};
|
||||
return PadDevice::ListAPIs();
|
||||
}
|
||||
|
||||
const TCHAR* KeyboardmaniaDevice::LongAPIName(const std::string& name)
|
||||
|
|
Loading…
Reference in New Issue