summaryrefslogtreecommitdiff
path: root/kvmd/apps/otg/hid/mouse.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-11-03 06:17:52 +0300
committerDevaev Maxim <[email protected]>2020-11-03 06:17:52 +0300
commitc31115051cb17a650e6d42e3e5cbfe05de809760 (patch)
tree457dd0414d0840a64d5de9c491413c6b1de783a3 /kvmd/apps/otg/hid/mouse.py
parent544f4b3fecb84e2ae21eb71ec0c37c8bec38261c (diff)
configurable wheel for otg
Diffstat (limited to 'kvmd/apps/otg/hid/mouse.py')
-rw-r--r--kvmd/apps/otg/hid/mouse.py227
1 files changed, 116 insertions, 111 deletions
diff --git a/kvmd/apps/otg/hid/mouse.py b/kvmd/apps/otg/hid/mouse.py
index dfb5adec..9dcc0e5d 100644
--- a/kvmd/apps/otg/hid/mouse.py
+++ b/kvmd/apps/otg/hid/mouse.py
@@ -24,114 +24,119 @@ from . import Hid
# =====
-MOUSE_ABSOLUTE_HID = Hid(
- protocol=0, # None protocol
- subclass=0, # No subclass
-
- report_length=7,
-
- report_descriptor=bytes([
- # https://github.com/NicoHood/HID/blob/0835e6a/src/SingleReport/SingleAbsoluteMouse.cpp
- # Репорт взят отсюда ^^^, но изменен диапазон значений координат перемещений.
- # Автор предлагает использовать -32768...32767, но семерка почему-то не хочет работать
- # с отрицательными значениями координат, как не хочет хавать 65536 и 32768.
- # Так что мы ей скармливаем диапазон 0...32767, и передаем рукожопам из микрософта привет,
- # потому что линуксы прекрасно работают с любыми двухбайтовыми диапазонами.
-
- # Absolute mouse
- 0x05, 0x01, # USAGE_PAGE (Generic Desktop)
- 0x09, 0x02, # USAGE (Mouse)
- 0xA1, 0x01, # COLLECTION (Application)
-
- # 8 Buttons
- 0x05, 0x09, # USAGE_PAGE (Button)
- 0x19, 0x01, # USAGE_MINIMUM (Button 1)
- 0x29, 0x08, # USAGE_MAXIMUM (Button 8)
- 0x15, 0x00, # LOGICAL_MINIMUM (0)
- 0x25, 0x01, # LOGICAL_MAXIMUM (1)
- 0x95, 0x08, # REPORT_COUNT (8)
- 0x75, 0x01, # REPORT_SIZE (1)
- 0x81, 0x02, # INPUT (Data,Var,Abs)
-
- # X, Y
- 0x05, 0x01, # USAGE_PAGE (Generic Desktop)
- 0x09, 0x30, # USAGE (X)
- 0x09, 0x31, # USAGE (Y)
- 0x16, 0x00, 0x00, # LOGICAL_MINIMUM (0)
- 0x26, 0xFF, 0x7F, # LOGICAL_MAXIMUM (32767)
- 0x75, 0x10, # REPORT_SIZE (16)
- 0x95, 0x02, # REPORT_COUNT (2)
- 0x81, 0x02, # INPUT (Data,Var,Abs)
-
- # Wheel
- 0x09, 0x38, # USAGE (Wheel)
- 0x15, 0x81, # LOGICAL_MINIMUM (-127)
- 0x25, 0x7F, # LOGICAL_MAXIMUM (127)
- 0x75, 0x08, # REPORT_SIZE (8)
- 0x95, 0x01, # REPORT_COUNT (1)
- 0x81, 0x06, # INPUT (Data,Var,Rel)
-
- # Horizontal wheel
- 0x05, 0x0C, # USAGE PAGE (Consumer Devices)
- 0x0A, 0x38, 0x02, # USAGE (AC Pan)
- 0x15, 0x81, # LOGICAL_MINIMUM (-127)
- 0x25, 0x7F, # LOGICAL_MAXIMUM (127)
- 0x75, 0x08, # REPORT_SIZE (8)
- 0x95, 0x01, # REPORT_COUNT (1)
- 0x81, 0x06, # INPUT (Data,Var,Rel)
-
- # End
- 0xC0, # END_COLLECTION
- ]),
-)
-
-MOUSE_RELATIVE_HID = Hid(
- protocol=2, # Mouse protocol
- subclass=1, # Boot interface subclass
-
- report_length=5,
-
- report_descriptor=bytes([
- # https://github.com/NicoHood/HID/blob/0835e6a/src/SingleReport/BootMouse.cpp
-
- # Relative mouse
- 0x05, 0x01, # USAGE_PAGE (Generic Desktop)
- 0x09, 0x02, # USAGE (Mouse)
- 0xA1, 0x01, # COLLECTION (Application)
-
- # 8 Buttons
- 0x05, 0x09, # USAGE_PAGE (Button)
- 0x19, 0x01, # USAGE_MINIMUM (Button 1)
- 0x29, 0x08, # USAGE_MAXIMUM (Button 8)
- 0x15, 0x00, # LOGICAL_MINIMUM (0)
- 0x25, 0x01, # LOGICAL_MAXIMUM (1)
- 0x95, 0x08, # REPORT_COUNT (8)
- 0x75, 0x01, # REPORT_SIZE (1)
- 0x81, 0x02, # INPUT (Data,Var,Abs)
-
- # X, Y
- 0x05, 0x01, # USAGE_PAGE (Generic Desktop)
- 0x09, 0x30, # USAGE (X)
- 0x09, 0x31, # USAGE (Y)
-
- # Wheel
- 0x09, 0x38, # USAGE (Wheel)
- 0x15, 0x81, # LOGICAL_MINIMUM (-127)
- 0x25, 0x7F, # LOGICAL_MAXIMUM (127)
- 0x75, 0x08, # REPORT_SIZE (8)
- 0x95, 0x03, # REPORT_COUNT (3)
- 0x81, 0x06, # INPUT (Data,Var,Rel)
-
- # Horizontal wheel
- 0x05, 0x0C, # USAGE PAGE (Consumer Devices)
- 0x0A, 0x38, 0x02, # USAGE (AC Pan)
- 0x15, 0x81, # LOGICAL_MINIMUM (-127)
- 0x25, 0x7F, # LOGICAL_MAXIMUM (127)
- 0x75, 0x08, # REPORT_SIZE (8)
- 0x95, 0x01, # REPORT_COUNT (1)
- 0x81, 0x06, # INPUT (Data,Var,Rel)
-
- # End
- 0xC0, # END_COLLECTION
- ]),
-)
+def make_mouse_hid(absolute: bool, horizontal_wheel: bool) -> Hid:
+ maker = (_make_absolute_hid if absolute else _make_relative_hid)
+ return maker(horizontal_wheel)
+
+
+_HORIZONTAL_WHEEL = [
+ 0x05, 0x0C, # USAGE PAGE (Consumer Devices)
+ 0x0A, 0x38, 0x02, # USAGE (AC Pan)
+ 0x15, 0x81, # LOGICAL_MINIMUM (-127)
+ 0x25, 0x7F, # LOGICAL_MAXIMUM (127)
+ 0x75, 0x08, # REPORT_SIZE (8)
+ 0x95, 0x01, # REPORT_COUNT (1)
+ 0x81, 0x06, # INPUT (Data,Var,Rel)
+]
+
+
+def _make_absolute_hid(horizontal_wheel: bool) -> Hid:
+ return Hid(
+ protocol=0, # None protocol
+ subclass=0, # No subclass
+
+ report_length=(7 if horizontal_wheel else 6),
+
+ report_descriptor=bytes([
+ # https://github.com/NicoHood/HID/blob/0835e6a/src/SingleReport/SingleAbsoluteMouse.cpp
+ # Репорт взят отсюда ^^^, но изменен диапазон значений координат перемещений.
+ # Автор предлагает использовать -32768...32767, но семерка почему-то не хочет работать
+ # с отрицательными значениями координат, как не хочет хавать 65536 и 32768.
+ # Так что мы ей скармливаем диапазон 0...32767, и передаем рукожопам из микрософта привет,
+ # потому что линуксы прекрасно работают с любыми двухбайтовыми диапазонами.
+
+ # Absolute mouse
+ 0x05, 0x01, # USAGE_PAGE (Generic Desktop)
+ 0x09, 0x02, # USAGE (Mouse)
+ 0xA1, 0x01, # COLLECTION (Application)
+
+ # 8 Buttons
+ 0x05, 0x09, # USAGE_PAGE (Button)
+ 0x19, 0x01, # USAGE_MINIMUM (Button 1)
+ 0x29, 0x08, # USAGE_MAXIMUM (Button 8)
+ 0x15, 0x00, # LOGICAL_MINIMUM (0)
+ 0x25, 0x01, # LOGICAL_MAXIMUM (1)
+ 0x95, 0x08, # REPORT_COUNT (8)
+ 0x75, 0x01, # REPORT_SIZE (1)
+ 0x81, 0x02, # INPUT (Data,Var,Abs)
+
+ # X, Y
+ 0x05, 0x01, # USAGE_PAGE (Generic Desktop)
+ 0x09, 0x30, # USAGE (X)
+ 0x09, 0x31, # USAGE (Y)
+ 0x16, 0x00, 0x00, # LOGICAL_MINIMUM (0)
+ 0x26, 0xFF, 0x7F, # LOGICAL_MAXIMUM (32767)
+ 0x75, 0x10, # REPORT_SIZE (16)
+ 0x95, 0x02, # REPORT_COUNT (2)
+ 0x81, 0x02, # INPUT (Data,Var,Abs)
+
+ # Wheel
+ 0x09, 0x38, # USAGE (Wheel)
+ 0x15, 0x81, # LOGICAL_MINIMUM (-127)
+ 0x25, 0x7F, # LOGICAL_MAXIMUM (127)
+ 0x75, 0x08, # REPORT_SIZE (8)
+ 0x95, 0x01, # REPORT_COUNT (1)
+ 0x81, 0x06, # INPUT (Data,Var,Rel)
+
+ *(_HORIZONTAL_WHEEL if horizontal_wheel else []),
+
+ # End
+ 0xC0, # END_COLLECTION
+ ]),
+ )
+
+
+def _make_relative_hid(horizontal_wheel: bool) -> Hid:
+ return Hid(
+ protocol=2, # Mouse protocol
+ subclass=1, # Boot interface subclass
+
+ report_length=(5 if horizontal_wheel else 4),
+
+ report_descriptor=bytes([
+ # https://github.com/NicoHood/HID/blob/0835e6a/src/SingleReport/BootMouse.cpp
+
+ # Relative mouse
+ 0x05, 0x01, # USAGE_PAGE (Generic Desktop)
+ 0x09, 0x02, # USAGE (Mouse)
+ 0xA1, 0x01, # COLLECTION (Application)
+
+ # 8 Buttons
+ 0x05, 0x09, # USAGE_PAGE (Button)
+ 0x19, 0x01, # USAGE_MINIMUM (Button 1)
+ 0x29, 0x08, # USAGE_MAXIMUM (Button 8)
+ 0x15, 0x00, # LOGICAL_MINIMUM (0)
+ 0x25, 0x01, # LOGICAL_MAXIMUM (1)
+ 0x95, 0x08, # REPORT_COUNT (8)
+ 0x75, 0x01, # REPORT_SIZE (1)
+ 0x81, 0x02, # INPUT (Data,Var,Abs)
+
+ # X, Y
+ 0x05, 0x01, # USAGE_PAGE (Generic Desktop)
+ 0x09, 0x30, # USAGE (X)
+ 0x09, 0x31, # USAGE (Y)
+
+ # Wheel
+ 0x09, 0x38, # USAGE (Wheel)
+ 0x15, 0x81, # LOGICAL_MINIMUM (-127)
+ 0x25, 0x7F, # LOGICAL_MAXIMUM (127)
+ 0x75, 0x08, # REPORT_SIZE (8)
+ 0x95, 0x03, # REPORT_COUNT (3)
+ 0x81, 0x06, # INPUT (Data,Var,Rel)
+
+ *(_HORIZONTAL_WHEEL if horizontal_wheel else []),
+
+ # End
+ 0xC0, # END_COLLECTION
+ ]),
+ )