mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
updated code to be compatiable with configurator
This commit is contained in:
@@ -2,7 +2,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import usb4vc_shared
|
|
||||||
import usb4vc_usb_scan
|
import usb4vc_usb_scan
|
||||||
import usb4vc_ui
|
import usb4vc_ui
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ code_value_to_name_lookup = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
board_id_lookup = {
|
board_id_lookup = {
|
||||||
|
'Unknown':0,
|
||||||
'IBMPC':1,
|
'IBMPC':1,
|
||||||
'ADB':2,
|
'ADB':2,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ PROTOCOL_PS2_MOUSE = {'pid':4, 'display_name':"PS/2"}
|
|||||||
PROTOCOL_MICROSOFT_SERIAL_MOUSE = {'pid':5, 'display_name':"Microsft Serial"}
|
PROTOCOL_MICROSOFT_SERIAL_MOUSE = {'pid':5, 'display_name':"Microsft Serial"}
|
||||||
PROTOCOL_ADB_MOUSE = {'pid':6, 'display_name':"ADB"}
|
PROTOCOL_ADB_MOUSE = {'pid':6, 'display_name':"ADB"}
|
||||||
PROTOCOL_15PIN_GAMEPORT_GAMEPAD = {'pid':7, 'display_name':"Generic 15-Pin", 'mapping':IBM_GGP_DEAULT_MAPPING}
|
PROTOCOL_15PIN_GAMEPORT_GAMEPAD = {'pid':7, 'display_name':"Generic 15-Pin", 'mapping':IBM_GGP_DEAULT_MAPPING}
|
||||||
PROTOCOL_GAMEPORT_GRAVIS_GAMEPAD = {'pid':8, 'display_name':"Gravis Pro"}
|
# PROTOCOL_GAMEPORT_GRAVIS_GAMEPAD = {'pid':8, 'display_name':"Gravis Pro"}
|
||||||
PROTOCOL_GAMEPORT_MICROSOFT_SIDEWINDER = {'pid':9, 'display_name':"MS Sidewinder"}
|
# PROTOCOL_GAMEPORT_MICROSOFT_SIDEWINDER = {'pid':9, 'display_name':"MS Sidewinder"}
|
||||||
PROTOCOL_RAW_KEYBOARD = {'pid':125, 'display_name':"Raw data"}
|
PROTOCOL_RAW_KEYBOARD = {'pid':125, 'display_name':"Raw data"}
|
||||||
PROTOCOL_RAW_MOUSE = {'pid':126, 'display_name':"Raw data"}
|
PROTOCOL_RAW_MOUSE = {'pid':126, 'display_name':"Raw data"}
|
||||||
PROTOCOL_RAW_GAMEPAD = {'pid':127, 'display_name':"Raw data"}
|
PROTOCOL_RAW_GAMEPAD = {'pid':127, 'display_name':"Raw data"}
|
||||||
@@ -696,8 +696,6 @@ class usb4vc_menu(object):
|
|||||||
self.current_mouse_protocol = self.mouse_protocol_list[self.current_mouse_protocol_index]
|
self.current_mouse_protocol = self.mouse_protocol_list[self.current_mouse_protocol_index]
|
||||||
self.current_gamepad_protocol = self.gamepad_protocol_list[self.current_gamepad_protocol_index]
|
self.current_gamepad_protocol = self.gamepad_protocol_list[self.current_gamepad_protocol_index]
|
||||||
|
|
||||||
# print('this', this_msg)
|
|
||||||
# print('last', self.last_spi_message)
|
|
||||||
if this_msg == self.last_spi_message:
|
if this_msg == self.last_spi_message:
|
||||||
print("SPI: no need to send")
|
print("SPI: no need to send")
|
||||||
return
|
return
|
||||||
@@ -853,8 +851,8 @@ def ui_init():
|
|||||||
this_mapping_bid = usb4vc_shared.board_id_lookup.get(item['protocol_board'], 0)
|
this_mapping_bid = usb4vc_shared.board_id_lookup.get(item['protocol_board'], 0)
|
||||||
if this_mapping_bid == this_pboard_id and item['device_type'] in pboard_database[this_pboard_id]:
|
if this_mapping_bid == this_pboard_id and item['device_type'] in pboard_database[this_pboard_id]:
|
||||||
this_mapping_pid = usb4vc_shared.protocol_id_lookup.get(item['protocol_name'])
|
this_mapping_pid = usb4vc_shared.protocol_id_lookup.get(item['protocol_name'])
|
||||||
this_profile = {'pid':this_mapping_pid, 'display_name':item['display_name'], 'mapping':item['mapping']}
|
item['pid'] = this_mapping_pid
|
||||||
pboard_database[this_pboard_id][item['device_type']].append(this_profile)
|
pboard_database[this_pboard_id][item['device_type']].append(item)
|
||||||
pboard_database[this_pboard_id]['hw_rev'] = pboard_info_spi_msg[4]
|
pboard_database[this_pboard_id]['hw_rev'] = pboard_info_spi_msg[4]
|
||||||
pboard_database[this_pboard_id]['fw_ver'] = (pboard_info_spi_msg[5], pboard_info_spi_msg[6], pboard_info_spi_msg[7])
|
pboard_database[this_pboard_id]['fw_ver'] = (pboard_info_spi_msg[5], pboard_info_spi_msg[6], pboard_info_spi_msg[7])
|
||||||
if 'rpi_app_ver' not in configuration_dict:
|
if 'rpi_app_ver' not in configuration_dict:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import math
|
||||||
import spidev
|
import spidev
|
||||||
import evdev
|
import evdev
|
||||||
import threading
|
import threading
|
||||||
@@ -8,7 +9,6 @@ import RPi.GPIO as GPIO
|
|||||||
import usb4vc_ui
|
import usb4vc_ui
|
||||||
import usb4vc_shared
|
import usb4vc_shared
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
sudo apt install stm32flash
|
sudo apt install stm32flash
|
||||||
|
|
||||||
@@ -175,10 +175,68 @@ MOUSE_SPI_LOOKUP = {
|
|||||||
REL_WHEEL:8,
|
REL_WHEEL:8,
|
||||||
}
|
}
|
||||||
|
|
||||||
def find_keycode_in_mapping(source_code, mapping_dict):
|
xbox_one_bluetooth_to_linux_ev_code_dict = {
|
||||||
|
"XB1_A":"BTN_SOUTH",
|
||||||
|
"XB1_B":"BTN_EAST",
|
||||||
|
"XB1_X":"BTN_NORTH",
|
||||||
|
"XB1_Y":"BTN_WEST",
|
||||||
|
"XB1_LSB":"BTN_THUMBL",
|
||||||
|
"XB1_RSB":"BTN_THUMBR",
|
||||||
|
"XB1_LB":"BTN_TL",
|
||||||
|
"XB1_RB":"BTN_TR",
|
||||||
|
"XB1_VIEW":"KEY_BACK",
|
||||||
|
"XB1_MENU":"BTN_START",
|
||||||
|
"XB1_LOGO":"KEY_HOMEPAGE",
|
||||||
|
"XB1_LSX":"ABS_X",
|
||||||
|
"XB1_LSY":"ABS_Y",
|
||||||
|
"XB1_RSX":"ABS_Z",
|
||||||
|
"XB1_RSY":"ABS_RZ",
|
||||||
|
"XB1_LT":"ABS_BRAKE",
|
||||||
|
"XB1_RT":"ABS_GAS",
|
||||||
|
"XB1_DPX":"ABS_HAT0X",
|
||||||
|
"XB1_DPY":"ABS_HAT0Y",
|
||||||
|
}
|
||||||
|
|
||||||
|
xbox_one_wired_to_linux_ev_code_dict = {
|
||||||
|
"XB1_A":"BTN_SOUTH",
|
||||||
|
"XB1_B":"BTN_EAST",
|
||||||
|
"XB1_X":"BTN_NORTH",
|
||||||
|
"XB1_Y":"BTN_WEST",
|
||||||
|
"XB1_LSB":"BTN_THUMBL",
|
||||||
|
"XB1_RSB":"BTN_THUMBR",
|
||||||
|
"XB1_LB":"BTN_TL",
|
||||||
|
"XB1_RB":"BTN_TR",
|
||||||
|
"XB1_VIEW":"BTN_SELECT",
|
||||||
|
"XB1_MENU":"BTN_START",
|
||||||
|
"XB1_LOGO":"BTN_MODE",
|
||||||
|
"XB1_LSX":"ABS_X",
|
||||||
|
"XB1_LSY":"ABS_Y",
|
||||||
|
"XB1_RSX":"ABS_RX",
|
||||||
|
"XB1_RSY":"ABS_RY",
|
||||||
|
"XB1_LT":"ABS_Z",
|
||||||
|
"XB1_RT":"ABS_RZ",
|
||||||
|
"XB1_DPX":"ABS_HAT0X",
|
||||||
|
"XB1_DPY":"ABS_HAT0Y",
|
||||||
|
}
|
||||||
|
|
||||||
|
def translate_dict(old_mapping_dict, lookup_dict):
|
||||||
|
translated_map_dict = {}
|
||||||
|
for key in old_mapping_dict:
|
||||||
|
lookup_result = lookup_dict.get(key)
|
||||||
|
if lookup_result is not None:
|
||||||
|
translated_map_dict[lookup_result] = old_mapping_dict[key]
|
||||||
|
return translated_map_dict
|
||||||
|
|
||||||
|
def find_keycode_in_mapping(source_code, mapping_dict, usb_gamepad_type):
|
||||||
source_name = usb4vc_shared.code_value_to_name_lookup.get(source_code)
|
source_name = usb4vc_shared.code_value_to_name_lookup.get(source_code)
|
||||||
if source_name is None:
|
if source_name is None:
|
||||||
return None, None
|
return None, None
|
||||||
|
translated_map_dict = {}
|
||||||
|
if usb_gamepad_type == "Xbox One Bluetooth":
|
||||||
|
mapping_dict = translate_dict(mapping_dict, xbox_one_bluetooth_to_linux_ev_code_dict)
|
||||||
|
elif usb_gamepad_type == "Xbox One Wired":
|
||||||
|
mapping_dict = translate_dict(mapping_dict, xbox_one_wired_to_linux_ev_code_dict)
|
||||||
|
|
||||||
target_info = None
|
target_info = None
|
||||||
for item in source_name:
|
for item in source_name:
|
||||||
if item in mapping_dict:
|
if item in mapping_dict:
|
||||||
@@ -186,6 +244,8 @@ def find_keycode_in_mapping(source_code, mapping_dict):
|
|||||||
if target_info is None or 'code' not in target_info:
|
if target_info is None or 'code' not in target_info:
|
||||||
return None, None
|
return None, None
|
||||||
target_info = dict(target_info) # make a copy so the lookup table itself won't get modified
|
target_info = dict(target_info) # make a copy so the lookup table itself won't get modified
|
||||||
|
# print(target_info['code'])
|
||||||
|
# print('---///////////////---')
|
||||||
lookup_result = usb4vc_shared.code_name_to_value_lookup.get(target_info['code'])
|
lookup_result = usb4vc_shared.code_name_to_value_lookup.get(target_info['code'])
|
||||||
if lookup_result is None:
|
if lookup_result is None:
|
||||||
return None, None
|
return None, None
|
||||||
@@ -212,15 +272,6 @@ def find_furthest_from_midpoint(this_set):
|
|||||||
curr_best = item
|
curr_best = item
|
||||||
return curr_best
|
return curr_best
|
||||||
|
|
||||||
import math
|
|
||||||
|
|
||||||
def my_fade(value):
|
|
||||||
if 0 < value < 1:
|
|
||||||
return -1 * value + 1
|
|
||||||
if 1 <= value < 2:
|
|
||||||
return value - 1
|
|
||||||
return 1
|
|
||||||
|
|
||||||
def apply_curve(x_0_255, y_0_255):
|
def apply_curve(x_0_255, y_0_255):
|
||||||
x_neg127_127 = x_0_255 - 127
|
x_neg127_127 = x_0_255 - 127
|
||||||
y_neg127_127 = y_0_255 - 127
|
y_neg127_127 = y_0_255 - 127
|
||||||
@@ -270,7 +321,8 @@ def make_generic_gamepad_spi_packet(gp_status_dict, gp_id, axes_info, mapping_in
|
|||||||
REL_WHEEL:0,
|
REL_WHEEL:0,
|
||||||
}
|
}
|
||||||
for source_code in this_gp_dict:
|
for source_code in this_gp_dict:
|
||||||
source_type, target_info = find_keycode_in_mapping(source_code, mapping_info['mapping'])
|
usb_gamepad_type = mapping_info.get('usb_gamepad_type', 'Generic USB')
|
||||||
|
source_type, target_info = find_keycode_in_mapping(source_code, mapping_info['mapping'], usb_gamepad_type)
|
||||||
if target_info is None:
|
if target_info is None:
|
||||||
continue
|
continue
|
||||||
target_code = target_info['code']
|
target_code = target_info['code']
|
||||||
|
|||||||
Reference in New Issue
Block a user