mouse axes and button mapping working

This commit is contained in:
dekunukem
2021-12-26 20:29:02 +00:00
parent d8c983063c
commit 3c1b5ef7a7
4 changed files with 106 additions and 53 deletions

View File

@@ -1,3 +1,38 @@
# print(time.time(), '-----------')
# print('=====>',from_code, from_type, to_code, to_type)
# print('kb', curr_kb_output)
# print('prev', prev_gp_output)
# print('curr', curr_gp_output)
print("mouse", curr_mouse_output)
rawx = int.from_bytes(data[4:6], byteorder='little', signed=True)
rawx = int(rawx * usb4vc_ui.get_mouse_sensitivity()) & 0xffff
mouse_status_dict["x"] = list(rawx.to_bytes(2, byteorder='little'))
'mapping':
{
# buttons to buttons
USBGP_BTN_X: IBMPC_GGP_JS1_X_NEG,
USBGP_BTN_B: IBMPC_GGP_JS1_X_POS,
USBGP_BTN_Y: IBMPC_GGP_JS1_Y_POS,
USBGP_BTN_A: IBMPC_GGP_JS1_Y_NEG,
# analog stick to analog stick
USBGP_ABS_X: IBMPC_GGP_JS1_X,
USBGP_ABS_Y: IBMPC_GGP_JS1_Y,
USBGP_ABS_HAT0X: IBMPC_GGP_JS1_X,
USBGP_ABS_HAT0Y: IBMPC_GGP_JS1_Y,
# buttons to analog stick
USBGP_BTN_TL: IBMPC_GGP_BTN_1,
USBGP_BTN_TR: IBMPC_GGP_BTN_2,
# buttons to keyboard key
USBGP_BTN_START: KB_KEY_A,
USBGP_BTN_SELECT: KB_KEY_B,
USBGP_BTN_TL: IBMPC_GGP_JS1_X_NEG,
USBGP_BTN_TR: IBMPC_GGP_JS1_X_POS,
# analog stick to keyboard key
USBGP_ABS_RX: {'type':'pb_kb', 'pos_key':KB_KEY_RIGHT[0], 'neg_key':KB_KEY_LEFT[0]},
USBGP_ABS_RY: {'type':'pb_kb', 'pos_key':KB_KEY_DOWN[0], 'neg_key':KB_KEY_UP[0]},
}
print("HERE")
print('=====>',from_code, from_type, to_code, to_type)
if page == 1:

View File

@@ -25,7 +25,7 @@ GPIO.setup(PBOARD_RESET_PIN, GPIO.IN)
GPIO.setup(PBOARD_DFU_PIN, GPIO.OUT)
GPIO.output(PBOARD_DFU_PIN, GPIO.LOW)
reset_pboard()
# reset_pboard()
usb4vc_ui.ui_init()

View File

@@ -151,13 +151,13 @@ custom_profile_1 = {
'mapping':
{
# buttons to buttons
USBGP_BTN_X: IBMPC_GGP_JS1_X_NEG,
USBGP_BTN_B: IBMPC_GGP_JS1_X_POS,
USBGP_BTN_Y: IBMPC_GGP_JS1_Y_POS,
USBGP_BTN_A: IBMPC_GGP_JS1_Y_NEG,
USBGP_BTN_X: MOUSE_BTN_LEFT,
USBGP_BTN_B: MOUSE_BTN_RIGHT,
USBGP_BTN_Y: MOUSE_BTN_MIDDLE,
USBGP_BTN_A: MOUSE_BTN_MIDDLE,
# analog stick to analog stick
USBGP_ABS_X: IBMPC_GGP_JS1_X,
USBGP_ABS_Y: IBMPC_GGP_JS1_Y,
USBGP_ABS_X: MOUSE_X,
USBGP_ABS_Y: MOUSE_Y,
USBGP_ABS_HAT0X: IBMPC_GGP_JS1_X,
USBGP_ABS_HAT0Y: IBMPC_GGP_JS1_Y,
# buttons to analog stick
@@ -449,8 +449,6 @@ def get_pboard_dict(pid):
def get_mouse_sensitivity():
return mouse_sensitivity_list[configuration_dict[this_pboard_id]["mouse_sensitivity_index"]]
PROTOCOL_CUSTOM_PROFILE = {'pid':0, 'display_name':'Custom', 'is_custom':1, 'mapping':{}}
def ui_init():
global pboard_info_spi_msg
global this_pboard_id

View File

@@ -169,24 +169,6 @@ def clamp_to_8bit(value, axes_dict, axis_key):
return value % 256
return int(value / (axes_dict[axis_key]['max'] / 127)) + 127
IBMPC_GGP_BTN_1 = 'IBMGGP_BTN_1'
IBMPC_GGP_BTN_2 = 'IBMGGP_BTN_2'
IBMPC_GGP_BTN_3 = 'IBMGGP_BTN_3'
IBMPC_GGP_BTN_4 = 'IBMGGP_BTN_4'
IBMPC_GGP_JS1_X = 'IBMGGP_JS1_X'
IBMPC_GGP_JS1_Y = 'IBMGGP_JS1_Y'
IBMPC_GGP_JS2_X = 'IBMGGP_JS2_X'
IBMPC_GGP_JS2_Y = 'IBMGGP_JS2_Y'
MOUSE_BTN_LEFT = 'MOUSE_BTN_LEFT'
MOUSE_BTN_MIDDLE = 'MOUSE_BTN_MIDDLE'
MOUSE_BTN_RIGHT = 'MOUSE_BTN_RIGHT'
MOUSE_BTN_SIDE = 'MOUSE_BTN_SIDE'
MOUSE_BTN_EXTRA = 'MOUSE_BTN_EXTRA'
MOUSE_X = 'MOUSE_X'
MOUSE_Y = 'MOUSE_Y'
MOUSE_SCROLL = 'MOUSE_SCROLL'
IBMPC_GGP_SPI_LOOKUP = {
'IBMGGP_BTN_1':4,
'IBMGGP_BTN_2':5,
@@ -198,6 +180,17 @@ IBMPC_GGP_SPI_LOOKUP = {
'IBMGGP_JS2_Y':11,
}
MOUSE_SPI_LOOKUP = {
'MOUSE_BTN_LEFT':13,
'MOUSE_BTN_RIGHT':14,
'MOUSE_BTN_MIDDLE':15,
'MOUSE_BTN_SIDE':16,
'MOUSE_BTN_EXTRA':17,
'MOUSE_X':4,
'MOUSE_Y':6,
'MOUSE_SCROLL':8,
}
def find_keycode_in_mapping(key_code, mapping_dict):
if ABS_X <= key_code <= ABS_HAT3Y:
code_type = 'usb_gp_axes'
@@ -227,25 +220,26 @@ def make_generic_gamepad_spi_packet(gp_status_dict, gp_id, axes_info, mapping_in
global prev_kb_output
this_gp_dict = gp_status_dict[gp_id]
curr_gp_output = {
IBMPC_GGP_BTN_1:set([0]),
IBMPC_GGP_BTN_2:set([0]),
IBMPC_GGP_BTN_3:set([0]),
IBMPC_GGP_BTN_4:set([0]),
IBMPC_GGP_JS1_X:set([127]),
IBMPC_GGP_JS1_Y:set([127]),
IBMPC_GGP_JS2_X:set([127]),
IBMPC_GGP_JS2_Y:set([127]),
'IBMPC_GGP_BTN_1':set([0]),
'IBMPC_GGP_BTN_2':set([0]),
'IBMPC_GGP_BTN_3':set([0]),
'IBMPC_GGP_BTN_4':set([0]),
'IBMPC_GGP_JS1_X':set([127]),
'IBMPC_GGP_JS1_Y':set([127]),
'IBMPC_GGP_JS2_X':set([127]),
'IBMPC_GGP_JS2_Y':set([127]),
}
curr_kb_output = {}
curr_mouse_output = {
MOUSE_BTN_LEFT:set([0]),
MOUSE_BTN_MIDDLE:set([0]),
MOUSE_BTN_RIGHT:set([0]),
MOUSE_BTN_SIDE:set([0]),
MOUSE_BTN_EXTRA:set([0]),
MOUSE_X:set([0]),
MOUSE_Y:set([0]),
MOUSE_SCROLL:set([0]),
'IS_MODIFIED':False,
'MOUSE_BTN_LEFT':set([0]),
'MOUSE_BTN_MIDDLE':set([0]),
'MOUSE_BTN_RIGHT':set([0]),
'MOUSE_BTN_SIDE':set([0]),
'MOUSE_BTN_EXTRA':set([0]),
'MOUSE_X':0,
'MOUSE_Y':0,
'MOUSE_SCROLL':0,
}
for from_code in this_gp_dict:
@@ -285,20 +279,31 @@ def make_generic_gamepad_spi_packet(gp_status_dict, gp_id, axes_info, mapping_in
if clamp_to_8bit(this_gp_dict[from_code], axes_info, from_code) < 127-64:
is_activated = 1
curr_kb_output[to_code['neg_key']].add(is_activated)
# button to mouse buttons
if from_type == 'usb_gp_btn' and to_type == 'mouse_btn' and to_code in curr_mouse_output:
curr_mouse_output[to_code].add(this_gp_dict[from_code])
curr_mouse_output['IS_MODIFIED'] = True
# analog to mouse axes
# print('kb', curr_kb_output)
# print('prev', prev_gp_output)
# print('curr', curr_gp_output)
if from_type == 'usb_gp_axes' and to_type == 'mouse_axes' and to_code in curr_mouse_output:
amount = clamp_to_8bit(this_gp_dict[from_code], axes_info, from_code) - 127
if abs(amount) <= 20:
amount = 0
curr_mouse_output[to_code] = int(amount / 15) & 0xffff
curr_mouse_output['IS_MODIFIED'] = True
for key in curr_kb_output:
key_status_set = curr_kb_output[key]
curr_kb_output[key] = 0
if 1 in key_status_set:
curr_kb_output[key] = 1
for key in curr_mouse_output:
if "MOUSE_BTN_" in key:
mouse_button_status_set = curr_mouse_output[key]
curr_mouse_output[key] = 0
if 1 in mouse_button_status_set:
curr_mouse_output[key] = 1
# if curr axes set is more than prev, apply the new one, else apply the one furest from midpoint
gp_spi_msg = list(gamepad_event_ibm_ggp_spi_msg_template)
gp_spi_msg[3] = gp_id;
@@ -331,17 +336,28 @@ def make_generic_gamepad_spi_packet(gp_status_dict, gp_id, axes_info, mapping_in
kb_spi_msg[4] = key
kb_spi_msg[6] = curr_kb_output[key]
mouse_spi_msg = None
if curr_mouse_output['IS_MODIFIED']:
mouse_spi_msg = list(mouse_event_spi_msg_template)
for fuck in curr_mouse_output:
if "MOUSE_BTN_" in fuck:
mouse_spi_msg[MOUSE_SPI_LOOKUP[fuck]] = curr_mouse_output[fuck]
elif "MOUSE_" in fuck:
mouse_spi_msg[MOUSE_SPI_LOOKUP[fuck]:MOUSE_SPI_LOOKUP[fuck]+2] = list(curr_mouse_output[fuck].to_bytes(2, byteorder='little'))
prev_gp_output = curr_gp_output
prev_kb_output = curr_kb_output
print(gp_spi_msg)
# print(time.time(), '-----------')
return gp_spi_msg, kb_spi_msg
print(kb_spi_msg)
print(mouse_spi_msg)
print('-------')
return gp_spi_msg, kb_spi_msg, mouse_spi_msg
def make_gamepad_spi_packet(gp_status_dict, gp_id, axes_info):
current_protocol = usb4vc_ui.get_gamepad_protocol()
if current_protocol['pid'] == PID_GENERIC_GAMEPORT_GAMEPAD and current_protocol['is_custom']:
return make_generic_gamepad_spi_packet(gp_status_dict, gp_id, axes_info, current_protocol)
return list(nop_spi_msg_template)
return list(nop_spi_msg_template), None, None
def change_kb_led(scrolllock, numlock, capslock):
led_file_list = os.listdir(led_device_path)
@@ -466,10 +482,14 @@ def raw_input_event_worker():
gamepad_status_dict[gamepad_id][abs_axes] = abs_value
# SYNC report, update now
if data[0] == EV_SYN and data[2] == SYN_REPORT:
gp_to_transfer, kb_to_transfer = make_gamepad_spi_packet(gamepad_status_dict, gamepad_id, gamepad_opened_device_dict[key][2])
gp_to_transfer, kb_to_transfer, mouse_to_transfer = make_gamepad_spi_packet(gamepad_status_dict, gamepad_id, gamepad_opened_device_dict[key][2])
pcard_spi.xfer(gp_to_transfer)
if kb_to_transfer is not None:
time.sleep(0.001)
pcard_spi.xfer(kb_to_transfer)
if mouse_to_transfer is not None:
time.sleep(0.001)
pcard_spi.xfer(mouse_to_transfer)
# ----------------- PBOARD INTERRUPT -----------------
if GPIO.event_detected(SLAVE_REQ_PIN):