diff --git a/controller_uart_bridge.py b/controller_uart_bridge.py index 5ca5045..99a3dbf 100644 --- a/controller_uart_bridge.py +++ b/controller_uart_bridge.py @@ -36,7 +36,7 @@ from rich.table import Table UART_HEADER = 0xAA RUMBLE_HEADER = 0xBB RUMBLE_TYPE_RUMBLE = 0x01 -UART_BAUD = 900000 +UART_BAUD = 921600 RUMBLE_IDLE_TIMEOUT = 0.25 # seconds without packets before forcing rumble off RUMBLE_STUCK_TIMEOUT = 0.60 # continuous same-energy rumble will be stopped after this RUMBLE_MIN_ACTIVE = 0.50 # below this, rumble is treated as off/noise @@ -96,6 +96,14 @@ def trigger_to_button(value: int, threshold: int) -> bool: return value >= threshold +def set_hint(name: str, value: str) -> None: + """Set an SDL hint safely even if the constant is missing in PySDL2.""" + try: + sdl2.SDL_SetHint(name.encode(), value.encode()) + except Exception: + pass + + BUTTON_MAP = { # Direct mapping to the Switch PRO mask definitions in switch_pro_descriptors.h sdl2.SDL_CONTROLLER_BUTTON_A: SwitchButton.A, @@ -446,6 +454,10 @@ def main() -> None: console.print(f"[red]Failed to load SDL mapping {mapping_path}: {exc}[/red]") sdl2.SDL_SetHint(sdl2.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, b"1") + set_hint("SDL_JOYSTICK_HIDAPI", "1") + set_hint("SDL_JOYSTICK_HIDAPI_SWITCH", "1") + # Use controller button labels so Nintendo layouts (ABXY) map correctly on Linux. + set_hint("SDL_GAMECONTROLLER_USE_BUTTON_LABELS", "1") if sdl2.SDL_Init(sdl2.SDL_INIT_GAMECONTROLLER | sdl2.SDL_INIT_JOYSTICK) != 0: parser.error(f"SDL init failed: {sdl2.SDL_GetError().decode(errors='ignore')}") contexts: Dict[int, ControllerContext] = {} diff --git a/switch-pico.cpp b/switch-pico.cpp index 881f4de..646bbe0 100644 --- a/switch-pico.cpp +++ b/switch-pico.cpp @@ -14,7 +14,7 @@ // UART1 is reserved for external input frames from the host PC. #define UART_ID uart1 -#define BAUD_RATE 900000 +#define BAUD_RATE 921600 #define UART_TX_PIN 4 #define UART_RX_PIN 5 #define UART_RUMBLE_HEADER 0xBB