mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
configurable wheel for otg
This commit is contained in:
parent
544f4b3fec
commit
c31115051c
@ -42,9 +42,8 @@ from ... import env
|
||||
from .. import init
|
||||
|
||||
from .hid import Hid
|
||||
from .hid.keyboard import KEYBOARD_HID
|
||||
from .hid.mouse import MOUSE_ABSOLUTE_HID
|
||||
from .hid.mouse import MOUSE_RELATIVE_HID
|
||||
from .hid.keyboard import make_keyboard_hid
|
||||
from .hid.mouse import make_mouse_hid
|
||||
|
||||
|
||||
# =====
|
||||
@ -203,11 +202,11 @@ def _cmd_start(config: Section) -> None:
|
||||
|
||||
if config.kvmd.hid.type == "otg":
|
||||
logger.info("===== Required HID =====")
|
||||
_create_hid(gadget_path, config_path, 0, KEYBOARD_HID)
|
||||
if config.kvmd.hid.mouse.absolute:
|
||||
_create_hid(gadget_path, config_path, 1, MOUSE_ABSOLUTE_HID)
|
||||
else:
|
||||
_create_hid(gadget_path, config_path, 1, MOUSE_RELATIVE_HID)
|
||||
_create_hid(gadget_path, config_path, 0, make_keyboard_hid())
|
||||
_create_hid(gadget_path, config_path, 1, make_mouse_hid(
|
||||
absolute=config.kvmd.hid.mouse.absolute,
|
||||
horizontal_wheel=config.kvmd.hid.mouse.horizontal_wheel,
|
||||
))
|
||||
|
||||
if config.kvmd.msd.type == "otg":
|
||||
logger.info("===== Required MSD =====")
|
||||
|
||||
@ -24,7 +24,8 @@ from . import Hid
|
||||
|
||||
|
||||
# =====
|
||||
KEYBOARD_HID = Hid(
|
||||
def make_keyboard_hid() -> Hid:
|
||||
return Hid(
|
||||
protocol=1, # Keyboard protocol
|
||||
subclass=1, # Boot interface subclass
|
||||
|
||||
@ -79,4 +80,4 @@ KEYBOARD_HID = Hid(
|
||||
|
||||
0xC0, # END_COLLECTION
|
||||
]),
|
||||
)
|
||||
)
|
||||
|
||||
@ -24,11 +24,28 @@ from . import Hid
|
||||
|
||||
|
||||
# =====
|
||||
MOUSE_ABSOLUTE_HID = Hid(
|
||||
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,
|
||||
report_length=(7 if horizontal_wheel else 6),
|
||||
|
||||
report_descriptor=bytes([
|
||||
# https://github.com/NicoHood/HID/blob/0835e6a/src/SingleReport/SingleAbsoluteMouse.cpp
|
||||
@ -71,25 +88,20 @@ MOUSE_ABSOLUTE_HID = Hid(
|
||||
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)
|
||||
*(_HORIZONTAL_WHEEL if horizontal_wheel else []),
|
||||
|
||||
# End
|
||||
0xC0, # END_COLLECTION
|
||||
]),
|
||||
)
|
||||
)
|
||||
|
||||
MOUSE_RELATIVE_HID = Hid(
|
||||
|
||||
def _make_relative_hid(horizontal_wheel: bool) -> Hid:
|
||||
return Hid(
|
||||
protocol=2, # Mouse protocol
|
||||
subclass=1, # Boot interface subclass
|
||||
|
||||
report_length=5,
|
||||
report_length=(5 if horizontal_wheel else 4),
|
||||
|
||||
report_descriptor=bytes([
|
||||
# https://github.com/NicoHood/HID/blob/0835e6a/src/SingleReport/BootMouse.cpp
|
||||
@ -122,16 +134,9 @@ MOUSE_RELATIVE_HID = Hid(
|
||||
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)
|
||||
*(_HORIZONTAL_WHEEL if horizontal_wheel else []),
|
||||
|
||||
# End
|
||||
0xC0, # END_COLLECTION
|
||||
]),
|
||||
)
|
||||
)
|
||||
|
||||
@ -76,6 +76,7 @@ class Plugin(BaseHid):
|
||||
"write_retries_delay": Option(0.1, type=valid_float_f01),
|
||||
"reopen_delay": Option(0.5, type=valid_float_f01),
|
||||
"absolute": Option(True, type=valid_bool),
|
||||
"horizontal_wheel": Option(True, type=valid_bool),
|
||||
},
|
||||
"noop": Option(False, type=valid_bool),
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ class _WheelEvent(BaseEvent):
|
||||
class MouseProcess(BaseDeviceProcess):
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
self.__absolute: bool = kwargs.pop("absolute")
|
||||
self.__horizontal_wheel: bool = kwargs.pop("horizontal_wheel")
|
||||
|
||||
super().__init__(
|
||||
name="mouse",
|
||||
@ -212,4 +213,7 @@ class MouseProcess(BaseDeviceProcess):
|
||||
def __make_report(self, buttons: int, move_x: int, move_y: int, wheel_x: int, wheel_y: int) -> bytes:
|
||||
# XXX: Wheel Y before X: it's ok.
|
||||
# See /kvmd/apps/otg/hid/mouse.py for details
|
||||
if self.__horizontal_wheel:
|
||||
return struct.pack(("<BHHbb" if self.__absolute else "<Bbbbb"), buttons, move_x, move_y, wheel_y, wheel_x)
|
||||
else:
|
||||
return struct.pack(("<BHHb" if self.__absolute else "<Bbbb"), buttons, move_x, move_y, wheel_y)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user