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 Jul 10, 2021
1 parent 09a239a commit c66314c
Show file tree
Hide file tree
Showing 14 changed files with 582 additions and 423 deletions.
4 changes: 3 additions & 1 deletion pcsx2/USB/gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include <gtk/gtk.h>

GtkWidget* new_combobox(const char* label, GtkWidget* vbox, bool scrollable = false); // linux/config-gtk.cpp
12 changes: 9 additions & 3 deletions pcsx2/USB/linux/config-gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static void configureApi(GtkWidget* widget, gpointer data)
}
}

GtkWidget* new_combobox(const char* label, GtkWidget* vbox)
GtkWidget* new_combobox(const char* label, GtkWidget* vbox, bool scrollable)
{
GtkWidget *rs_hbox, *rs_label, *rs_cb;

Expand All @@ -199,10 +199,16 @@ GtkWidget* new_combobox(const char* label, GtkWidget* vbox)
rs_label = gtk_label_new(label);
gtk_box_pack_start(GTK_BOX(rs_hbox), rs_label, FALSE, TRUE, 5);
gtk_label_set_justify(GTK_LABEL(rs_label), GTK_JUSTIFY_RIGHT);
gtk_misc_set_alignment(GTK_MISC(rs_label), 1, 0.5);

rs_cb = gtk_combo_box_text_new();
gtk_box_pack_start(GTK_BOX(rs_hbox), rs_cb, TRUE, TRUE, 5);
if (!scrollable)
gtk_box_pack_start(GTK_BOX(rs_hbox), rs_cb, TRUE, TRUE, 5);
else
{
GtkWidget* sw = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(sw), rs_cb);
gtk_box_pack_start(GTK_BOX(rs_hbox), sw, TRUE, TRUE, 5);
}
return rs_cb;
}

Expand Down
2 changes: 0 additions & 2 deletions pcsx2/USB/usb-eyetoy/cam-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

#include <linux/videodev2.h>

GtkWidget* new_combobox(const char* label, GtkWidget* vbox); // src/linux/config-gtk.cpp

#define CLEAR(x) memset(&(x), 0, sizeof(x))

namespace usb_eyetoy
Expand Down
2 changes: 0 additions & 2 deletions pcsx2/USB/usb-hid/evdev/evdev-gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <cstdio>
#include <sstream>

GtkWidget* new_combobox(const char* label, GtkWidget* vbox); // src/linux/config-gtk.cpp

namespace usb_hid
{
namespace evdev
Expand Down
2 changes: 0 additions & 2 deletions pcsx2/USB/usb-mic/audiodev-pulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "USB/dynlink/pulse.h"
#endif

GtkWidget* new_combobox(const char* label, GtkWidget* vbox); // src/linux/config-gtk.cpp

namespace usb_mic
{
namespace audiodev_pulse
Expand Down
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 @@ -1316,7 +1316,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 @@ -1460,11 +1460,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
18 changes: 9 additions & 9 deletions pcsx2/USB/usb-pad/evdev/evdev-gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ namespace usb_pad
"BRIGHTNESS_ZERO", /* linux:244 (KEY_BRIGHTNESS_ZERO) */
"DISPLAY_OFF", /* linux:245 (KEY_DISPLAY_OFF) */
"WIMAX", /* linux:246 (KEY_WIMAX) */
"247", /* linux:247 (unnamed) */
"248", /* linux:248 (unnamed) */
"RFKILL", /* linux:247 (KEY_RFKILL) */
"MICMUTE", /* linux:248 (KEY_MICMUTE) */
"249", /* linux:249 (unnamed) */
"250", /* linux:250 (unnamed) */
"251", /* linux:251 (unnamed) */
Expand Down Expand Up @@ -556,15 +556,15 @@ namespace usb_pad
"NUMERIC_9", /* linux:521 (KEY_NUMERIC_9) */
"NUMERIC_STAR", /* linux:522 (KEY_NUMERIC_STAR) */
"NUMERIC_POUND", /* linux:523 (KEY_NUMERIC_POUND) */
"RFKILL", /* linux:524 (KEY_RFKILL) */
"KEY_NUMERIC_A", /* linux:524 (KEY_NUMERIC_A) */
};

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
72 changes: 21 additions & 51 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 @@ -151,7 +150,7 @@ namespace usb_pad
str.clear();
str.str("");
str << EVDEV_DIR << dp->d_name;
std::string path = str.str();
const std::string path = str.str();

auto it = std::find_if(list_cache.begin(), list_cache.end(),
[&path](evdev_device& dev) {
Expand All @@ -168,22 +167,21 @@ namespace usb_pad
continue;
}

//list_cache.push_back(std::make_pair(std::string(dp->d_name), path));

res = ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
if (res < 0)
Console.Warning("EVIOCGNAME");
else
{
list_cache.push_back({buf, dp->d_name, path});
evdev_device dev{buf, dp->d_name, path, {}};
res = ioctl(fd, EVIOCGID, &dev.input_id);
list_cache.push_back(dev);
}

close(fd);
}
}

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 @@ -568,7 +557,7 @@ namespace usb_pad
}

if (joypath.empty() || !file_exists(joypath))
goto quit;
return 1;

int fd = -1;
if ((fd = open(joypath.c_str(), O_RDWR | O_NONBLOCK)) < 0)
Expand All @@ -584,16 +573,6 @@ namespace usb_pad
int pid, vid;
if ((mUseRawFF = FindHidraw(evphys, hid_dev, &vid, &pid)))
{

// For safety, only allow Logitech (classic ffb) devices
if (vid != 0x046D /* Logitech */ /*|| info.bustype != BUS_USB*/
|| pid == 0xc262 /* G920 hid mode */
|| pid == 0xc261 /* G920 xbox mode */
)
{
mUseRawFF = 0;
}

// check if still using hidraw and run the thread
if (mUseRawFF && !mWriterThreadIsRunning)
{
Expand Down Expand Up @@ -637,22 +616,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 +692,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 @@ -763,10 +734,6 @@ namespace usb_pad
}

return 0;

quit:
Close();
return 1;
}

int EvDevPad::Close()
Expand All @@ -776,9 +743,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 c66314c

Please sign in to comment.