mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
added p board database
This commit is contained in:
BIN
captures/xt boot.sal
Normal file
BIN
captures/xt boot.sal
Normal file
Binary file not shown.
BIN
captures/xt quick brown fox.sal
Normal file
BIN
captures/xt quick brown fox.sal
Normal file
Binary file not shown.
@@ -10,6 +10,9 @@ def print_welcome_screen(version_tuple):
|
||||
|
||||
def oled_clear():
|
||||
device.clear()
|
||||
|
||||
import queue
|
||||
oled_display_queue = queue.PriorityQueue()
|
||||
|
||||
|
||||
# while 1:
|
||||
|
||||
@@ -5,10 +5,10 @@ import RPi.GPIO as GPIO
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
|
||||
import usb4vc_shared
|
||||
import usb4vc_usb_scan
|
||||
import usb4vc_ui
|
||||
|
||||
RPI_APP_VERSION_TUPLE = (0, 0, 1)
|
||||
PBOARD_RESET_PIN = 25
|
||||
PBOARD_DFU_PIN = 12
|
||||
|
||||
@@ -27,7 +27,8 @@ GPIO.output(PBOARD_DFU_PIN, GPIO.LOW)
|
||||
|
||||
reset_pboard()
|
||||
# usb4vc_usb_scan.set_protocol()
|
||||
usb4vc_usb_scan.get_pboard_info()
|
||||
|
||||
usb4vc_ui.ui_init()
|
||||
|
||||
usb4vc_ui.ui_worker.start()
|
||||
usb4vc_usb_scan.usb_device_scan_thread.start()
|
||||
|
||||
1
user_program/usb4vc_shared.py
Normal file
1
user_program/usb4vc_shared.py
Normal file
@@ -0,0 +1 @@
|
||||
RPI_APP_VERSION_TUPLE = (0, 0, 1)
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
import sys
|
||||
import time
|
||||
import queue
|
||||
import threading
|
||||
from demo_opts import get_device
|
||||
from luma.core.render import canvas
|
||||
from PIL import ImageFont
|
||||
import RPi.GPIO as GPIO
|
||||
import usb4vc_usb_scan
|
||||
import usb4vc_shared
|
||||
|
||||
"""
|
||||
oled display object:
|
||||
@@ -21,8 +21,6 @@ duration
|
||||
afterwards
|
||||
|
||||
"""
|
||||
oled_display_queue = queue.PriorityQueue()
|
||||
|
||||
|
||||
PLUS_BUTTON_PIN = 27
|
||||
MINUS_BUTTON_PIN = 19
|
||||
@@ -49,6 +47,7 @@ OLED_HEIGHT = 32
|
||||
my_arg = ['--display', 'ssd1306', '--interface', 'spi', '--spi-port', '0', '--spi-device', '1', '--gpio-reset', '6', '--gpio-data-command', '5', '--width', str(OLED_WIDTH), '--height', str(OLED_HEIGHT), '--spi-bus-speed', '2000000']
|
||||
device = get_device(my_arg)
|
||||
|
||||
|
||||
"""
|
||||
OLED for USB4VC
|
||||
128*32
|
||||
@@ -70,7 +69,7 @@ medium font: 16
|
||||
large font: 11
|
||||
|
||||
int(sys.argv[1])
|
||||
$ sh sync.sh; ssh -t pi@192.168.1.56 "pkill python3;cd ~/usb4vc;python3 usb4vc_ui.py"
|
||||
sh sync.sh; ssh -t pi@192.168.1.56 "pkill python3;cd ~/usb4vc;python3 usb4vc_main.py"
|
||||
"""
|
||||
|
||||
font_regular = ImageFont.truetype("ProggyTiny.ttf", 16)
|
||||
@@ -87,15 +86,66 @@ def oled_print_centered(text, font, y, this_canvas):
|
||||
start_x = 0
|
||||
this_canvas.text((start_x, y), text, font=font, fill="white")
|
||||
|
||||
PROTOCOL_OFF = {'pid':0, 'display_name':"OFF"}
|
||||
PROTOCOL_AT_PS2_KB = {'pid':1, 'display_name':"AT/PS2"}
|
||||
PROTOCOL_XT_KB = {'pid':2, 'display_name':"PC XT"}
|
||||
PROTOCOL_ADB_KB = {'pid':3, 'display_name':"ADB"}
|
||||
PROTOCOL_PS2_MOUSE = {'pid':4, 'display_name':"PS/2"}
|
||||
PROTOCOL_MICROSOFT_SERIAL_MOUSE = {'pid':5, 'display_name':"MS Serial"}
|
||||
PROTOCOL_ADB_MOUSE = {'pid':6, 'display_name':"ADB"}
|
||||
PROTOCOL_GENERIC_GAMEPORT_GAMEPAD = {'pid':7, 'display_name':"Generic PC"}
|
||||
PROTOCOL_GAMEPORT_GRAVIS_GAMEPAD = {'pid':8, 'display_name':"Gravis Pro"}
|
||||
PROTOCOL_GAMEPORT_MICROSOFT_SIDEWINDER = {'pid':9, 'display_name':"MS Sidewinder"}
|
||||
PROTOCOL_RAW_KEYBOARD = {'pid':125, 'display_name':"Raw data"}
|
||||
PROTOCOL_RAW_MOUSE = {'pid':126, 'display_name':"Raw data"}
|
||||
PROTOCOL_RAW_GAMEPAD = {'pid':127, 'display_name':"Raw data"}
|
||||
|
||||
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_OFF, PROTOCOL_ADB_KB]
|
||||
mouse_protocol_options_adb = [PROTOCOL_OFF, PROTOCOL_ADB_MOUSE]
|
||||
gamepad_protocol_options_adb = [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_offset_list = [0, 0.2, 0.4, 0.6, -0.6, -0.4, -0.2]
|
||||
|
||||
configuration_dict = {}
|
||||
|
||||
"""
|
||||
key is protocol card ID
|
||||
conf_dict[pbid]:
|
||||
hw revision
|
||||
current keyboard protocol
|
||||
current mouse protocol
|
||||
current gamepad procotol
|
||||
mouse sensitivity
|
||||
"""
|
||||
|
||||
def save_config():
|
||||
pass
|
||||
|
||||
|
||||
class usb4vc_menu(object):
|
||||
def __init__(self):
|
||||
def __init__(self, pboard):
|
||||
super(usb4vc_menu, self).__init__()
|
||||
self.current_level = 0
|
||||
self.current_page = 0
|
||||
self.level_size = 2
|
||||
self.page_size = [3, 6]
|
||||
self.page_size = [4, 5]
|
||||
self.last_refresh = 0
|
||||
self.kb_opts = list(pboard['kbp'])
|
||||
self.mouse_opts = list(pboard['mp'])
|
||||
self.gamepad_opts = list(pboard['gpp'])
|
||||
self.pb_info = dict(pboard)
|
||||
self.current_keyboard_protocol_index = 0
|
||||
self.current_mouse_protocol_index = 0
|
||||
self.current_mouse_sensitivity_offset_index = 0
|
||||
self.current_gamepad_protocol_index = 0
|
||||
|
||||
def switch_page(self, amount):
|
||||
self.current_page = (self.current_page + amount) % self.page_size[self.current_level]
|
||||
@@ -110,9 +160,9 @@ class usb4vc_menu(object):
|
||||
if level == 0:
|
||||
if page == 0:
|
||||
with canvas(device) as draw:
|
||||
draw.text((0, 0), "Keyboard: PS/2", font=font_regular, fill="white")
|
||||
draw.text((0, 10), "Mouse: Serial", font=font_regular, fill="white")
|
||||
draw.text((0, 20), "Gamepad: Generic", font=font_regular, fill="white")
|
||||
draw.text((0, 0), f"KBD: {self.kb_opts[self.current_keyboard_protocol_index]['display_name']}", font=font_regular, fill="white")
|
||||
draw.text((0, 10), f"MOS: {self.mouse_opts[self.current_mouse_protocol_index]['display_name']}", font=font_regular, fill="white")
|
||||
draw.text((0, 20), f"GPD: {self.gamepad_opts[self.current_gamepad_protocol_index]['display_name']}", font=font_regular, fill="white")
|
||||
if page == 1:
|
||||
with canvas(device) as draw:
|
||||
draw.text((0, 0), f"USB Keyboard: {len(usb4vc_usb_scan.keyboard_opened_device_dict)}", font=font_regular, fill="white")
|
||||
@@ -120,31 +170,31 @@ class usb4vc_menu(object):
|
||||
draw.text((0, 20), f"USB Gamepad: {len(usb4vc_usb_scan.gamepad_opened_device_dict)}", font=font_regular, fill="white")
|
||||
if page == 2:
|
||||
with canvas(device) as draw:
|
||||
draw.text((0, 0), "PBoard: IBM PC Compat", font=font_regular, fill="white")
|
||||
draw.text((0, 10), "PBoard FW: 0.1.1", font=font_regular, fill="white")
|
||||
draw.text((0, 20), "IP: 192.168.231.12", font=font_regular, fill="white")
|
||||
draw.text((0, 0), f"PB:{self.pb_info['full_name']}", font=font_regular, fill="white")
|
||||
draw.text((0, 10), f"FW:{self.pb_info['fw_ver'][0]}.{self.pb_info['fw_ver'][1]}.{self.pb_info['fw_ver'][2]} REV:{self.pb_info['hw_rev']}", font=font_regular, fill="white")
|
||||
draw.text((0, 20), f"IP: 192.168.231.12", font=font_regular, fill="white")
|
||||
if page == 3:
|
||||
with canvas(device) as draw:
|
||||
oled_print_centered("Pair Bluetooth", font_medium, 10, draw)
|
||||
|
||||
if level == 1:
|
||||
if page == 0:
|
||||
with canvas(device) as draw:
|
||||
oled_print_centered("Keyboard Protocol", font_medium, 0, draw)
|
||||
oled_print_centered("PS/2", font_medium, 15, draw)
|
||||
oled_print_centered(self.kb_opts[self.current_keyboard_protocol_index]['display_name'], font_medium, 15, draw)
|
||||
if page == 1:
|
||||
with canvas(device) as draw:
|
||||
oled_print_centered("Mouse Protocol", font_medium, 0, draw)
|
||||
oled_print_centered("Serial", font_medium, 15, draw)
|
||||
oled_print_centered(self.mouse_opts[self.current_mouse_protocol_index]['display_name'], font_medium, 15, draw)
|
||||
if page == 2:
|
||||
with canvas(device) as draw:
|
||||
oled_print_centered("Mouse Sensitivity", font_medium, 0, draw)
|
||||
oled_print_centered("1.0", font_medium, 15, draw)
|
||||
oled_print_centered("Gamepad Protocol", font_medium, 0, draw)
|
||||
oled_print_centered(self.gamepad_opts[self.current_gamepad_protocol_index]['display_name'], font_medium, 15, draw)
|
||||
if page == 3:
|
||||
with canvas(device) as draw:
|
||||
oled_print_centered("Gamepad Protocol", font_medium, 0, draw)
|
||||
oled_print_centered("MS Sidewinder", font_medium, 15, draw)
|
||||
oled_print_centered("Mouse Sensitivity", font_medium, 0, draw)
|
||||
oled_print_centered(f"{1 + mouse_sensitivity_offset_list[self.current_mouse_sensitivity_offset_index]}", font_medium, 15, draw)
|
||||
if page == 4:
|
||||
with canvas(device) as draw:
|
||||
oled_print_centered("Pair Bluetooth", font_medium, 10, draw)
|
||||
if page == 5:
|
||||
with canvas(device) as draw:
|
||||
oled_print_centered("Back", font_medium, 10, draw)
|
||||
|
||||
@@ -153,7 +203,19 @@ class usb4vc_menu(object):
|
||||
self.switch_level(1)
|
||||
self.display_curent_page()
|
||||
if level == 1:
|
||||
if page == 5:
|
||||
if page == 0:
|
||||
self.current_keyboard_protocol_index = (self.current_keyboard_protocol_index + 1) % len(self.kb_opts)
|
||||
self.display_curent_page()
|
||||
if page == 1:
|
||||
self.current_mouse_protocol_index = (self.current_mouse_protocol_index + 1) % len(self.mouse_opts)
|
||||
self.display_curent_page()
|
||||
if page == 2:
|
||||
self.current_gamepad_protocol_index = (self.current_gamepad_protocol_index + 1) % len(self.gamepad_opts)
|
||||
self.display_curent_page()
|
||||
if page == 3:
|
||||
self.current_mouse_sensitivity_offset_index = (self.current_mouse_sensitivity_offset_index + 1) % len(mouse_sensitivity_offset_list)
|
||||
self.display_curent_page()
|
||||
if page == 4:
|
||||
self.switch_level(-1)
|
||||
self.display_curent_page()
|
||||
|
||||
@@ -168,10 +230,28 @@ class usb4vc_menu(object):
|
||||
self.display_page(0, 1)
|
||||
self.last_refresh = time.time()
|
||||
|
||||
my_menu = usb4vc_menu()
|
||||
pboard_info_spi_msg = [0] * 32
|
||||
pboard_database = {
|
||||
0:{'author':'Unknown', 'fw_ver':(0,0,0), 'full_name':'Unknown/Unplugged', 'hw_rev':0, 'kbp':keyboard_protocol_options_raw, 'mp':mouse_protocol_options_raw, 'gpp':gamepad_protocol_options_raw},
|
||||
1:{'author':'dekuNukem', 'fw_ver':(0,0,0), 'full_name':'IBM PC Compatible', 'hw_rev':0, 'kbp':keyboard_protocol_options_ibmpc, 'mp':mouse_protocol_options_ibmpc, 'gpp':gamepad_protocol_options_ibmpc},
|
||||
2:{'author':'dekuNukem', 'fw_ver':(0,0,0), 'full_name':'Apple Desktop Bus', 'hw_rev':0, , 'kbp':keyboard_protocol_options_adb, 'mp':mouse_protocol_options_adb, 'gpp':gamepad_protocol_options_adb},
|
||||
}
|
||||
|
||||
def get_pboard_dict(pid):
|
||||
if pid not in pboard_database:
|
||||
pid = 0
|
||||
return pboard_database[pid]
|
||||
|
||||
def ui_init():
|
||||
global pboard_info_spi_msg
|
||||
pboard_info_spi_msg = usb4vc_usb_scan.get_pboard_info()
|
||||
if pboard_info_spi_msg[3] in pboard_database:
|
||||
pboard_database[pboard_info_spi_msg[3]]['hw_rev'] = pboard_info_spi_msg[4]
|
||||
pboard_database[pboard_info_spi_msg[3]]['fw_ver'] = (pboard_info_spi_msg[5], pboard_info_spi_msg[6], pboard_info_spi_msg[7])
|
||||
|
||||
def ui_worker():
|
||||
print("ui_worker started")
|
||||
my_menu = usb4vc_menu(get_pboard_dict(pboard_info_spi_msg[3]))
|
||||
my_menu.display_page(0, 0)
|
||||
while 1:
|
||||
time.sleep(0.1)
|
||||
|
||||
@@ -6,6 +6,7 @@ import threading
|
||||
import subprocess
|
||||
import RPi.GPIO as GPIO
|
||||
import usb4vc_ui
|
||||
import usb4vc_shared
|
||||
|
||||
"""
|
||||
sudo apt install stm32flash
|
||||
@@ -114,16 +115,6 @@ ABS_HAT2Y = 0x15
|
||||
ABS_HAT3X = 0x16
|
||||
ABS_HAT3Y = 0x17
|
||||
|
||||
PROTOCOL_AT_PS2_KB = 1
|
||||
PROTOCOL_XT_KB = 2
|
||||
PROTOCOL_ADB_KB = 3
|
||||
PROTOCOL_PS2_MOUSE = 4
|
||||
PROTOCOL_MICROSOFT_SERIAL_MOUSE = 5
|
||||
PROTOCOL_ADB_MOUSE = 6
|
||||
PROTOCOL_GENERIC_GAMEPORT_GAMEPAD = 7
|
||||
PROTOCOL_GAMEPORT_GRAVIS_GAMEPAD = 8
|
||||
PROTOCOL_GAMEPORT_MICROSOFT_SIDEWINDER = 9
|
||||
|
||||
nop_spi_msg_template = [SPI_MOSI_MAGIC] + [0]*31
|
||||
info_request_spi_msg_template = [SPI_MOSI_MAGIC, 0, SPI_MOSI_MSG_TYPE_INFO_REQUEST] + [0]*29
|
||||
set_protocl_spi_msg_template = [SPI_MOSI_MAGIC, 0, SPI_MOSI_MSG_TYPE_SET_PROTOCOL] + [0]*29
|
||||
@@ -405,13 +396,18 @@ usb_device_scan_thread = threading.Thread(target=usb_device_scan_worker, daemon=
|
||||
|
||||
def get_pboard_info():
|
||||
# send request
|
||||
pcard_spi.xfer(list(info_request_spi_msg_template))
|
||||
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]
|
||||
pcard_spi.xfer(this_msg)
|
||||
|
||||
time.sleep(0.01)
|
||||
# send an empty message to allow response to be shifted into RPi
|
||||
response = pcard_spi.xfer(list(nop_spi_msg_template))
|
||||
time.sleep(0.01)
|
||||
response = pcard_spi.xfer(list(nop_spi_msg_template))
|
||||
print(response)
|
||||
return response
|
||||
|
||||
def set_protocol():
|
||||
this_msg = list(set_protocl_spi_msg_template)
|
||||
|
||||
Reference in New Issue
Block a user