(q: 'Queue[str]')
| 94 | button_name_list: list[str] = [] |
| 95 | |
| 96 | def wheel_poll_thread(q: 'Queue[str]') -> NoReturn: |
| 97 | # Open the joystick device. |
| 98 | fn = '/dev/input/js0' |
| 99 | print(f'Opening {fn}...') |
| 100 | jsdev = open(fn, 'rb') |
| 101 | |
| 102 | # Get the device name. |
| 103 | #buf = bytearray(63) |
| 104 | buf = array.array('B', [0] * 64) |
| 105 | ioctl(jsdev, 0x80006a13 + (0x10000 * len(buf)), buf) # JSIOCGNAME(len) |
| 106 | js_name = buf.tobytes().rstrip(b'\x00').decode('utf-8') |
| 107 | print(f'Device name: {js_name}') |
| 108 | |
| 109 | # Get number of axes and buttons. |
| 110 | buf = array.array('B', [0]) |
| 111 | ioctl(jsdev, 0x80016a11, buf) # JSIOCGAXES |
| 112 | num_axes = buf[0] |
| 113 | |
| 114 | buf = array.array('B', [0]) |
| 115 | ioctl(jsdev, 0x80016a12, buf) # JSIOCGBUTTONS |
| 116 | num_buttons = buf[0] |
| 117 | |
| 118 | # Get the axis map. |
| 119 | buf = array.array('B', [0] * 0x40) |
| 120 | ioctl(jsdev, 0x80406a32, buf) # JSIOCGAXMAP |
| 121 | |
| 122 | for _axis in buf[:num_axes]: |
| 123 | axis_name = axis_names.get(_axis, f'unknown(0x{_axis:02x})') |
| 124 | axis_name_list.append(axis_name) |
| 125 | axis_states[axis_name] = 0.0 |
| 126 | |
| 127 | # Get the button map. |
| 128 | buf = array.array('H', [0] * 200) |
| 129 | ioctl(jsdev, 0x80406a34, buf) # JSIOCGBTNMAP |
| 130 | |
| 131 | for btn in buf[:num_buttons]: |
| 132 | btn_name = button_names.get(btn, f'unknown(0x{btn:03x})') |
| 133 | button_name_list.append(btn_name) |
| 134 | button_states[btn_name] = 0 |
| 135 | |
| 136 | print(f'{num_axes} axes found: {", ".join(axis_name_list)}') |
| 137 | print(f'{num_buttons} buttons found: {", ".join(button_name_list)}') |
| 138 | |
| 139 | # Enable FF |
| 140 | import evdev |
| 141 | from evdev import ecodes, InputDevice |
| 142 | device = evdev.list_devices()[0] |
| 143 | evtdev = InputDevice(device) |
| 144 | val = 24000 |
| 145 | evtdev.write(ecodes.EV_FF, ecodes.FF_AUTOCENTER, val) |
| 146 | |
| 147 | while True: |
| 148 | evbuf = jsdev.read(8) |
| 149 | value, mtype, number = struct.unpack('4xhBB', evbuf) |
| 150 | # print(mtype, number, value) |
| 151 | if mtype & 0x02: # wheel & paddles |
| 152 | axis = axis_name_list[number] |
| 153 |
no test coverage detected