mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
relay msd fixes
This commit is contained in:
parent
440f71d5a0
commit
06040c8da9
@ -38,6 +38,7 @@ from .... import aiofs
|
|||||||
|
|
||||||
from ....yamlconf import Option
|
from ....yamlconf import Option
|
||||||
|
|
||||||
|
from ....validators.basic import valid_bool
|
||||||
from ....validators.basic import valid_int_f1
|
from ....validators.basic import valid_int_f1
|
||||||
from ....validators.basic import valid_float_f01
|
from ....validators.basic import valid_float_f01
|
||||||
from ....validators.os import valid_abs_path
|
from ....validators.os import valid_abs_path
|
||||||
@ -64,6 +65,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
self,
|
self,
|
||||||
gpio_device_path: str,
|
gpio_device_path: str,
|
||||||
target_pin: int,
|
target_pin: int,
|
||||||
|
reset_inverted: bool,
|
||||||
reset_pin: int,
|
reset_pin: int,
|
||||||
|
|
||||||
device_path: str,
|
device_path: str,
|
||||||
@ -76,7 +78,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
self.__init_delay = init_delay
|
self.__init_delay = init_delay
|
||||||
self.__init_retries = init_retries
|
self.__init_retries = init_retries
|
||||||
|
|
||||||
self.__gpio = Gpio(gpio_device_path, target_pin, reset_pin, reset_delay)
|
self.__gpio = Gpio(gpio_device_path, target_pin, reset_pin, reset_inverted, reset_delay)
|
||||||
|
|
||||||
self.__device_info: Optional[DeviceInfo] = None
|
self.__device_info: Optional[DeviceInfo] = None
|
||||||
self.__connected = False
|
self.__connected = False
|
||||||
@ -87,20 +89,13 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
self.__notifier = aiotools.AioNotifier()
|
self.__notifier = aiotools.AioNotifier()
|
||||||
self.__region = aiotools.AioExclusiveRegion(MsdIsBusyError, self.__notifier)
|
self.__region = aiotools.AioExclusiveRegion(MsdIsBusyError, self.__notifier)
|
||||||
|
|
||||||
logger = get_logger(0)
|
|
||||||
logger.info("Using %r as MSD", self.__device_path)
|
|
||||||
try:
|
|
||||||
aiotools.run_sync(self.__load_device_info())
|
|
||||||
except Exception as err:
|
|
||||||
log = (logger.error if isinstance(err, MsdError) else logger.exception)
|
|
||||||
log("MSD is offline: %s", err)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_plugin_options(cls) -> Dict:
|
def get_plugin_options(cls) -> Dict:
|
||||||
return {
|
return {
|
||||||
"gpio_device": Option("/dev/gpiochip0", type=valid_abs_path, unpack_as="gpio_device_path"),
|
"gpio_device": Option("/dev/gpiochip0", type=valid_abs_path, unpack_as="gpio_device_path"),
|
||||||
"target_pin": Option(-1, type=valid_gpio_pin),
|
"target_pin": Option(-1, type=valid_gpio_pin),
|
||||||
"reset_pin": Option(-1, type=valid_gpio_pin),
|
"reset_pin": Option(-1, type=valid_gpio_pin),
|
||||||
|
"reset_inverted": Option(False, type=valid_bool),
|
||||||
|
|
||||||
"device": Option("", type=valid_abs_path, unpack_as="device_path"),
|
"device": Option("", type=valid_abs_path, unpack_as="device_path"),
|
||||||
"init_delay": Option(1.0, type=valid_float_f01),
|
"init_delay": Option(1.0, type=valid_float_f01),
|
||||||
@ -109,7 +104,14 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
}
|
}
|
||||||
|
|
||||||
def sysprep(self) -> None:
|
def sysprep(self) -> None:
|
||||||
|
logger = get_logger(0)
|
||||||
self.__gpio.open()
|
self.__gpio.open()
|
||||||
|
logger.info("Using %r as MSD", self.__device_path)
|
||||||
|
try:
|
||||||
|
aiotools.run_sync(self.__load_device_info())
|
||||||
|
except Exception as err:
|
||||||
|
log = (logger.error if isinstance(err, MsdError) else logger.exception)
|
||||||
|
log("MSD is offline: %s", err)
|
||||||
|
|
||||||
async def get_state(self) -> Dict:
|
async def get_state(self) -> Dict:
|
||||||
storage: Optional[Dict] = None
|
storage: Optional[Dict] = None
|
||||||
@ -243,10 +245,10 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
async def __write_image_info(self, name: str, complete: bool) -> None:
|
async def __write_image_info(self, name: str, complete: bool) -> None:
|
||||||
assert self.__device_file
|
assert self.__device_file
|
||||||
assert self.__device_info
|
assert self.__device_info
|
||||||
if not self.__device_info.write_image_info(
|
if not (await self.__device_info.write_image_info(
|
||||||
device_file=self.__device_file,
|
device_file=self.__device_file,
|
||||||
image_info=ImageInfo(name, self.__written, complete),
|
image_info=ImageInfo(name, self.__written, complete),
|
||||||
):
|
)):
|
||||||
get_logger().error("Can't write image info because device is full")
|
get_logger().error("Can't write image info because device is full")
|
||||||
|
|
||||||
async def __close_device_file(self) -> None:
|
async def __close_device_file(self) -> None:
|
||||||
|
|||||||
@ -28,18 +28,20 @@ from .... import aiogp
|
|||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
class Gpio:
|
class Gpio: # pylint: disable=too-many-instance-attributes
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
device_path: str,
|
device_path: str,
|
||||||
target_pin: int,
|
target_pin: int,
|
||||||
reset_pin: int,
|
reset_pin: int,
|
||||||
|
reset_inverted: bool,
|
||||||
reset_delay: float,
|
reset_delay: float,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
self.__device_path = device_path
|
self.__device_path = device_path
|
||||||
self.__target_pin = target_pin
|
self.__target_pin = target_pin
|
||||||
self.__reset_pin = reset_pin
|
self.__reset_pin = reset_pin
|
||||||
|
self.__reset_inverted = reset_inverted
|
||||||
self.__reset_delay = reset_delay
|
self.__reset_delay = reset_delay
|
||||||
|
|
||||||
self.__chip: Optional[gpiod.Chip] = None
|
self.__chip: Optional[gpiod.Chip] = None
|
||||||
@ -57,7 +59,7 @@ class Gpio:
|
|||||||
self.__target_line.request("kvmd::msd::target", gpiod.LINE_REQ_DIR_OUT, default_vals=[0])
|
self.__target_line.request("kvmd::msd::target", gpiod.LINE_REQ_DIR_OUT, default_vals=[0])
|
||||||
|
|
||||||
self.__reset_line = self.__chip.get_line(self.__reset_pin)
|
self.__reset_line = self.__chip.get_line(self.__reset_pin)
|
||||||
self.__reset_line.request("kvmd::msd::reset", gpiod.LINE_REQ_DIR_OUT, default_vals=[0])
|
self.__reset_line.request("kvmd::msd::reset", gpiod.LINE_REQ_DIR_OUT, default_vals=[int(self.__reset_inverted)])
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
if self.__chip:
|
if self.__chip:
|
||||||
@ -76,4 +78,4 @@ class Gpio:
|
|||||||
|
|
||||||
async def reset(self) -> None:
|
async def reset(self) -> None:
|
||||||
assert self.__reset_line
|
assert self.__reset_line
|
||||||
await aiogp.pulse(self.__reset_line, self.__reset_delay, 0)
|
await aiogp.pulse(self.__reset_line, self.__reset_delay, 0, self.__reset_inverted)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user