mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
corrently handle spi protocol switch with custom profiles
This commit is contained in:
@@ -68,21 +68,21 @@ PROTOCOL_RAW_KEYBOARD = {'pid':125, 'display_name':"Raw data", 'is_custom':0}
|
||||
PROTOCOL_RAW_MOUSE = {'pid':126, 'display_name':"Raw data", 'is_custom':0}
|
||||
PROTOCOL_RAW_GAMEPAD = {'pid':127, 'display_name':"Raw data", 'is_custom':0}
|
||||
|
||||
BTN_SOUTH = 0x130
|
||||
BTN_EAST = 0x131
|
||||
BTN_C = 0x132
|
||||
BTN_NORTH = 0x133
|
||||
BTN_WEST = 0x134
|
||||
BTN_Z = 0x135
|
||||
BTN_TL = 0x136
|
||||
BTN_TR = 0x137
|
||||
BTN_TL2 = 0x138
|
||||
BTN_TR2 = 0x139
|
||||
BTN_SELECT = 0x13a
|
||||
BTN_START = 0x13b
|
||||
BTN_MODE = 0x13c
|
||||
BTN_THUMBL = 0x13d
|
||||
BTN_THUMBR = 0x13e
|
||||
GP_BTN_SOUTH = 0x130
|
||||
GP_BTN_EAST = 0x131
|
||||
GP_BTN_C = 0x132
|
||||
GP_BTN_NORTH = 0x133
|
||||
GP_BTN_WEST = 0x134
|
||||
GP_BTN_Z = 0x135
|
||||
GP_BTN_TL = 0x136
|
||||
GP_BTN_TR = 0x137
|
||||
GP_BTN_TL2 = 0x138
|
||||
GP_BTN_TR2 = 0x139
|
||||
GP_BTN_SELECT = 0x13a
|
||||
GP_BTN_START = 0x13b
|
||||
GP_BTN_MODE = 0x13c
|
||||
GP_BTN_THUMBL = 0x13d
|
||||
GP_BTN_THUMBR = 0x13e
|
||||
|
||||
IBMPC_GGP_BUTTON_1 = 1
|
||||
IBMPC_GGP_BUTTON_2 = 2
|
||||
@@ -104,12 +104,12 @@ custom_profile_1 = {
|
||||
'pid':PROTOCOL_GENERIC_GAMEPORT_GAMEPAD['pid'],
|
||||
'mapping':
|
||||
{
|
||||
BTN_SOUTH: IBMPC_GGP_BUTTON_1,
|
||||
BTN_EAST: IBMPC_GGP_BUTTON_2,
|
||||
BTN_WEST: IBMPC_GGP_BUTTON_3,
|
||||
BTN_NORTH: IBMPC_GGP_BUTTON_4,
|
||||
BTN_TL: IBMPC_GGP_BUTTON_1,
|
||||
BTN_TR2: IBMPC_GGP_BUTTON_2,
|
||||
GP_BTN_SOUTH: IBMPC_GGP_BUTTON_1,
|
||||
GP_BTN_EAST: IBMPC_GGP_BUTTON_2,
|
||||
GP_BTN_WEST: IBMPC_GGP_BUTTON_3,
|
||||
GP_BTN_NORTH: IBMPC_GGP_BUTTON_4,
|
||||
GP_BTN_TL: IBMPC_GGP_BUTTON_1,
|
||||
GP_BTN_TR2: IBMPC_GGP_BUTTON_2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,12 +120,12 @@ custom_profile_2 = {
|
||||
'pid':PROTOCOL_GENERIC_GAMEPORT_GAMEPAD['pid'],
|
||||
'mapping':
|
||||
{
|
||||
BTN_SOUTH: IBMPC_GGP_BUTTON_1,
|
||||
BTN_EAST: IBMPC_GGP_BUTTON_1,
|
||||
BTN_WEST: IBMPC_GGP_BUTTON_1,
|
||||
BTN_NORTH: IBMPC_GGP_BUTTON_1,
|
||||
BTN_TL: IBMPC_GGP_BUTTON_1,
|
||||
BTN_TR2: IBMPC_GGP_BUTTON_1,
|
||||
GP_BTN_SOUTH: IBMPC_GGP_BUTTON_1,
|
||||
GP_BTN_EAST: IBMPC_GGP_BUTTON_1,
|
||||
GP_BTN_WEST: IBMPC_GGP_BUTTON_1,
|
||||
GP_BTN_NORTH: IBMPC_GGP_BUTTON_1,
|
||||
GP_BTN_TL: IBMPC_GGP_BUTTON_1,
|
||||
GP_BTN_TR2: IBMPC_GGP_BUTTON_1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,17 +169,17 @@ def oled_print_centered(text, font, y, this_canvas):
|
||||
start_x = 0
|
||||
this_canvas.text((start_x, y), text, font=font, fill="white")
|
||||
|
||||
keyboard_protocol_options_ibmpc = [PROTOCOL_AT_PS2_KB, PROTOCOL_XT_KB, PROTOCOL_OFF]
|
||||
mouse_protocol_options_ibmpc = [PROTOCOL_PS2_MOUSE, PROTOCOL_MICROSOFT_SERIAL_MOUSE, PROTOCOL_OFF]
|
||||
gamepad_protocol_options_ibmpc = [PROTOCOL_GENERIC_GAMEPORT_GAMEPAD, PROTOCOL_GAMEPORT_GRAVIS_GAMEPAD, PROTOCOL_GAMEPORT_MICROSOFT_SIDEWINDER, PROTOCOL_OFF]
|
||||
keyboard_protocol_options_ibmpc = [PROTOCOL_OFF, PROTOCOL_AT_PS2_KB, PROTOCOL_XT_KB]
|
||||
mouse_protocol_options_ibmpc = [PROTOCOL_OFF, PROTOCOL_PS2_MOUSE, PROTOCOL_MICROSOFT_SERIAL_MOUSE]
|
||||
gamepad_protocol_options_ibmpc = [PROTOCOL_OFF, PROTOCOL_GENERIC_GAMEPORT_GAMEPAD, PROTOCOL_GAMEPORT_GRAVIS_GAMEPAD, PROTOCOL_GAMEPORT_MICROSOFT_SIDEWINDER]
|
||||
|
||||
keyboard_protocol_options_adb = [PROTOCOL_ADB_KB, PROTOCOL_OFF]
|
||||
mouse_protocol_options_adb = [PROTOCOL_ADB_MOUSE, PROTOCOL_OFF]
|
||||
keyboard_protocol_options_adb = [PROTOCOL_OFF, PROTOCOL_ADB_KB]
|
||||
mouse_protocol_options_adb = [PROTOCOL_OFF, PROTOCOL_ADB_MOUSE]
|
||||
gamepad_protocol_options_adb = [PROTOCOL_OFF]
|
||||
|
||||
keyboard_protocol_options_raw = [PROTOCOL_RAW_KEYBOARD, PROTOCOL_OFF]
|
||||
mouse_protocol_options_raw = [PROTOCOL_RAW_MOUSE, PROTOCOL_OFF]
|
||||
gamepad_protocol_options_raw = [PROTOCOL_RAW_GAMEPAD, PROTOCOL_OFF]
|
||||
keyboard_protocol_options_raw = [PROTOCOL_OFF, PROTOCOL_RAW_KEYBOARD]
|
||||
mouse_protocol_options_raw = [PROTOCOL_OFF, PROTOCOL_RAW_MOUSE]
|
||||
gamepad_protocol_options_raw = [PROTOCOL_OFF, PROTOCOL_RAW_GAMEPAD]
|
||||
|
||||
mouse_sensitivity_list = [1, 1.25, 1.5, 1.75, 0.25, 0.5, 0.75]
|
||||
|
||||
@@ -295,16 +295,22 @@ class usb4vc_menu(object):
|
||||
def send_spi(self):
|
||||
status_dict = {}
|
||||
for index, item in enumerate(self.kb_opts):
|
||||
if item['pid'] & 0x7f in status_dict and status_dict[item['pid'] & 0x7f] == 1:
|
||||
continue
|
||||
status_dict[item['pid'] & 0x7f] = 0
|
||||
if index == self.current_keyboard_protocol_index:
|
||||
status_dict[item['pid'] & 0x7f] = 1
|
||||
|
||||
for index, item in enumerate(self.mouse_opts):
|
||||
if item['pid'] & 0x7f in status_dict and status_dict[item['pid'] & 0x7f] == 1:
|
||||
continue
|
||||
status_dict[item['pid'] & 0x7f] = 0
|
||||
if index == self.current_mouse_protocol_index:
|
||||
status_dict[item['pid'] & 0x7f] = 1
|
||||
|
||||
for index, item in enumerate(self.gamepad_opts):
|
||||
if item['pid'] & 0x7f in status_dict and status_dict[item['pid'] & 0x7f] == 1:
|
||||
continue
|
||||
status_dict[item['pid'] & 0x7f] = 0
|
||||
if index == self.current_gamepad_protocol_index:
|
||||
status_dict[item['pid'] & 0x7f] = 1
|
||||
@@ -321,6 +327,12 @@ class usb4vc_menu(object):
|
||||
this_msg = list(usb4vc_shared.set_protocl_spi_msg_template)
|
||||
this_msg[3:3+len(protocol_bytes)] = protocol_bytes
|
||||
|
||||
self.current_keyboard_protocol = self.kb_opts[self.current_keyboard_protocol_index]
|
||||
self.current_mouse_protocol = self.mouse_opts[self.current_mouse_protocol_index]
|
||||
self.current_gamepad_protocol = self.gamepad_opts[self.current_gamepad_protocol_index]
|
||||
|
||||
print('this', this_msg)
|
||||
print('last', self.last_spi_message)
|
||||
if this_msg == self.last_spi_message:
|
||||
print("SPI: no need to send")
|
||||
return
|
||||
@@ -328,9 +340,6 @@ class usb4vc_menu(object):
|
||||
usb4vc_usb_scan.set_protocol(this_msg)
|
||||
print('new status:', [hex(x) for x in usb4vc_usb_scan.get_pboard_info()])
|
||||
self.last_spi_message = list(this_msg)
|
||||
self.current_keyboard_protocol = self.kb_opts[self.current_keyboard_protocol_index]
|
||||
self.current_mouse_protocol = self.mouse_opts[self.current_mouse_protocol_index]
|
||||
self.current_gamepad_protocol = self.gamepad_opts[self.current_gamepad_protocol_index]
|
||||
|
||||
def action(self, level, page):
|
||||
if level == 0:
|
||||
@@ -405,7 +414,7 @@ def ui_init():
|
||||
if 'rpi_app_ver' not in configuration_dict:
|
||||
configuration_dict['rpi_app_ver'] = usb4vc_shared.RPI_APP_VERSION_TUPLE
|
||||
if this_pboard_id not in configuration_dict:
|
||||
configuration_dict[this_pboard_id] = {"keyboard_protocol_index":0, "mouse_protocol_index":0, "mouse_sensitivity_index":0, "gamepad_protocol_index":0}
|
||||
configuration_dict[this_pboard_id] = {"keyboard_protocol_index":1, "mouse_protocol_index":1, "mouse_sensitivity_index":0, "gamepad_protocol_index":1}
|
||||
|
||||
plus_button = my_button(PLUS_BUTTON_PIN)
|
||||
minus_button = my_button(MINUS_BUTTON_PIN)
|
||||
|
||||
@@ -162,34 +162,35 @@ def make_mouse_spi_packet(mouse_dict, mouse_id):
|
||||
to_transfer[17] = dict_get_if_exist(mouse_dict, BTN_EXTRA)
|
||||
return to_transfer
|
||||
|
||||
PID_GENERIC_GAMEPORT_GAMEPAD = 7
|
||||
|
||||
def make_gamepad_spi_packet(gp_status_dict, gp_id, axes_info):
|
||||
# do the mapping here
|
||||
print(usb4vc_ui.get_gamepad_protocol())
|
||||
current_gamepad_protocol = usb4vc_ui.get_gamepad_protocol()
|
||||
if current_gamepad_protocol['pid'] == PID_GENERIC_GAMEPORT_GAMEPAD:
|
||||
result = list(gamepad_event_mapped_spi_msg_template)
|
||||
result[3] = gp_id;
|
||||
result[4] = dict_get_if_exist(gp_status_dict[gp_id], GP_BTN_SOUTH)
|
||||
result[5] = dict_get_if_exist(gp_status_dict[gp_id], GP_BTN_EAST)
|
||||
result[6] = dict_get_if_exist(gp_status_dict[gp_id], GP_BTN_WEST)
|
||||
result[7] = dict_get_if_exist(gp_status_dict[gp_id], GP_BTN_NORTH)
|
||||
|
||||
result = list(gamepad_event_mapped_spi_msg_template)
|
||||
result[8] = dict_get_if_exist(gp_status_dict[gp_id], ABS_X)
|
||||
if ABS_X in axes_info and 'max' in axes_info[ABS_X]:
|
||||
result[8] = int(result[8] / (axes_info[ABS_X]['max'] / 127)) + 127
|
||||
|
||||
result[3] = gp_id;
|
||||
result[4] = dict_get_if_exist(gp_status_dict[gp_id], GP_BTN_SOUTH)
|
||||
result[5] = dict_get_if_exist(gp_status_dict[gp_id], GP_BTN_EAST)
|
||||
result[6] = dict_get_if_exist(gp_status_dict[gp_id], GP_BTN_WEST)
|
||||
result[7] = dict_get_if_exist(gp_status_dict[gp_id], GP_BTN_NORTH)
|
||||
result[9] = dict_get_if_exist(gp_status_dict[gp_id], ABS_Y)
|
||||
if ABS_Y in axes_info and 'max' in axes_info[ABS_Y]:
|
||||
result[9] = int(result[9] / (axes_info[ABS_Y]['max'] / 127)) + 127
|
||||
|
||||
result[8] = dict_get_if_exist(gp_status_dict[gp_id], ABS_X)
|
||||
if ABS_X in axes_info and 'max' in axes_info[ABS_X]:
|
||||
result[8] = int(result[8] / (axes_info[ABS_X]['max'] / 127)) + 127
|
||||
result[10] = dict_get_if_exist(gp_status_dict[gp_id], ABS_RX)
|
||||
if ABS_RX in axes_info and 'max' in axes_info[ABS_RX]:
|
||||
result[10] = int(result[10] / (axes_info[ABS_RX]['max'] / 127)) + 127
|
||||
|
||||
result[9] = dict_get_if_exist(gp_status_dict[gp_id], ABS_Y)
|
||||
if ABS_Y in axes_info and 'max' in axes_info[ABS_Y]:
|
||||
result[9] = int(result[9] / (axes_info[ABS_Y]['max'] / 127)) + 127
|
||||
|
||||
result[10] = dict_get_if_exist(gp_status_dict[gp_id], ABS_RX)
|
||||
if ABS_RX in axes_info and 'max' in axes_info[ABS_RX]:
|
||||
result[10] = int(result[10] / (axes_info[ABS_RX]['max'] / 127)) + 127
|
||||
|
||||
result[11] = dict_get_if_exist(gp_status_dict[gp_id], ABS_RY)
|
||||
if ABS_RY in axes_info and 'max' in axes_info[ABS_RY]:
|
||||
result[11] = int(result[11] / (axes_info[ABS_RY]['max'] / 127)) + 127
|
||||
return result
|
||||
result[11] = dict_get_if_exist(gp_status_dict[gp_id], ABS_RY)
|
||||
if ABS_RY in axes_info and 'max' in axes_info[ABS_RY]:
|
||||
result[11] = int(result[11] / (axes_info[ABS_RY]['max'] / 127)) + 127
|
||||
return result
|
||||
return list(nop_spi_msg_template)
|
||||
|
||||
def change_kb_led(scrolllock, numlock, capslock):
|
||||
led_file_list = os.listdir(led_device_path)
|
||||
|
||||
Reference in New Issue
Block a user