#!/usr/bin/env python3 """ Debug script to test uhid communication """ import os import sys import struct import time UHID_CREATE2 = 11 # Simple HID descriptor for testing - just a joystick with X/Y hid_descriptor = bytes([ 0x05, 0x01, # Usage Page (Generic Desktop) 0x09, 0x04, # Usage (Joystick) 0xA1, 0x01, # Collection (Application) 0x09, 0x30, # Usage (X) 0x09, 0x31, # Usage (Y) 0x15, 0x00, # Logical Minimum (0) 0x26, 0xFF, 0x00, # Logical Maximum (255) 0x75, 0x08, # Report Size (8 bits) 0x95, 0x02, # Report Count (2) 0x81, 0x02, # Input (Data, Variable, Absolute) 0xC0 # End Collection ]) print("Testing UHID device creation...") print(f"HID descriptor size: {len(hid_descriptor)} bytes") try: fd = os.open('/dev/uhid', os.O_RDWR | os.O_NONBLOCK) print("✓ Opened /dev/uhid") except PermissionError: print("✗ Permission denied. Run with sudo.") sys.exit(1) except FileNotFoundError: print("✗ /dev/uhid not found") sys.exit(1) # Build event according to kernel structure name = b"Test Fake Wheel" phys = b"fake-test" uniq = b"test-001" # Pack the create2 structure # struct uhid_create2_req { # __u8 name[128]; # __u8 phys[64]; # __u8 uniq[64]; # __u16 rd_size; # __u16 bus; # __u32 vendor; # __u32 product; # __u32 version; # __u32 country; # __u8 rd_data[HID_MAX_DESCRIPTOR_SIZE]; # } event_data = struct.pack('