Skip to content

Commit

Permalink
console: allow sending a single command to the device.
Browse files Browse the repository at this point in the history
This avoids having to open the session and makes scripting a lot easier
particularly when changing the settings of the device and needing a
restart to continue.
  • Loading branch information
Flameeyes committed Aug 3, 2023
1 parent 5db2266 commit a0fecb4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions freestyle_hid/tools/hid_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
callback=lambda ctx, param, value: pathlib.Path(value) if value else None,
required=False,
)
@click.argument(
"command",
type=str,
required=False,
)
def main(
*,
text_command_type: int,
Expand All @@ -68,6 +73,7 @@ def main(
device_path: Optional[pathlib.Path],
encoding: str,
encrypted_protocol: bool,
command: Optional[str],
):
if not product_id and not device_path:
raise click.UsageError(
Expand All @@ -85,6 +91,14 @@ def main(

session.connect()

if command is not None:
try:
print(session.send_text_command(bytes(command, "ascii")))
except freestyle_hid.CommandError as error:
print(f"! {error!r}")

return

while True:
if sys.stdin.isatty():
command = input(">>> ")
Expand Down

0 comments on commit a0fecb4

Please sign in to comment.