|
78 | 78 | BUTTONS = ["left", "right", "middle"]
|
79 | 79 |
|
80 | 80 | mouse_bufs = []
|
| 81 | + |
81 | 82 | for mouse_tg in mouse_tgs:
|
82 | 83 | # Buffer to hold data read from the mouse
|
83 | 84 | # Boot mice have 4 byte reports
|
84 |
| - mouse_bufs.append(array.array("b", [0] * 4)) |
| 85 | + mouse_bufs.append(array.array("b", [0] * 8)) |
| 86 | + |
| 87 | + |
| 88 | +def get_mouse_deltas(buffer, read_count): |
| 89 | + if read_count == 4: |
| 90 | + delta_x = buffer[1] |
| 91 | + delta_y = buffer[2] |
| 92 | + elif read_count == 8: |
| 93 | + delta_x = buffer[2] |
| 94 | + delta_y = buffer[4] |
| 95 | + else: |
| 96 | + raise ValueError(f"Unsupported mouse packet size: {read_count}, must be 4 or 8") |
| 97 | + return delta_x, delta_y |
85 | 98 |
|
86 | 99 |
|
87 | 100 | while True:
|
|
92 | 105 | )
|
93 | 106 | except usb.core.USBTimeoutError:
|
94 | 107 | continue
|
95 |
| - |
| 108 | + mouse_deltas = get_mouse_deltas(mouse_bufs[mouse_index], count) |
96 | 109 | mouse_tgs[mouse_index].x = max(
|
97 |
| - 0, min(display.width - 1, mouse_tgs[mouse_index].x + mouse_bufs[mouse_index][1]) |
| 110 | + 0, min(display.width - 1, mouse_tgs[mouse_index].x + mouse_deltas[0]) |
98 | 111 | )
|
99 | 112 | mouse_tgs[mouse_index].y = max(
|
100 |
| - 0, min(display.height - 1, mouse_tgs[mouse_index].y + mouse_bufs[mouse_index][2]) |
| 113 | + 0, min(display.height - 1, mouse_tgs[mouse_index].y + mouse_deltas[1]) |
101 | 114 | )
|
102 | 115 |
|
103 | 116 | out_str = f"{mouse_tgs[mouse_index].x},{mouse_tgs[mouse_index].y}"
|
|
0 commit comments