mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
hid set_connected api
This commit is contained in:
parent
4b6d7605c5
commit
edb967c633
@ -79,6 +79,11 @@ class HidApi:
|
|||||||
self.__hid.set_mouse_output(valid_hid_mouse_output(request.query.get("output")))
|
self.__hid.set_mouse_output(valid_hid_mouse_output(request.query.get("output")))
|
||||||
return make_json_response()
|
return make_json_response()
|
||||||
|
|
||||||
|
@exposed_http("POST", "/hid/set_connected")
|
||||||
|
async def __set_connected_handler(self, request: Request) -> Response:
|
||||||
|
self.__hid.set_connected(valid_bool(request.query.get("connected")))
|
||||||
|
return make_json_response()
|
||||||
|
|
||||||
@exposed_http("POST", "/hid/reset")
|
@exposed_http("POST", "/hid/reset")
|
||||||
async def __reset_handler(self, _: Request) -> Response:
|
async def __reset_handler(self, _: Request) -> Response:
|
||||||
await self.__hid.reset()
|
await self.__hid.reset()
|
||||||
|
|||||||
@ -73,6 +73,9 @@ class BaseHid(BasePlugin):
|
|||||||
def set_mouse_output(self, output: str) -> None:
|
def set_mouse_output(self, output: str) -> None:
|
||||||
_ = output
|
_ = output
|
||||||
|
|
||||||
|
def set_connected(self, connected: bool) -> None:
|
||||||
|
_ = connected
|
||||||
|
|
||||||
def clear_events(self) -> None:
|
def clear_events(self) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|||||||
@ -58,6 +58,7 @@ from .proto import RESPONSE_LEGACY_OK
|
|||||||
from .proto import BaseEvent
|
from .proto import BaseEvent
|
||||||
from .proto import SetKeyboardOutputEvent
|
from .proto import SetKeyboardOutputEvent
|
||||||
from .proto import SetMouseOutputEvent
|
from .proto import SetMouseOutputEvent
|
||||||
|
from .proto import SetConnectedEvent
|
||||||
from .proto import ClearEvent
|
from .proto import ClearEvent
|
||||||
from .proto import KeyEvent
|
from .proto import KeyEvent
|
||||||
from .proto import MouseButtonEvent
|
from .proto import MouseButtonEvent
|
||||||
@ -166,27 +167,27 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
|
|||||||
state = await self.__state_flags.get()
|
state = await self.__state_flags.get()
|
||||||
online = bool(state["online"])
|
online = bool(state["online"])
|
||||||
pong = (state["status"] >> 16) & 0xFF
|
pong = (state["status"] >> 16) & 0xFF
|
||||||
outputs = (state["status"] >> 8) & 0xFF
|
outputs1 = (state["status"] >> 8) & 0xFF
|
||||||
features = state["status"] & 0xFF
|
outputs2 = state["status"] & 0xFF
|
||||||
|
|
||||||
absolute = True
|
absolute = True
|
||||||
active_mouse = get_active_mouse(outputs)
|
active_mouse = get_active_mouse(outputs1)
|
||||||
if online and active_mouse in ["usb_rel", "ps2"]:
|
if online and active_mouse in ["usb_rel", "ps2"]:
|
||||||
absolute = False
|
absolute = False
|
||||||
|
|
||||||
keyboard_outputs: Dict = {"available": [], "active": ""}
|
keyboard_outputs: Dict = {"available": [], "active": ""}
|
||||||
mouse_outputs: Dict = {"available": [], "active": ""}
|
mouse_outputs: Dict = {"available": [], "active": ""}
|
||||||
|
|
||||||
if outputs & 0b10000000: # Dynamic
|
if outputs1 & 0b10000000: # Dynamic
|
||||||
if features & 0b00000001: # USB
|
if outputs2 & 0b00000001: # USB
|
||||||
keyboard_outputs["available"].extend(["usb"])
|
keyboard_outputs["available"].extend(["usb"])
|
||||||
mouse_outputs["available"].extend(["usb", "usb_rel"])
|
mouse_outputs["available"].extend(["usb", "usb_rel"])
|
||||||
|
|
||||||
if features & 0b00000010: # PS/2
|
if outputs2 & 0b00000010: # PS/2
|
||||||
keyboard_outputs["available"].extend(["ps2"])
|
keyboard_outputs["available"].extend(["ps2"])
|
||||||
mouse_outputs["available"].extend(["ps2"])
|
mouse_outputs["available"].extend(["ps2"])
|
||||||
|
|
||||||
active_keyboard = get_active_keyboard(outputs)
|
active_keyboard = get_active_keyboard(outputs1)
|
||||||
if active_keyboard in keyboard_outputs["available"]:
|
if active_keyboard in keyboard_outputs["available"]:
|
||||||
keyboard_outputs["active"] = active_keyboard
|
keyboard_outputs["active"] = active_keyboard
|
||||||
|
|
||||||
@ -196,6 +197,7 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
|
|||||||
return {
|
return {
|
||||||
"online": online,
|
"online": online,
|
||||||
"busy": bool(state["busy"]),
|
"busy": bool(state["busy"]),
|
||||||
|
"connected": (bool(outputs2 & 0b01000000) if outputs2 & 0b10000000 else None),
|
||||||
"keyboard": {
|
"keyboard": {
|
||||||
"online": (online and not (pong & 0b00001000)),
|
"online": (online and not (pong & 0b00001000)),
|
||||||
"leds": {
|
"leds": {
|
||||||
@ -256,6 +258,9 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
|
|||||||
def set_mouse_output(self, output: str) -> None:
|
def set_mouse_output(self, output: str) -> None:
|
||||||
self.__queue_event(SetMouseOutputEvent(output), clear=True)
|
self.__queue_event(SetMouseOutputEvent(output), clear=True)
|
||||||
|
|
||||||
|
def set_connected(self, connected: bool) -> None:
|
||||||
|
self.__queue_event(SetConnectedEvent(connected), clear=True)
|
||||||
|
|
||||||
def clear_events(self) -> None:
|
def clear_events(self) -> None:
|
||||||
self.__queue_event(ClearEvent(), clear=True)
|
self.__queue_event(ClearEvent(), clear=True)
|
||||||
|
|
||||||
|
|||||||
@ -82,6 +82,15 @@ class SetMouseOutputEvent(BaseEvent):
|
|||||||
return _make_request(struct.pack(">BBxxx", 0x04, _MOUSE_NAMES_TO_CODES.get(self.mouse, 0)))
|
return _make_request(struct.pack(">BBxxx", 0x04, _MOUSE_NAMES_TO_CODES.get(self.mouse, 0)))
|
||||||
|
|
||||||
|
|
||||||
|
# =====
|
||||||
|
@dataclasses.dataclass(frozen=True)
|
||||||
|
class SetConnectedEvent(BaseEvent):
|
||||||
|
connected: bool
|
||||||
|
|
||||||
|
def make_request(self) -> bytes:
|
||||||
|
return _make_request(struct.pack(">BBxxx", 0x05, int(self.connected)))
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
class ClearEvent(BaseEvent):
|
class ClearEvent(BaseEvent):
|
||||||
def make_request(self) -> bytes:
|
def make_request(self) -> bytes:
|
||||||
|
|||||||
@ -134,6 +134,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
|||||||
return {
|
return {
|
||||||
"online": True,
|
"online": True,
|
||||||
"busy": False,
|
"busy": False,
|
||||||
|
"connected": None,
|
||||||
"keyboard": {
|
"keyboard": {
|
||||||
"online": state["online"],
|
"online": state["online"],
|
||||||
"leds": {
|
"leds": {
|
||||||
|
|||||||
@ -93,6 +93,7 @@ class Plugin(BaseHid):
|
|||||||
return {
|
return {
|
||||||
"online": True,
|
"online": True,
|
||||||
"busy": False,
|
"busy": False,
|
||||||
|
"connected": None,
|
||||||
"keyboard": {
|
"keyboard": {
|
||||||
"online": keyboard_state["online"],
|
"online": keyboard_state["online"],
|
||||||
"leds": {
|
"leds": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user