@@ -23,12 +23,15 @@ def example_modify_existing():
2323 print (f"Available devices: { list (specs .keys ())} " )
2424
2525 # Get connected devices
26- connected = pyspacemouse .get_connected_devices ()
26+ connected = pyspacemouse .get_connected_devices_by_path ()
2727 if not connected :
2828 print ("No devices connected!" )
2929 return
30+ if len (connected ) > 1 :
31+ print ("This example only works with one device connected." )
32+ return
3033
31- device_name = connected [0 ]
34+ device_name = list ( connected . values ()) [0 ]
3235 print (f"Using device: { device_name } " )
3336
3437 # Get base spec and create modified version
@@ -49,11 +52,11 @@ def example_modify_existing():
4952 print ("Move the SpaceMouse (Ctrl+C to exit)" )
5053 print ("Y and Z axes are now inverted!\n " )
5154
52- for _ in range (50 ): # Run for ~5 seconds
55+ for _ in range (500 ): # Run for ~5 seconds
5356 state = device .read ()
54- if any ([ state .x , state . y , state . z ] ):
57+ if state .has_motion ( ):
5558 print (f"x={ state .x :+.2f} y={ state .y :+.2f} z={ state .z :+.2f} (Y/Z inverted)" )
56- time .sleep (0.1 )
59+ time .sleep (0.01 )
5760
5861
5962def example_invert_rotations ():
@@ -62,30 +65,34 @@ def example_invert_rotations():
6265 print ("Example 2: Fix rotation conventions" )
6366 print ("=" * 60 )
6467
65- connected = pyspacemouse .get_connected_devices ()
68+ connected = pyspacemouse .get_connected_devices_by_path ()
6669 if not connected :
6770 print ("No devices connected!" )
6871 return
72+ if len (connected ) > 1 :
73+ print ("This example only works with one device connected." )
74+ return
6975
76+ device_name = list (connected .values ())[0 ]
7077 specs = pyspacemouse .get_device_specs ()
71- base_spec = specs [connected [ 0 ] ]
78+ base_spec = specs [device_name ]
7279
7380 # Invert roll and yaw for right-handed coordinate system
7481 fixed_spec = pyspacemouse .modify_device_info (
7582 base_spec ,
76- name = f"{ connected [ 0 ] } (Fixed Rotations)" ,
83+ name = f"{ device_name } (Fixed Rotations)" ,
7784 invert_axes = ["roll" , "yaw" ],
7885 )
7986
8087 with pyspacemouse .open (device_spec = fixed_spec ) as device :
8188 print (f"Connected to: { device .name } " )
8289 print ("Roll and Yaw are now inverted!\n " )
8390
84- for _ in range (30 ):
91+ for _ in range (500 ):
8592 state = device .read ()
86- if any ([ state .roll , state . pitch , state . yaw ] ):
93+ if state .has_motion ( ):
8794 print (f"roll={ state .roll :+.2f} pitch={ state .pitch :+.2f} yaw={ state .yaw :+.2f} " )
88- time .sleep (0.1 )
95+ time .sleep (0.01 )
8996
9097
9198def example_create_custom ():
0 commit comments