Skip to content

Commit

Permalink
USB: Add evdev support for keyboardmania
Browse files Browse the repository at this point in the history
  • Loading branch information
jackun committed Feb 24, 2021
1 parent 589f2a0 commit eeb7633
Show file tree
Hide file tree
Showing 9 changed files with 575 additions and 310 deletions.
6 changes: 3 additions & 3 deletions pcsx2/USB/usb-pad/dx/dinput-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ namespace usb_pad
INVERTFORCES[port] = SendDlgItemMessage(hWnd, IDC_CHECK1, BM_GETCHECK, 0, 0);
useRamp = !!SendDlgItemMessage(hWnd, IDC_CHECK3, BM_GETCHECK, 0, 0);
GAINZ[port][0] = SendMessage(GetDlgItem(hWnd, IDC_SLIDER4), TBM_GETPOS, 0, 0);
FFMULTI[port][0] = SendMessage(GetDlgItem(hWnd, IDC_SLIDER5), TBM_GETPOS, 0, 0);
FFMULTI[port][0] = SendMessage(GetDlgItem(hWnd, IDC_SLIDER5), TBM_GETPOS, 0, 0);
}

void SaveDInputConfig(int port, const char* dev_type)
Expand Down Expand Up @@ -1424,11 +1424,11 @@ namespace usb_pad
struct DXDlgSettings s;
s.port = port;
s.dev_type = dev_type;
if (strcmp(dev_type, "buzz_device") == 0)
if (strcmp(dev_type, BuzzDevice::TypeName()) == 0)
{
return DialogBoxParam(h.hInst, MAKEINTRESOURCE(IDD_DLG_BUZZ), h.hWnd, DxDialogProc, (LPARAM)&s);
}
if (strcmp(dev_type, "keyboardmania") == 0)
if (strcmp(dev_type, KeyboardmaniaDevice::TypeName()) == 0)
{
return DialogBoxParam(h.hInst, MAKEINTRESOURCE(IDD_DLG_KEYBOARDMANIA), h.hWnd, DxDialogProc, (LPARAM)&s);
}
Expand Down
12 changes: 6 additions & 6 deletions pcsx2/USB/usb-pad/evdev/evdev-gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@ namespace usb_pad
"RFKILL", /* linux:524 (KEY_RFKILL) */
};

static bool GetEventName(const char* dev_type, int map, int event, const char** name)
static bool GetEventName(const char* dev_type, int map, int event, bool is_button, const char** name)
{
if (!name)
return false;

if (map < JOY_STEERING || !strcmp(dev_type, BuzzDevice::TypeName()))
if (is_button)
{
if (event < (int)key_to_str.size())
{
Expand Down Expand Up @@ -593,7 +593,7 @@ namespace usb_pad
};
AxisValue axisVal[ABS_MAX + 1]{};
unsigned long absbit[NBITS(ABS_MAX)]{};
struct axis_correct abs_correct[ABS_MAX]{};
axis_correct abs_correct[ABS_MAX]{};

inverted = false;

Expand All @@ -616,9 +616,7 @@ namespace usb_pad
while ((len = read(js.second.fd, &event, sizeof(event))) > 0)
;

struct timeval timeout
{
};
timeval timeout{};
timeout.tv_sec = 5;
int result = select(maxfd + 1, &fdset, NULL, NULL, &timeout);

Expand Down Expand Up @@ -744,6 +742,8 @@ namespace usb_pad
int ret = 0;
if (!strcmp(dev_type, BuzzDevice::TypeName()))
ret = GtkBuzzConfigure(port, dev_type, "Evdev Settings", evdev::APINAME, GTK_WINDOW(data), apicbs);
else if (!strcmp(dev_type, KeyboardmaniaDevice::TypeName()))
ret = GtkKeyboardmaniaConfigure(port, dev_type, "Evdev Settings", evdev::APINAME, GTK_WINDOW(data), apicbs);
else
ret = GtkPadConfigure(port, dev_type, "Evdev Settings", evdev::APINAME, GTK_WINDOW(data), apicbs);
return ret;
Expand Down
48 changes: 16 additions & 32 deletions pcsx2/USB/usb-pad/evdev/evdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ namespace usb_pad
}
}
}
//quit:
closedir(dirp);
return false;
}
Expand Down Expand Up @@ -183,7 +182,6 @@ namespace usb_pad
}

list.assign(list_cache.begin(), list_cache.end());
//quit:
closedir(dirp);
}

Expand Down Expand Up @@ -220,7 +218,7 @@ namespace usb_pad
//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:
//treat_me_like_ABS_RY:
mWheelData.throttle = 0xFF;
mWheelData.brake = 0xFF;
if (value < 0)
Expand All @@ -230,18 +228,10 @@ namespace usb_pad
break;
case 0x80 | JOY_THROTTLE:
case ABS_Z:
/*if (mIsGamepad)
mWheelData.brake = 0xFF - NORM(value, 0xFF);
else*/
mWheelData.throttle = device.cfg.inverted[1] ? NORM(value, 0xFF) : 0xFF - NORM(value, 0xFF);
break;
case 0x80 | JOY_BRAKE:
case ABS_RZ:
/*if (mIsGamepad)
mWheelData.throttle = 0xFF - NORM(value, 0xFF);
else if (mIsDualAnalog)
goto treat_me_like_ABS_RY;
else*/
mWheelData.brake = device.cfg.inverted[2] ? NORM(value, 0xFF) : 0xFF - NORM(value, 0xFF);
break;

Expand Down Expand Up @@ -323,17 +313,16 @@ namespace usb_pad
break;

value = AxisCorrect(device.abs_correct[event.code], event.value);
/*if (event.code == 0)
event.code, device.axis_map[event.code] & ~0x80, event.value, 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)
if (mType == WT_BUZZ_CONTROLLER || mType == WT_KEYBOARDMANIA_CONTROLLER)
{
if (device.btn_map[event.code] != (uint16_t)-1)
{
Expand Down Expand Up @@ -637,22 +626,20 @@ namespace usb_pad
continue;
}

/*unsigned int version;
if (ioctl(mHandle, EVIOCGVERSION, &version) < 0)
{
SysMessage("%s: Get version failed: %s\n", APINAME, strerror(errno));
return false;
}*/

int max_buttons = JOY_STEERING;
switch (mType)
{
case WT_BUZZ_CONTROLLER:
LoadBuzzMappings(mDevType, mPort, it.id, device.cfg);
max_buttons = 20;
break;
case WT_KEYBOARDMANIA_CONTROLLER:
max_buttons = 31;
LoadMappings(mDevType, mPort, it.id, max_buttons, 0, device.cfg);
break;
default:
LoadMappings(mDevType, mPort, it.id, device.cfg);
max_buttons = JOY_STEERING;
LoadMappings(mDevType, mPort, it.id, max_buttons, 3, device.cfg);
if (!LoadSetting(mDevType, mPort, APINAME, N_GAIN_ENABLED, b_gain))
b_gain = 1;
if (!LoadSetting(mDevType, mPort, APINAME, N_GAIN, gain))
Expand Down Expand Up @@ -715,12 +702,6 @@ namespace usb_pad
}
}

#ifndef NDEBUG
for (int i = 0; i < ABS_MAX; ++i)
{
}
#endif

for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i)
{
if (test_bit(i, keybit))
Expand Down Expand Up @@ -776,9 +757,12 @@ namespace usb_pad

if (mHidHandle != -1)
{
uint8_t reset[7] = {0};
reset[0] = 0xF3; //stop forces
write(mHidHandle, reset, sizeof(reset));
if (mType <= WT_GT_FORCE)
{
uint8_t reset[7] = {0};
reset[0] = 0xF3; //stop forces
write(mHidHandle, reset, sizeof(reset));
}
close(mHidHandle);
}

Expand Down
Loading

0 comments on commit eeb7633

Please sign in to comment.