Skip to content

Commit

Permalink
USB: Simplify evdev controller mapping
Browse files Browse the repository at this point in the history
Remove "clever autoconfig" that possibly mapped wrong control to wrong player.
Breaks mapping analog stick's single axis to two axes, for now.
  • Loading branch information
jackun committed Jul 12, 2021
1 parent 2925077 commit 1f0f584
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 163 deletions.
194 changes: 38 additions & 156 deletions pcsx2/USB/usb-pad/evdev/evdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -304,109 +290,31 @@ namespace usb_pad
for (int i = 0; i < len; i++)
{
input_event& event = events[i];
int code, value;
switch (event.type)
{
case EV_ABS:
{
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);
}
break;
case EV_KEY:
{
code = device.btn_map[event.code] != (uint16_t)-1 ? device.btn_map[event.code] : event.code;

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
}

uint16_t button = device.btn_map[event.code];
if (button == (uint16_t)-1 || !(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
}
button = button & ~0x8000;

//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
}
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?
Expand Down Expand Up @@ -476,13 +384,15 @@ namespace usb_pad
{
if (mUseRawFF)
{

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

Expand All @@ -495,9 +405,12 @@ namespace usb_pad
return len;
}

const ff_data* ffdata = (const ff_data*)data;
bool hires = (mType == WT_DRIVING_FORCE_PRO || mType == WT_DRIVING_FORCE_PRO_1102);
ParseFFData(ffdata, hires);
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;
}
Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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])
{
has_mappings = true;
device.btn_map[i] = 0x8000 | k;
}
}
}
}
for (int i = 0; i < BTN_JOYSTICK; ++i)
for (int k = 0; k < max_buttons; k++)
{
if (test_bit(i, keybit))
auto i = device.cfg.controls[k];
if (i >= 0 && i <= KEY_MAX)
{
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;
}
}
has_mappings = true;
device.btn_map[i] = 0x8000 | k;
}
}

if (!has_mappings)
{
close(device.cfg.fd);
Expand Down
3 changes: 1 addition & 2 deletions pcsx2/USB/usb-pad/evdev/shared-gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions pcsx2/USB/usb-pad/evdev/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/USB/usb-pad/usb-pad-ff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion pcsx2/USB/usb-pad/usb-pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1f0f584

Please sign in to comment.