Compatibility with old vanilla kernels (#88)

This commit is contained in:
Frank Zhang 2022-05-24 21:05:49 +08:00 committed by GitHub
parent 628d25cb87
commit d722c3fff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,8 +78,11 @@ def _unlink(path: str, optional: bool=False) -> None:
os.unlink(path)
def _write(path: str, value: Union[str, int]) -> None:
def _write(path: str, value: Union[str, int], optional: bool=False) -> None:
get_logger().info("WRITE --- %s", path)
if optional and not os.access(path, os.F_OK):
get_logger().info("SKIP ---- %s", path)
return
with open(path, "w") as param_file:
param_file.write(str(value))
@ -158,9 +161,9 @@ class _GadgetConfig:
func = f"hid.usb{self.__hid_instance}"
func_path = join(self.__gadget_path, "functions", func)
_mkdir(func_path)
_write(join(func_path, "no_out_endpoint"), "1")
_write(join(func_path, "no_out_endpoint"), "1", optional=True)
if remote_wakeup:
_write(join(func_path, "wakeup_on_write"), "1")
_write(join(func_path, "wakeup_on_write"), "1", optional=True)
_write(join(func_path, "protocol"), hid.protocol)
_write(join(func_path, "subclass"), hid.subclass)
_write(join(func_path, "report_length"), hid.report_length)