mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
optional serial number
This commit is contained in:
parent
ae4509f234
commit
e83764c501
@ -488,9 +488,9 @@ def _get_config_scheme() -> Dict:
|
|||||||
"otg": {
|
"otg": {
|
||||||
"vendor_id": Option(0x1D6B, type=valid_otg_id), # Linux Foundation
|
"vendor_id": Option(0x1D6B, type=valid_otg_id), # Linux Foundation
|
||||||
"product_id": Option(0x0104, type=valid_otg_id), # Multifunction Composite Gadget
|
"product_id": Option(0x0104, type=valid_otg_id), # Multifunction Composite Gadget
|
||||||
"manufacturer": Option("PiKVM"),
|
"manufacturer": Option("PiKVM", type=valid_stripped_string),
|
||||||
"product": Option("Composite KVM Device"),
|
"product": Option("Composite KVM Device", type=valid_stripped_string),
|
||||||
"serial": Option("CAFEBABE"),
|
"serial": Option("CAFEBABE", type=valid_stripped_string, if_none=None),
|
||||||
"device_version": Option(-1, type=functools.partial(valid_number, min=-1, max=0xFFFF)),
|
"device_version": Option(-1, type=functools.partial(valid_number, min=-1, max=0xFFFF)),
|
||||||
"usb_version": Option(0x0200, type=valid_otg_id),
|
"usb_version": Option(0x0200, type=valid_otg_id),
|
||||||
"max_power": Option(250, type=functools.partial(valid_number, min=50, max=500)),
|
"max_power": Option(250, type=functools.partial(valid_number, min=50, max=500)),
|
||||||
|
|||||||
@ -195,7 +195,7 @@ class _GadgetConfig:
|
|||||||
_write(join(self.__meta_path, f"{func}@meta.json"), json.dumps({"func": func, "name": name}))
|
_write(join(self.__meta_path, f"{func}@meta.json"), json.dumps({"func": func, "name": name}))
|
||||||
|
|
||||||
|
|
||||||
def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements
|
def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements,too-many-branches
|
||||||
# https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
|
# https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
|
||||||
# https://www.isticktoit.net/?p=1383
|
# https://www.isticktoit.net/?p=1383
|
||||||
|
|
||||||
@ -231,7 +231,8 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements
|
|||||||
_mkdir(lang_path)
|
_mkdir(lang_path)
|
||||||
_write(join(lang_path, "manufacturer"), config.otg.manufacturer)
|
_write(join(lang_path, "manufacturer"), config.otg.manufacturer)
|
||||||
_write(join(lang_path, "product"), config.otg.product)
|
_write(join(lang_path, "product"), config.otg.product)
|
||||||
_write(join(lang_path, "serialnumber"), config.otg.serial)
|
if config.otg.serial is not None:
|
||||||
|
_write(join(lang_path, "serialnumber"), config.otg.serial)
|
||||||
|
|
||||||
profile_path = join(gadget_path, usb.G_PROFILE)
|
profile_path = join(gadget_path, usb.G_PROFILE)
|
||||||
_mkdir(profile_path)
|
_mkdir(profile_path)
|
||||||
|
|||||||
@ -119,6 +119,7 @@ class Option:
|
|||||||
self,
|
self,
|
||||||
default: Any,
|
default: Any,
|
||||||
type: Optional[Callable[[Any], Any]]=None, # pylint: disable=redefined-builtin
|
type: Optional[Callable[[Any], Any]]=None, # pylint: disable=redefined-builtin
|
||||||
|
if_none: Any=Stub,
|
||||||
if_empty: Any=Stub,
|
if_empty: Any=Stub,
|
||||||
only_if: str="",
|
only_if: str="",
|
||||||
unpack_as: str="",
|
unpack_as: str="",
|
||||||
@ -127,6 +128,7 @@ class Option:
|
|||||||
|
|
||||||
self.default = default
|
self.default = default
|
||||||
self.type: Callable[[Any], Any] = (type or (self.__type(default) if default is not None else str)) # type: ignore
|
self.type: Callable[[Any], Any] = (type or (self.__type(default) if default is not None else str)) # type: ignore
|
||||||
|
self.if_none = if_none
|
||||||
self.if_empty = if_empty
|
self.if_empty = if_empty
|
||||||
self.only_if = only_if
|
self.only_if = only_if
|
||||||
self.unpack_as = unpack_as
|
self.unpack_as = unpack_as
|
||||||
@ -134,8 +136,8 @@ class Option:
|
|||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return (
|
return (
|
||||||
f"<Option(default={self.default}, type={self.type}, if_empty={self.if_empty},"
|
f"<Option(default={self.default}, type={self.type}, if_none={self.if_none},"
|
||||||
f" only_if={self.only_if}, unpack_as={self.unpack_as})>"
|
f" if_empty={self.if_empty}, only_if={self.only_if}, unpack_as={self.unpack_as})>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -179,7 +181,9 @@ def make_config(raw: Dict[str, Any], scheme: Dict[str, Any], _keys: Tuple[str, .
|
|||||||
value = option.default
|
value = option.default
|
||||||
else:
|
else:
|
||||||
value = raw.get(key, option.default)
|
value = raw.get(key, option.default)
|
||||||
if option.if_empty != Stub and not value:
|
if option.if_none != Stub and value is None:
|
||||||
|
value = option.if_none
|
||||||
|
elif option.if_empty != Stub and not value:
|
||||||
value = option.if_empty
|
value = option.if_empty
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user