improved unsupported gamepad detection

This commit is contained in:
dekunukem
2022-04-26 17:58:58 +01:00
parent d6f53d3ec5
commit ce3806fbd9
3 changed files with 129 additions and 6 deletions

View File

@@ -3,10 +3,10 @@
# sh sync.sh; ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 usb4vc_main.py"
scp ./* pi@169.254.194.124:~/usb4vc/rpi_app
# ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 usb4vc_main.py"
ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 usb4vc_main.py"
# ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 usb4vc_check_update.py"
ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 firmware_flasher.py /home/pi/usb4vc/firmware/PBFW_IBMPC_PBID1_V0_1_5.hex /home/pi/usb4vc/firmware/ibmpc_test.hex"
# ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 firmware_flasher.py /home/pi/usb4vc/firmware/PBFW_IBMPC_PBID1_V0_1_5.hex /home/pi/usb4vc/firmware/ibmpc_test.hex"
# ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 bb_tester.py"
# pi@169.254.245.21 bb_tester

View File

@@ -355,3 +355,111 @@ protocol_id_lookup = {
'RAW_MOUSE':126,
'RAW_GAMEPAD':127,
}
gamepad_event_code_name_list = [
"BTN_JOYSTICK",
"BTN_TRIGGER",
"BTN_THUMB",
"BTN_THUMB2",
"BTN_TOP",
"BTN_TOP2",
"BTN_PINKIE",
"BTN_BASE",
"BTN_BASE2",
"BTN_BASE3",
"BTN_BASE4",
"BTN_BASE5",
"BTN_BASE6",
"BTN_DEAD",
"BTN_GAMEPAD",
"BTN_SOUTH",
"BTN_A",
"BTN_SOUTH",
"BTN_EAST",
"BTN_B",
"BTN_EAST",
"BTN_C",
"BTN_NORTH",
"BTN_X",
"BTN_NORTH",
"BTN_WEST",
"BTN_Y",
"BTN_WEST",
"BTN_Z",
"BTN_TL",
"BTN_TR",
"BTN_TL2",
"BTN_TR2",
"BTN_SELECT",
"BTN_START",
"BTN_MODE",
"BTN_THUMBL",
"BTN_THUMBR",
"BTN_WHEEL",
"BTN_GEAR_DOWN",
"BTN_GEAR_UP",
"BTN_DPAD_UP",
"BTN_DPAD_DOWN",
"BTN_DPAD_LEFT",
"BTN_DPAD_RIGHT",
"BTN_TRIGGER_HAPPY",
"BTN_TRIGGER_HAPPY1",
"BTN_TRIGGER_HAPPY2",
"BTN_TRIGGER_HAPPY3",
"BTN_TRIGGER_HAPPY4",
"BTN_TRIGGER_HAPPY5",
"BTN_TRIGGER_HAPPY6",
"BTN_TRIGGER_HAPPY7",
"BTN_TRIGGER_HAPPY8",
"BTN_TRIGGER_HAPPY9",
"BTN_TRIGGER_HAPPY10",
"BTN_TRIGGER_HAPPY11",
"BTN_TRIGGER_HAPPY12",
"BTN_TRIGGER_HAPPY13",
"BTN_TRIGGER_HAPPY14",
"BTN_TRIGGER_HAPPY15",
"BTN_TRIGGER_HAPPY16",
"BTN_TRIGGER_HAPPY17",
"BTN_TRIGGER_HAPPY18",
"BTN_TRIGGER_HAPPY19",
"BTN_TRIGGER_HAPPY20",
"BTN_TRIGGER_HAPPY21",
"BTN_TRIGGER_HAPPY22",
"BTN_TRIGGER_HAPPY23",
"BTN_TRIGGER_HAPPY24",
"BTN_TRIGGER_HAPPY25",
"BTN_TRIGGER_HAPPY26",
"BTN_TRIGGER_HAPPY27",
"BTN_TRIGGER_HAPPY28",
"BTN_TRIGGER_HAPPY29",
"BTN_TRIGGER_HAPPY30",
"BTN_TRIGGER_HAPPY31",
"BTN_TRIGGER_HAPPY32",
"BTN_TRIGGER_HAPPY33",
"BTN_TRIGGER_HAPPY34",
"BTN_TRIGGER_HAPPY35",
"BTN_TRIGGER_HAPPY36",
"BTN_TRIGGER_HAPPY37",
"BTN_TRIGGER_HAPPY38",
"BTN_TRIGGER_HAPPY39",
"BTN_TRIGGER_HAPPY40",
"ABS_X",
"ABS_Y",
"ABS_Z",
"ABS_RX",
"ABS_RY",
"ABS_RZ",
"ABS_THROTTLE",
"ABS_RUDDER",
"ABS_WHEEL",
"ABS_GAS",
"ABS_BRAKE",
"ABS_HAT0X",
"ABS_HAT0Y",
"ABS_HAT1X",
"ABS_HAT1Y",
"ABS_HAT2X",
"ABS_HAT2Y",
"ABS_HAT3X",
"ABS_HAT3Y",
"KEY_MODE"]

View File

@@ -828,6 +828,21 @@ def raw_input_event_worker():
except Exception as e:
print('exception change_kb_led:', e)
def check_is_gamepad(capability_dict):
keys_and_buttons = capability_dict.get(('EV_KEY', 1))
if keys_and_buttons is None:
return False
key_name_set = set()
for item in [x[0] for x in keys_and_buttons]:
if isinstance(item, str):
key_name_set.add(item)
if isinstance(item, list):
key_name_set.update(item)
for item in usb4vc_shared.gamepad_event_code_name_list:
if item in key_name_set:
return True
return False
def get_input_devices():
result = []
available_devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
@@ -845,14 +860,13 @@ def get_input_devices():
'is_mouse':False,
'is_gp':False,
}
cap_str = str(this_device.capabilities(verbose=True))
this_cap = this_device.capabilities(verbose=True)
cap_str = str(this_cap)
if 'BTN_LEFT' in cap_str and "EV_REL" in cap_str:
dev_dict['is_mouse'] = True
if 'KEY_ENTER' in cap_str and "KEY_Y" in cap_str:
dev_dict['is_kb'] = True
if 'KEY_MODE' in cap_str:
dev_dict['is_gp'] = True
if 'EV_ABS' in cap_str and "BTN_SOUTH" in cap_str:
if check_is_gamepad(this_cap):
dev_dict['is_gp'] = True
try:
for item in this_device.capabilities()[EV_ABS]:
@@ -882,6 +896,7 @@ def usb_device_scan_worker():
time.sleep(0.75)
try:
device_list = get_input_devices()
print(device_list)
except Exception as e:
print('exception get_input_devices:', e)
continue