added lisa mac adb card custom mapping support

This commit is contained in:
dekunukem
2023-04-24 03:10:32 +01:00
parent 5d06148faf
commit 77a764d781
3 changed files with 58 additions and 58 deletions

View File

@@ -5,14 +5,42 @@ config_dir_path = "/home/pi/usb4vc/config"
firmware_dir_path = "/home/pi/usb4vc/firmware"
temp_dir_path = "/home/pi/usb4vc/temp"
i2c_bootloader_pbid = [1, 3]
usb_bootloader_pbid = [2]
def ensure_dir(dir_path):
print('ensure_dir', dir_path)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
PBOARD_ID_UNKNOWN = 0
PBOARD_ID_IBMPC = 1
PBOARD_ID_ADB = 2
PBOARD_ID_APPLE_LISA_MAC_ADB = 3
i2c_bootloader_pbid = [PBOARD_ID_IBMPC, PBOARD_ID_APPLE_LISA_MAC_ADB]
usb_bootloader_pbid = [PBOARD_ID_ADB]
board_id_lookup = {
'Unknown':PBOARD_ID_UNKNOWN,
'IBMPC':PBOARD_ID_IBMPC,
'ADB':PBOARD_ID_ADB,
'Lisa/Mac/ADB':PBOARD_ID_APPLE_LISA_MAC_ADB,
}
protocol_id_lookup = {
'OFF':0,
'AT_PS2_KB':1,
'XT_KB':2,
'ADB_KB':3,
'PS2_MOUSE':4,
'MICROSOFT_SERIAL_MOUSE':5,
'ADB_MOUSE':6,
'GAMEPORT_15PIN_GAMEPAD':7,
'GAMEPORT_GRAVIS_GAMEPAD':8,
'GAMEPORT_MICROSOFT_SIDEWINDER':9,
'RAW_KEYBOARD':125,
'RAW_MOUSE':126,
'RAW_GAMEPAD':127,
}
"""
0.3.0
20230307
@@ -21,9 +49,14 @@ Added BUSY signal detect
0.3.1
20230416
Added Lisa Mac ADB card firmware update support
0.3.2
20230424
Added lisa mac adb card custom mapping support
made USB joystick-to-mouse movement speed faster
"""
RPI_APP_VERSION_TUPLE = (0, 3, 1)
RPI_APP_VERSION_TUPLE = (0, 3, 2)
code_name_to_value_lookup = {
'KEY_RESERVED':(0, 'kb_key'),
@@ -496,28 +529,6 @@ code_value_to_name_lookup = {
373:{'BTN_MODE'},
}
board_id_lookup = {
'Unknown':0,
'IBMPC':1,
'ADB':2,
}
protocol_id_lookup = {
'OFF':0,
'AT_PS2_KB':1,
'XT_KB':2,
'ADB_KB':3,
'PS2_MOUSE':4,
'MICROSOFT_SERIAL_MOUSE':5,
'ADB_MOUSE':6,
'GAMEPORT_15PIN_GAMEPAD':7,
'GAMEPORT_GRAVIS_GAMEPAD':8,
'GAMEPORT_MICROSOFT_SIDEWINDER':9,
'RAW_KEYBOARD':125,
'RAW_MOUSE':126,
'RAW_GAMEPAD':127,
}
gamepad_event_code_name_list = [
'BTN_1',
'BTN_2',

View File

@@ -8,20 +8,13 @@ import usb4vc_oled
from luma.core.render import canvas
import RPi.GPIO as GPIO
import usb4vc_usb_scan
import usb4vc_shared
import usb4vc_show_ev
import usb4vc_check_update
import json
import subprocess
from subprocess import Popen, PIPE
from usb4vc_shared import this_app_dir_path
from usb4vc_shared import config_dir_path
from usb4vc_shared import firmware_dir_path
from usb4vc_shared import temp_dir_path
from usb4vc_shared import ensure_dir
from usb4vc_shared import i2c_bootloader_pbid
from usb4vc_shared import usb_bootloader_pbid
from usb4vc_shared import *
config_file_path = os.path.join(config_dir_path, 'config.json')
@@ -63,11 +56,7 @@ class my_button(object):
result = True
self.prev_state = current_state
return result
PBOARD_ID_UNKNOWN = 0
PBOARD_ID_IBMPC = 1
PBOARD_ID_ADB = 2
PBOARD_ID_APPLE_LISA_MAC_ADB = 3
pboard_info_spi_msg = [0] * 32
this_pboard_id = PBOARD_ID_UNKNOWN
@@ -515,7 +504,7 @@ class usb4vc_menu(object):
draw.text((0, 0), f"{self.pb_info['full_name']} PID {this_pboard_id}", font=usb4vc_oled.font_regular, fill="white")
else:
draw.text((0, 0), f"{self.pb_info['full_name']}", font=usb4vc_oled.font_regular, fill="white")
draw.text((0, 10), f"PB {self.pb_info['fw_ver'][0]}.{self.pb_info['fw_ver'][1]}.{self.pb_info['fw_ver'][2]} RPi {usb4vc_shared.RPI_APP_VERSION_TUPLE[0]}.{usb4vc_shared.RPI_APP_VERSION_TUPLE[1]}.{usb4vc_shared.RPI_APP_VERSION_TUPLE[2]}", font=usb4vc_oled.font_regular, fill="white")
draw.text((0, 10), f"PB {self.pb_info['fw_ver'][0]}.{self.pb_info['fw_ver'][1]}.{self.pb_info['fw_ver'][2]} RPi {RPI_APP_VERSION_TUPLE[0]}.{RPI_APP_VERSION_TUPLE[1]}.{RPI_APP_VERSION_TUPLE[2]}", font=usb4vc_oled.font_regular, fill="white")
draw.text((0, 20), f"IP: {get_ip_address()}", font=usb4vc_oled.font_regular, fill="white")
if page == 2:
with canvas(usb4vc_oled.oled_device) as draw:
@@ -863,15 +852,15 @@ def ui_init():
if this_pboard_id in pboard_database:
# load custom profile mapping into protocol list
for item in custom_profile_list:
this_mapping_bid = usb4vc_shared.board_id_lookup.get(item['protocol_board'], 0)
this_mapping_bid = 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]:
this_mapping_pid = usb4vc_shared.protocol_id_lookup.get(item['protocol_name'])
this_mapping_pid = protocol_id_lookup.get(item['protocol_name'])
item['pid'] = this_mapping_pid
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]['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:
configuration_dict['rpi_app_ver'] = usb4vc_shared.RPI_APP_VERSION_TUPLE
configuration_dict['rpi_app_ver'] = RPI_APP_VERSION_TUPLE
if this_pboard_id not in configuration_dict:
configuration_dict[this_pboard_id] = {"keyboard_protocol_index":1, "mouse_protocol_index":1, "mouse_sensitivity_index":0, "gamepad_protocol_index":1}

View File

@@ -7,7 +7,7 @@ import evdev
import threading
import RPi.GPIO as GPIO
import usb4vc_ui
import usb4vc_shared
from usb4vc_shared import *
import usb4vc_gamepads
"""
@@ -128,11 +128,11 @@ def xfer_when_not_busy(data, drop=False):
return pcard_spi.xfer(data)
def is_gamepad_button(event_code):
name_result = usb4vc_shared.code_value_to_name_lookup.get(event_code)
name_result = code_value_to_name_lookup.get(event_code)
if name_result is None:
return False
for item in name_result:
if item in usb4vc_shared.gamepad_event_code_name_list:
if item in gamepad_event_code_name_list:
return True
return False
@@ -250,7 +250,7 @@ def find_keycode_in_mapping(source_code, mapping_dict, usb_gamepad_type):
elif 'Xbox' in usb_gamepad_type and map_dict_copy.get("MAPPING_TYPE") == "DEFAULT_MOUSE_KB":
map_dict_copy = usb4vc_gamepads.XBOX_DEFAULT_KB_MOUSE_MAPPING
source_name = usb4vc_shared.code_value_to_name_lookup.get(source_code)
source_name = code_value_to_name_lookup.get(source_code)
if source_name is None:
return None, None
if 'Xbox' in usb_gamepad_type:
@@ -267,7 +267,7 @@ def find_keycode_in_mapping(source_code, mapping_dict, usb_gamepad_type):
return None, None
target_info = dict(target_info) # make a copy so the lookup table itself won't get modified
lookup_result = usb4vc_shared.code_name_to_value_lookup.get(target_info['code'])
lookup_result = code_name_to_value_lookup.get(target_info['code'])
if lookup_result is None:
return None, None
source_type = None
@@ -279,7 +279,7 @@ def find_keycode_in_mapping(source_code, mapping_dict, usb_gamepad_type):
return None, None
target_info['code'] = lookup_result[0]
if 'code_neg' in target_info:
target_info['code_neg'] = usb4vc_shared.code_name_to_value_lookup.get(target_info['code_neg'])[0]
target_info['code_neg'] = code_name_to_value_lookup.get(target_info['code_neg'])[0]
target_info['type'] = lookup_result[1]
return source_type, target_info
@@ -424,7 +424,7 @@ def make_15pin_gamepad_spi_packet(gp_status_dict, this_device_info, mapping_info
pass
if abs(movement) <= deadzone_amount:
movement = 0
joystick_to_mouse_slowdown = 17
joystick_to_mouse_slowdown = 10
curr_mouse_output[target_code] = int(movement / joystick_to_mouse_slowdown)
curr_mouse_output['is_modified'] = True
@@ -519,19 +519,19 @@ def xbname_to_ev_codename(xb_btn):
ev_name = usb4vc_gamepads.xbox_one_to_linux_ev_code_dict.get(xb_btn)
if ev_name is None:
return None
return usb4vc_shared.code_name_to_value_lookup[ev_name][0]
return code_name_to_value_lookup[ev_name][0]
def ps5name_to_ev_codename(ps5_btn):
ev_name = usb4vc_gamepads.ps5_to_linux_ev_code_dict.get(ps5_btn)
if ev_name is None:
return None
return usb4vc_shared.code_name_to_value_lookup[ev_name][0]
return code_name_to_value_lookup[ev_name][0]
def ps4name_to_ev_codename(ps4_btn):
ev_name = usb4vc_gamepads.ps4_to_linux_ev_code_dict.get(ps4_btn)
if ev_name is None:
return None
return usb4vc_shared.code_name_to_value_lookup[ev_name][0]
return code_name_to_value_lookup[ev_name][0]
xbox_to_generic_dict = {
xbname_to_ev_codename('XB_A'):'FACE_BUTTON_SOUTH',
@@ -841,7 +841,7 @@ def raw_input_event_worker():
last_mouse_msg = list(this_mouse_msg)
if this_device['is_gp']:
for axis_name in USB_GAMEPAD_STICK_AXES_NAMES:
axis_code = usb4vc_shared.code_name_to_value_lookup.get(axis_name)[0]
axis_code = code_name_to_value_lookup.get(axis_name)[0]
this_gp_dict = gamepad_status_dict[this_device['id']]
if axis_code in this_gp_dict and 127 - 10 <= this_gp_dict[axis_code] <= 127 + 10:
this_gp_dict[axis_code] = 127
@@ -884,7 +884,7 @@ def check_is_gamepad(capability_dict):
key_name_set.add(item)
if isinstance(item, list):
key_name_set.update(item)
for item in usb4vc_shared.gamepad_event_code_name_list:
for item in gamepad_event_code_name_list:
if item in key_name_set:
return True
return False
@@ -975,9 +975,9 @@ usb_device_scan_thread = threading.Thread(target=usb_device_scan_worker, daemon=
def get_pboard_info():
# send request
this_msg = list(info_request_spi_msg_template)
this_msg[3] = usb4vc_shared.RPI_APP_VERSION_TUPLE[0]
this_msg[4] = usb4vc_shared.RPI_APP_VERSION_TUPLE[1]
this_msg[5] = usb4vc_shared.RPI_APP_VERSION_TUPLE[2]
this_msg[3] = RPI_APP_VERSION_TUPLE[0]
this_msg[4] = RPI_APP_VERSION_TUPLE[1]
this_msg[5] = RPI_APP_VERSION_TUPLE[2]
xfer_when_not_busy(this_msg)
time.sleep(0.05)