From de5f7f70e2d653d0a05949c6963ca9b522e09f95 Mon Sep 17 00:00:00 2001 From: kust2708 Date: Sat, 27 Feb 2016 20:04:06 +0100 Subject: [PATCH] OnePad: Fix multi-gamepad support Can change the number of gamepad with the constant GAMEPAD_NUMBER in the onepad.h file --- plugins/onepad/KeyStatus.cpp | 2 +- plugins/onepad/KeyStatus.h | 18 +++++++++--------- plugins/onepad/Linux/dialog.cpp | 24 ++++++++++++------------ plugins/onepad/Linux/dialog.h | 1 - plugins/onepad/Linux/ini.cpp | 6 +++--- plugins/onepad/Linux/linux.cpp | 2 +- plugins/onepad/controller.h | 13 ++++++++----- plugins/onepad/keyboard.cpp | 6 +++--- plugins/onepad/onepad.cpp | 3 ++- plugins/onepad/onepad.h | 2 ++ 10 files changed, 41 insertions(+), 36 deletions(-) diff --git a/plugins/onepad/KeyStatus.cpp b/plugins/onepad/KeyStatus.cpp index 11c2f410d1..8ebd108d25 100644 --- a/plugins/onepad/KeyStatus.cpp +++ b/plugins/onepad/KeyStatus.cpp @@ -23,7 +23,7 @@ void KeyStatus::Init() { - for (int pad = 0; pad < 2; pad++) { + for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { m_button[pad] = 0xFFFF; m_internal_button_kbd[pad] = 0xFFFF; m_internal_button_joy[pad] = 0xFFFF; diff --git a/plugins/onepad/KeyStatus.h b/plugins/onepad/KeyStatus.h index 98b912f928..b540ad5e4d 100644 --- a/plugins/onepad/KeyStatus.h +++ b/plugins/onepad/KeyStatus.h @@ -35,18 +35,18 @@ typedef struct class KeyStatus { private: - u16 m_button[2]; - u16 m_internal_button_kbd[2]; - u16 m_internal_button_joy[2]; + u16 m_button[GAMEPAD_NUMBER]; + u16 m_internal_button_kbd[GAMEPAD_NUMBER]; + u16 m_internal_button_joy[GAMEPAD_NUMBER]; - u8 m_button_pressure[2][MAX_KEYS]; - u8 m_internal_button_pressure[2][MAX_KEYS]; + u8 m_button_pressure[GAMEPAD_NUMBER][MAX_KEYS]; + u8 m_internal_button_pressure[GAMEPAD_NUMBER][MAX_KEYS]; - bool m_state_acces[2]; + bool m_state_acces[GAMEPAD_NUMBER]; - PADAnalog m_analog[2]; - PADAnalog m_internal_analog_kbd[2]; - PADAnalog m_internal_analog_joy[2]; + PADAnalog m_analog[GAMEPAD_NUMBER]; + PADAnalog m_internal_analog_kbd[GAMEPAD_NUMBER]; + PADAnalog m_internal_analog_joy[GAMEPAD_NUMBER]; void analog_set(u32 pad, u32 index, u8 value); bool analog_is_reversed(u32 pad, u32 index); diff --git a/plugins/onepad/Linux/dialog.cpp b/plugins/onepad/Linux/dialog.cpp index 70cd374219..46ab7628eb 100644 --- a/plugins/onepad/Linux/dialog.cpp +++ b/plugins/onepad/Linux/dialog.cpp @@ -240,10 +240,10 @@ Dialog::Dialog() : wxFrame( NULL, // Parent { // Tabs panels m_pan_tabs[i] = new opPanel( - m_tab_gamepad, - wxID_ANY, - wxDefaultPosition, - wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT) + m_tab_gamepad, + wxID_ANY, + wxDefaultPosition, + wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT) ); // Add new page // Define label @@ -258,14 +258,14 @@ Dialog::Dialog() : wxFrame( NULL, // Parent for(int j=0; jSetLabel(_T("&Left Joystick Config")); diff --git a/plugins/onepad/Linux/dialog.h b/plugins/onepad/Linux/dialog.h index 0f7ab28ed2..c2e1e8c115 100644 --- a/plugins/onepad/Linux/dialog.h +++ b/plugins/onepad/Linux/dialog.h @@ -59,7 +59,6 @@ enum gui_buttons { }; #define BUTTONS_LENGHT 32 // numbers of buttons on the gamepad -#define GAMEPAD_NUMBER 2 // numbers of gamepad #define UPDATE_TIME 5 #define DEFAULT_WIDTH 1000 #define DEFAULT_HEIGHT 740 diff --git a/plugins/onepad/Linux/ini.cpp b/plugins/onepad/Linux/ini.cpp index 98a45da8d0..5cbb9f324a 100644 --- a/plugins/onepad/Linux/ini.cpp +++ b/plugins/onepad/Linux/ini.cpp @@ -133,7 +133,7 @@ void SaveConfig() fprintf(f, "joy_pad_map = %d\n", conf->joyid_map); fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity()); - for (int pad = 0; pad < 2; pad++) + for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { for (int key = 0; key < MAX_KEYS; key++) { @@ -142,7 +142,7 @@ void SaveConfig() } map::iterator it; - for (int pad = 0; pad < 2 ; pad++) + for (int pad = 0; pad < GAMEPAD_NUMBER ; pad++) for (it = conf->keysym_map[pad].begin(); it != conf->keysym_map[pad].end(); ++it) fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it->first, it->second); @@ -181,7 +181,7 @@ void LoadConfig() if (fscanf(f, "ff_intensity = %d\n", &value) == 0) goto error; conf->set_ff_intensity(value); - for (int pad = 0; pad < 2; pad++) + for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { for (int key = 0; key < MAX_KEYS; key++) { diff --git a/plugins/onepad/Linux/linux.cpp b/plugins/onepad/Linux/linux.cpp index f6a9c3eb4d..602b1e9519 100644 --- a/plugins/onepad/Linux/linux.cpp +++ b/plugins/onepad/Linux/linux.cpp @@ -172,7 +172,7 @@ EXPORT_C_(void) PADupdate(int pad) // Actually PADupdate is always call with pad == 0. So you need to update both // pads -- Gregory - for (int cpad = 0; cpad < 2; cpad++) { + for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) { // Poll keyboard/mouse event key_status->keyboard_state_acces(cpad); PollForX11KeyboardInput(cpad); diff --git a/plugins/onepad/controller.h b/plugins/onepad/controller.h index 55ca2d6796..bd7c9b7297 100644 --- a/plugins/onepad/controller.h +++ b/plugins/onepad/controller.h @@ -52,7 +52,7 @@ extern int button_to_key(int button_id); extern int axis_to_key(int full_axis, int sign, int axis_id); extern int hat_to_key(int dir, int axis_id); -extern int PadEnum[2][2]; +//extern int PadEnum[2][2]; // never used class PADconf { @@ -71,14 +71,14 @@ class PADconf u16 sixaxis_usb :1; u16 sixaxis_pressure :1; u16 _free : 7; // The 8 remaining bits are unused, do what you wish with them ;) - } pad_options[2]; // One for each pads + } pad_options[GAMEPAD_NUMBER]; // One for each pads u32 packed_options; // Only first 8 bits of each 16 bits series are really used, rest is padding }; - u32 keys[2][MAX_KEYS]; + u32 keys[GAMEPAD_NUMBER][MAX_KEYS]; u32 log; u32 joyid_map; - map keysym_map[2]; + map keysym_map[GAMEPAD_NUMBER]; PADconf() { init(); } @@ -87,8 +87,11 @@ class PADconf log = packed_options = joyid_map = 0; ff_intensity = 0x7FFF; // set it at max value by default sensibility = 500; - for (int pad = 0; pad < 2 ; pad++) + for (int pad = 0; pad < GAMEPAD_NUMBER ; pad++) + { keysym_map[pad].clear(); + set_joyid((u32)pad, (u32)pad); // define id mapping for each gamepad + } } void set_joyid(u32 pad, u32 joy_id) { diff --git a/plugins/onepad/keyboard.cpp b/plugins/onepad/keyboard.cpp index 3696805aa9..273809bd6f 100644 --- a/plugins/onepad/keyboard.cpp +++ b/plugins/onepad/keyboard.cpp @@ -260,7 +260,7 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_KEYDOWN: if (lParam & 0x40000000) return TRUE; - for (int pad = 0; pad < 2; ++pad) + for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) { for (int i = 0; i < MAX_KEYS; i++) { @@ -277,7 +277,7 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) break; case WM_KEYUP: - for (int pad = 0; pad < 2; ++pad) + for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) { for (int i = 0; i < MAX_KEYS; i++) { @@ -304,7 +304,7 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) return GSwndProc(hWnd, msg, wParam, lParam); } - for (int pad = 0; pad < 2; ++pad) + for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) key_status->commit_status(pad); return TRUE; diff --git a/plugins/onepad/onepad.cpp b/plugins/onepad/onepad.cpp index 64e5d48275..f84a13df23 100644 --- a/plugins/onepad/onepad.cpp +++ b/plugins/onepad/onepad.cpp @@ -49,7 +49,8 @@ const u32 version = PS2E_PAD_VERSION; const u32 revision = 1; const u32 build = 2; // increase that with each version -int PadEnum[2][2] = {{0, 2}, {1, 3}}; +// Useless variable ... +//int PadEnum[2][2] = {{0, 2}, {1, 3}}; u8 stdpar[2][20] = { {0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80, diff --git a/plugins/onepad/onepad.h b/plugins/onepad/onepad.h index 81acf5a575..8b73876eee 100644 --- a/plugins/onepad/onepad.h +++ b/plugins/onepad/onepad.h @@ -22,6 +22,8 @@ #ifndef __PAD_H__ #define __PAD_H__ +#define GAMEPAD_NUMBER 2 // numbers of gamepad + #include #include #include