-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4833a85
commit 9941f2e
Showing
7 changed files
with
215 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import argparse | ||
import time | ||
|
||
from pyspacemouse import list_devices, list_available_devices, open as open_mouse, read as read_mouse, \ | ||
close as close_mouse, list_all_hid_devices | ||
from pkg_resources import get_distribution | ||
|
||
|
||
def print_version_cli(): | ||
distribution = get_distribution("pyspacemouse") | ||
print(f"pyspacemouse version {distribution.version}") | ||
|
||
|
||
def list_spacemouse_cli(): | ||
devices = list_devices() | ||
if devices: | ||
print("Connected SpaceMouse devices:") | ||
for device in devices: | ||
print(f"- {device}") | ||
else: | ||
print("Error: No connected SpaceMouse devices found.") | ||
|
||
def list_all_hid_devices_cli(): | ||
devices = list_all_hid_devices() | ||
if devices: | ||
print("All HID devices:") | ||
for (product_string, manufacturer_string, vendor_id, product_id) in devices: | ||
if product_string == "": | ||
product_string = "Unknown" | ||
if manufacturer_string == "": | ||
manufacturer_string = "Unknown" | ||
print(f"- {product_string} by {manufacturer_string} [VID: {hex(vendor_id)}, PID: {hex(product_id)}]") | ||
else: | ||
print("Error: No HID devices found.") | ||
|
||
def list_supported_devices_cli(): | ||
available_devices = list_available_devices() | ||
if available_devices: | ||
print("Available SpaceMouse devices:") | ||
for (device_name, vid_id, pid_id) in available_devices: | ||
print(f"- {device_name} [VID: {hex(vid_id)}, PID: {hex(pid_id)}]") | ||
else: | ||
print("Error: No available SpaceMouse devices found.") | ||
|
||
def test_connect_cli(): | ||
try: | ||
success = open_mouse() | ||
except Exception as e: | ||
print(f"Failed to open SpaceMouse: {e}") | ||
return | ||
|
||
if not success: | ||
print("Failed to open SpaceMouse") | ||
return | ||
|
||
print("SpaceMouse opened successfully, reading x, y, z values...") | ||
time.sleep(1) | ||
|
||
try: | ||
while True: | ||
state = read_mouse() | ||
print(state.x, state.y, state.z) | ||
time.sleep(0.01) | ||
except KeyboardInterrupt: | ||
print("KeyboardInterrupt: Exiting...") | ||
finally: | ||
close_mouse() | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="PySpaceMouse CLI", | ||
epilog="For more information, visit https://spacemouse.kubaandrysek.cz/") | ||
parser.add_argument( | ||
"--version", action="store_true", help="Version of pyspacemouse" | ||
) | ||
parser.add_argument( | ||
"--list-spacemouse", action="store_true", help="List connected SpaceMouse devices" | ||
) | ||
parser.add_argument( | ||
"--list-supported-devices", action="store_true", help="List supported SpaceMouse devices" | ||
) | ||
parser.add_argument( | ||
"--list-all-hid-devices", action="store_true", help="List all connected HID devices" | ||
) | ||
parser.add_argument( | ||
"--test-connect", action="store_true", help="Test connect to the first available device" | ||
) | ||
args = parser.parse_args() | ||
|
||
if args.version: | ||
print_version_cli() | ||
elif args.list_spacemouse: | ||
list_spacemouse_cli() | ||
elif args.list_supported_devices: | ||
list_supported_devices_cli() | ||
elif args.list_all_hid_devices: | ||
list_all_hid_devices_cli() | ||
elif args.test_connect: | ||
test_connect_cli() | ||
else: | ||
parser.print_help() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters