mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
async gpio plugins
This commit is contained in:
@@ -89,10 +89,10 @@ class BaseUserGpioDriver(BasePlugin):
|
||||
def cleanup(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
def read(self, pin: int) -> bool:
|
||||
async def read(self, pin: int) -> bool:
|
||||
raise NotImplementedError
|
||||
|
||||
def write(self, pin: int, state: bool) -> None:
|
||||
async def write(self, pin: int, state: bool) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
||||
@@ -108,12 +108,12 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
||||
if self.__proc.exitcode is not None:
|
||||
self.__proc.join()
|
||||
|
||||
def read(self, pin: int) -> bool:
|
||||
async def read(self, pin: int) -> bool:
|
||||
if not self.__is_online():
|
||||
raise GpioDriverOfflineError(self)
|
||||
return (self.__channel == pin)
|
||||
|
||||
def write(self, pin: int, state: bool) -> None:
|
||||
async def write(self, pin: int, state: bool) -> None:
|
||||
if not self.__is_online():
|
||||
raise GpioDriverOfflineError(self)
|
||||
if state and (0 <= pin <= 3):
|
||||
|
||||
@@ -95,13 +95,13 @@ class Plugin(BaseUserGpioDriver):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def read(self, pin: int) -> bool:
|
||||
async def read(self, pin: int) -> bool:
|
||||
assert self.__reader
|
||||
if pin in self.__input_pins:
|
||||
return self.__reader.get(pin)
|
||||
return bool(self.__output_lines[pin].get_value())
|
||||
|
||||
def write(self, pin: int, state: bool) -> None:
|
||||
async def write(self, pin: int, state: bool) -> None:
|
||||
self.__output_lines[pin].set_value(int(state))
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
||||
@@ -113,13 +113,13 @@ class Plugin(BaseUserGpioDriver):
|
||||
self.__close_device()
|
||||
self.__stop = True
|
||||
|
||||
def read(self, pin: int) -> bool:
|
||||
async def read(self, pin: int) -> bool:
|
||||
try:
|
||||
return self.__inner_read(pin)
|
||||
except Exception:
|
||||
raise GpioDriverOfflineError(self)
|
||||
|
||||
def write(self, pin: int, state: bool) -> None:
|
||||
async def write(self, pin: int, state: bool) -> None:
|
||||
try:
|
||||
return self.__inner_write(pin, state)
|
||||
except Exception:
|
||||
|
||||
@@ -100,11 +100,11 @@ class Plugin(BaseUserGpioDriver):
|
||||
def cleanup(self) -> None:
|
||||
pass
|
||||
|
||||
def read(self, pin: int) -> bool:
|
||||
async def read(self, pin: int) -> bool:
|
||||
_ = pin
|
||||
return os.path.islink(self.__get_driver_path(self.__udc))
|
||||
|
||||
def write(self, pin: int, state: bool) -> None:
|
||||
async def write(self, pin: int, state: bool) -> None:
|
||||
_ = pin
|
||||
with open(self.__get_driver_path("bind" if state else "unbind"), "w") as ctl_file:
|
||||
ctl_file.write(f"{self.__udc}\n")
|
||||
|
||||
Reference in New Issue
Block a user