Skip to content

Commit 5ae40f5

Browse files
committed
updated ps5 and xbox controller default mapping, added default mouse and keyboard mapping
1 parent e52825e commit 5ae40f5

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

user_program/usb4vc_ui.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,20 @@ def is_pressed(self):
101101
USBGP_ABS_HAT0X = 0x10 # D-pad X
102102
USBGP_ABS_HAT0Y = 0x11 # D-pad Y
103103

104+
GENERIC_USB_GAMEPAD_TO_MOUSE_KB_DEAULT_MAPPING = {
105+
"MAPPING_TYPE": "DEFAULT_MOUSE_KB",
106+
'BTN_TL': {'code': 'BTN_LEFT'},
107+
'BTN_TR': {'code': 'BTN_RIGHT'},
108+
'BTN_TL2': {'code': 'BTN_LEFT'},
109+
'BTN_TR2': {'code': 'BTN_RIGHT'},
110+
'ABS_X': {'code': 'REL_X'},
111+
'ABS_Y': {'code': 'REL_Y'},
112+
'ABS_HAT0X': {'code': 'KEY_RIGHT', 'code_neg': 'KEY_LEFT'},
113+
'ABS_HAT0Y': {'code': 'KEY_DOWN', 'code_neg': 'KEY_UP'}
114+
}
115+
104116
IBM_GENERIC_USB_GAMEPAD_TO_15PIN_GAMEPORT_GAMEPAD_DEAULT_MAPPING = {
105-
"IS_DEFAULT": True,
117+
"MAPPING_TYPE": "DEFAULT_15PIN",
106118
# buttons to buttons
107119
'BTN_SOUTH': {'code':'IBM_GGP_BTN_1'},
108120
'BTN_NORTH': {'code':'IBM_GGP_BTN_2'},
@@ -134,6 +146,7 @@ def is_pressed(self):
134146
PROTOCOL_MICROSOFT_SERIAL_MOUSE = {'pid':5, 'display_name':"Microsft Serial"}
135147
PROTOCOL_ADB_MOUSE = {'pid':6, 'display_name':"ADB"}
136148
PROTOCOL_15PIN_GAMEPORT_GAMEPAD = {'pid':7, 'display_name':"Generic 15-Pin", 'mapping':IBM_GENERIC_USB_GAMEPAD_TO_15PIN_GAMEPORT_GAMEPAD_DEAULT_MAPPING}
149+
PROTOCOL_USB_GP_TO_MOUSE_KB = {'pid':0, 'display_name':'Mouse & KB', 'mapping':GENERIC_USB_GAMEPAD_TO_MOUSE_KB_DEAULT_MAPPING}
137150
# PROTOCOL_GAMEPORT_GRAVIS_GAMEPAD = {'pid':8, 'display_name':"Gravis Pro"}
138151
# PROTOCOL_GAMEPORT_MICROSOFT_SIDEWINDER = {'pid':9, 'display_name':"MS Sidewinder"}
139152
PROTOCOL_RAW_KEYBOARD = {'pid':125, 'display_name':"Raw data"}
@@ -345,12 +358,11 @@ def oled_print_centered(text, font, y, this_canvas):
345358

346359
ibmpc_keyboard_protocols = [PROTOCOL_OFF, PROTOCOL_AT_PS2_KB, PROTOCOL_XT_KB]
347360
ibmpc_mouse_protocols = [PROTOCOL_OFF, PROTOCOL_PS2_MOUSE, PROTOCOL_MICROSOFT_SERIAL_MOUSE]
348-
# ibmpc_gamepad_protocols = [PROTOCOL_OFF, PROTOCOL_15PIN_GAMEPORT_GAMEPAD, PROTOCOL_GAMEPORT_GRAVIS_GAMEPAD, PROTOCOL_GAMEPORT_MICROSOFT_SIDEWINDER]
349-
ibmpc_gamepad_protocols = [PROTOCOL_OFF, PROTOCOL_15PIN_GAMEPORT_GAMEPAD]
361+
ibmpc_gamepad_protocols = [PROTOCOL_OFF, PROTOCOL_15PIN_GAMEPORT_GAMEPAD, PROTOCOL_USB_GP_TO_MOUSE_KB]
350362

351363
adb_keyboard_protocols = [PROTOCOL_OFF, PROTOCOL_ADB_KB]
352364
adb_mouse_protocols = [PROTOCOL_OFF, PROTOCOL_ADB_MOUSE]
353-
adb_gamepad_protocols = [PROTOCOL_OFF]
365+
adb_gamepad_protocols = [PROTOCOL_OFF, PROTOCOL_USB_GP_TO_MOUSE_KB]
354366

355367
raw_keyboard_protocols = [PROTOCOL_OFF, PROTOCOL_RAW_KEYBOARD]
356368
raw_mouse_protocols = [PROTOCOL_OFF, PROTOCOL_RAW_MOUSE]

user_program/usb4vc_usb_scan.py

+51-4
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,49 @@ def translate_dict(old_mapping_dict, lookup_dict):
235235
lookup_result = lookup_dict.get(key)
236236
if lookup_result is not None:
237237
translated_map_dict[lookup_result] = old_mapping_dict[key]
238+
del translated_map_dict[key]
238239
return translated_map_dict
239240

241+
XBOX_DEFAULT_KB_MOUSE_MAPPING = {
242+
'XB1_A': {'code': 'BTN_LEFT'},
243+
'XB1_B': {'code': 'BTN_RIGHT'},
244+
'XB1_LSX': {'code': 'REL_X'},
245+
'XB1_LSY': {'code': 'REL_Y'},
246+
'XB1_LB': {'code': 'BTN_LEFT'},
247+
'XB1_RB': {'code': 'BTN_RIGHT'},
248+
'XB1_RSX': {'code': 'KEY_RIGHT', 'code_neg': 'KEY_LEFT'},
249+
'XB1_RSY': {'code': 'KEY_DOWN', 'code_neg': 'KEY_UP'},
250+
'XB1_DPX': {'code': 'KEY_RIGHT', 'code_neg': 'KEY_LEFT'},
251+
'XB1_DPY': {'code': 'KEY_DOWN', 'code_neg': 'KEY_UP'},
252+
'XB1_X': {'code': 'BTN_LEFT'},
253+
'XB1_Y': {'code': 'BTN_RIGHT'},
254+
'XB1_MENU': {'code': 'KEY_ESC'},
255+
'XB1_VIEW': {'code': 'KEY_ESC'}
256+
}
257+
258+
PLAYSTATION_DEFAULT_KB_MOUSE_MAPPING = {
259+
'PS5_CROSS': {'code': 'BTN_LEFT'},
260+
'PS5_SQUARE': {'code': 'BTN_LEFT'},
261+
'PS5_L1': {'code': 'BTN_LEFT'},
262+
'PS5_L2_BUTTON': {'code': 'BTN_LEFT'},
263+
264+
'PS5_CIRCLE': {'code': 'BTN_RIGHT'},
265+
'PS5_TRIANGLE': {'code': 'BTN_RIGHT'},
266+
'PS5_R1': {'code': 'BTN_RIGHT'},
267+
'PS5_R2_BUTTON': {'code': 'BTN_RIGHT'},
268+
269+
'PS5_LSX': {'code': 'REL_X'},
270+
'PS5_LSY': {'code': 'REL_Y'},
271+
272+
'PS5_RSX': {'code': 'KEY_RIGHT', 'code_neg': 'KEY_LEFT'},
273+
'PS5_RSY': {'code': 'KEY_DOWN', 'code_neg': 'KEY_UP'},
274+
'PS5_DPX': {'code': 'KEY_RIGHT', 'code_neg': 'KEY_LEFT'},
275+
'PS5_DPY': {'code': 'KEY_DOWN', 'code_neg': 'KEY_UP'},
276+
277+
'PS5_CREATE': {'code': 'KEY_ESC'},
278+
'PS5_OPTION': {'code': 'KEY_ESC'}
279+
}
280+
240281
XBOX_DEFAULT_MAPPING = {
241282
# buttons to buttons
242283
'BTN_A': {'code':'IBM_GGP_BTN_1'},
@@ -284,10 +325,14 @@ def translate_dict(old_mapping_dict, lookup_dict):
284325

285326
def find_keycode_in_mapping(source_code, mapping_dict, usb_gamepad_type):
286327
map_dict_copy = dict(mapping_dict)
287-
if usb_gamepad_type == 'PlayStation' and map_dict_copy.get("IS_DEFAULT", False):
328+
if usb_gamepad_type == 'PlayStation' and map_dict_copy.get("MAPPING_TYPE") == "DEFAULT_15PIN":
288329
map_dict_copy = PLAYSTATION_DEAULT_MAPPING
289-
if usb_gamepad_type == 'Xbox' and map_dict_copy.get("IS_DEFAULT", False):
330+
elif usb_gamepad_type == 'Xbox' and map_dict_copy.get("MAPPING_TYPE") == "DEFAULT_15PIN":
290331
map_dict_copy = XBOX_DEFAULT_MAPPING
332+
elif usb_gamepad_type == 'PlayStation' and map_dict_copy.get("MAPPING_TYPE") == "DEFAULT_MOUSE_KB":
333+
map_dict_copy = PLAYSTATION_DEFAULT_KB_MOUSE_MAPPING
334+
elif usb_gamepad_type == 'Xbox' and map_dict_copy.get("MAPPING_TYPE") == "DEFAULT_MOUSE_KB":
335+
map_dict_copy = XBOX_DEFAULT_KB_MOUSE_MAPPING
291336
source_name = usb4vc_shared.code_value_to_name_lookup.get(source_code)
292337
if source_name is None:
293338
return None, None
@@ -363,11 +408,13 @@ def make_generic_gamepad_spi_packet(gp_status_dict, gp_id, this_device_info, map
363408
global prev_kb_output
364409
global curr_mouse_output
365410
axes_info = this_device_info['axes_info']
366-
this_gamepad_name = this_device_info.get('name', '').lower()
411+
this_gamepad_name = this_device_info.get('name', '').lower().strip()
367412
usb_gamepad_type = 'Generic USB'
368413
if 'xbox' in this_gamepad_name or 'x-box' in this_gamepad_name:
369414
usb_gamepad_type = 'Xbox'
370-
elif 'wireless controller' in this_gamepad_name:
415+
elif 'sony' in this_gamepad_name and 'wireless controller' in this_gamepad_name:
416+
usb_gamepad_type = 'PlayStation'
417+
elif this_gamepad_name == 'wireless controller':
371418
usb_gamepad_type = 'PlayStation'
372419

373420
this_gp_dict = gp_status_dict[gp_id]

0 commit comments

Comments
 (0)