mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 09:01:54 +08:00
only available gpio modes
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
# ========================================================================== #
|
||||
|
||||
|
||||
from typing import Set
|
||||
from typing import Type
|
||||
from typing import Optional
|
||||
from typing import Any
|
||||
@@ -46,6 +47,14 @@ class GpioDriverOfflineError(GpioOperationError):
|
||||
super().__init__(f"GPIO driver {driver} is offline")
|
||||
|
||||
|
||||
# =====
|
||||
class UserGpioModes:
|
||||
INPUT = "input"
|
||||
OUTPUT = "output"
|
||||
|
||||
ALL = set([INPUT, OUTPUT])
|
||||
|
||||
|
||||
# =====
|
||||
class BaseUserGpioDriver(BasePlugin):
|
||||
def __init__( # pylint: disable=super-init-not-called
|
||||
@@ -61,6 +70,10 @@ class BaseUserGpioDriver(BasePlugin):
|
||||
def get_instance_id(self) -> str:
|
||||
return self._instance_name
|
||||
|
||||
@classmethod
|
||||
def get_modes(cls) -> Set[str]:
|
||||
return set(UserGpioModes.ALL)
|
||||
|
||||
def register_input(self, pin: int) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import asyncio
|
||||
import contextlib
|
||||
|
||||
from typing import Dict
|
||||
from typing import Set
|
||||
from typing import Optional
|
||||
|
||||
import hid
|
||||
@@ -39,6 +40,7 @@ from ...validators.basic import valid_float_f01
|
||||
from ...validators.os import valid_abs_path
|
||||
|
||||
from . import GpioDriverOfflineError
|
||||
from . import UserGpioModes
|
||||
from . import BaseUserGpioDriver
|
||||
|
||||
|
||||
@@ -73,8 +75,12 @@ class Plugin(BaseUserGpioDriver):
|
||||
"state_poll": Option(5.0, type=valid_float_f01),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_modes(cls) -> Set[str]:
|
||||
return set([UserGpioModes.OUTPUT])
|
||||
|
||||
def register_input(self, pin: int) -> None:
|
||||
_ = pin
|
||||
raise RuntimeError(f"Unsupported mode 'input' for pin={pin} on {self}")
|
||||
|
||||
def register_output(self, pin: int, initial: Optional[bool]) -> None:
|
||||
self.__initials[pin] = initial
|
||||
@@ -153,7 +159,7 @@ class Plugin(BaseUserGpioDriver):
|
||||
def __check_pin(self, pin: int) -> bool:
|
||||
ok = (0 <= pin <= 7)
|
||||
if not ok:
|
||||
get_logger(0).warning("Unsupported pin for %s on %s: %d", self, self.__device_path, pin)
|
||||
get_logger(0).warning("Unsupported pin=%d for %s on %s", pin, self, self.__device_path)
|
||||
return ok
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
||||
Reference in New Issue
Block a user