Skip to content

Commit bc53cf0

Browse files
committed
Updated command line options
Added two command line options (smooth aggressiveness and smooth falloff) and updated the help option.
1 parent bc2d590 commit bc53cf0

File tree

4 files changed

+49
-16
lines changed

4 files changed

+49
-16
lines changed

FingerControl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515

1616
class Finger_Control_Listener(Leap.Listener): #The Listener that we attach to the controller. This listener is for pointer finger movement
17-
def __init__(self, mouse):
17+
def __init__(self, mouse, smooth_aggressiveness=8, smooth_falloff=1.3):
1818
super(Finger_Control_Listener, self).__init__() #Initialize like a normal listener
1919
#Initialize a bunch of stuff specific to this implementation
2020
self.screen = None
2121
self.screen_resolution = (0,0)
2222
self.cursor = mouse.absolute_cursor() #The cursor object that lets us control mice cross-platform
23-
self.mouse_position_smoother = mouse_position_smoother() #Keeps the cursor from fidgeting
23+
self.mouse_position_smoother = mouse_position_smoother(smooth_aggressiveness, smooth_falloff) #Keeps the cursor from fidgeting
2424
self.mouse_button_debouncer = debouncer(5) #A signal debouncer that ensures a reliable, non-jumpy click
2525
self.most_recent_pointer_finger_id = None #This holds the ID of the most recently used pointing finger, to prevent annoying switching
2626

MiscFunctions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313

1414
#Smooths the mouse's position
1515
class mouse_position_smoother(object):
16-
def __init__(self, smooth_aggressiveness=8, smooth_falloff=1.3):
16+
def __init__(self, smooth_aggressiveness, smooth_falloff):
17+
#Input validation
18+
if smooth_aggressiveness < 1:
19+
raise Exception("Smooth aggressiveness must be greater than 1.")
20+
if smooth_falloff < 1:
21+
raise Exception("Smooth falloff must be greater than 1.0.")
1722
self.previous_positions = []
1823
self.smooth_falloff = smooth_falloff
19-
self.smooth_aggressiveness = smooth_aggressiveness
24+
self.smooth_aggressiveness = int(smooth_aggressiveness)
2025
def update(self, (x,y)):
2126
self.previous_positions.append((x,y))
2227
if len(self.previous_positions) > self.smooth_aggressiveness:

PyLeapMouse.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,46 @@
1212
from PalmControl import Palm_Control_Listener #For palm-tilt based control
1313
from FingerControl import Finger_Control_Listener #For finger-pointing control
1414

15+
def show_help():
16+
print "----------------------------------PyLeapMouse----------------------------------"
17+
print "Use --finger (or blank) for pointer finger control, and --palm for palm control."
18+
print "Set smooth aggressiveness (# samples) with \"--smooth-aggressiveness [# samples]\""
19+
print "Set smooth falloff with \"--smooth-falloff [% per sample]\""
20+
print "Read README.md for even more info.\n"
1521

1622
def main():
17-
print "Use --finger (or no options) for pointer finger control,\nand --palm for palm control.\nRead README.md for more info."
23+
if "-h" in sys.argv or "--help" in sys.argv:
24+
show_help()
25+
return
26+
27+
print "----------------------------------PyLeapMouse----------------------------------"
28+
print "Use --finger (or blank) for pointer finger control, and --palm for palm control."
29+
print "Use -h or --help for more info.\n"
30+
31+
#Default
32+
finger_mode = True
33+
smooth_aggressiveness = 8
34+
smooth_falloff = 1.3
35+
36+
for i in range(0,len(sys.argv)):
37+
arg = sys.argv[i].lower()
38+
if "--palm" in arg:
39+
finger_mode = False
40+
if "--smooth-falloff" in arg:
41+
smooth_falloff = float(sys.argv[i+1])
42+
if "--smooth-aggressiveness" in arg:
43+
smooth_aggressiveness = int(sys.argv[i+1])
1844

1945
listener = None; #I'm tired and can't think of a way to organize this segment nicely
2046

2147
#Create a custom listener object which controls the mouse
22-
if len(sys.argv) == 1: #Finger pointer mode
23-
listener = Finger_Control_Listener(Mouse)
48+
if finger_mode: #Finger pointer mode
49+
listener = Finger_Control_Listener(Mouse, smooth_aggressiveness=smooth_aggressiveness, smooth_falloff=smooth_falloff)
2450
print "Using finger mode..."
25-
elif sys.argv[1].lower() == "--finger": #Also finger control mode
26-
listener = Finger_Control_Listener(Mouse)
27-
print "Using finger mode..."
28-
elif sys.argv[1].lower() == "--palm": #Palm control mode
51+
else: #Palm control mode
2952
listener = Palm_Control_Listener(Mouse)
3053
print "Using palm mode..."
31-
else:
32-
print "Error parsing input options"
33-
exit(1)
54+
3455

3556
controller = Leap.Controller() #Get a Leap controller
3657
print "Adding Listener."

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Two hands in frame: Left hand controls action.
2525
Two fingers open: Scrolling. Scrolling with right hand movement.
2626
This is a somewhat unintuitive method of operation, but I find that it gives exceptionally better control than the most obvious "point-at-screen" method of mouse control. With this two-handed tilt based mode, it is easy to hit and properly engage small buttons, scroll through webpages, etc.
2727

28+
2829
NOTES:
2930
This is a spare-time project, so it's not perfect quality. However, I tried to keep the code clean and readable. Let me know if you find any bugs (which there are certainly at least a few of). You can reach me at will (dot) yager (at) gmail (dot) (what the gmail domain ends in).
3031
The contents of the files are as follows:
@@ -36,9 +37,15 @@ OSX/Windows:
3637
Mouse.py: A set of generic commands and classes to abstract away from OS-Specific mouse commands
3738
Geometry.py: Geometric functions
3839
MiscFunctions.py: Things that aren't strictly geometry and aren't specific to any interface style
39-
README.md: You are here
40+
README.md: You are here
41+
42+
ADVANCED OPTIONS:
43+
`--smooth-aggressiveness [value]` sets the number of samples to use for pointer finger mouse smoothing.
44+
`--smooth-falloff [value]` sets the rate at which previous samples lose importance.
45+
For every sample back in time, the previous location of the mouse is weighted with weight smooth_falloff^(-#sample).
46+
So if smooth_falloff = 1.2, the current frame has weight 1/(1.2^0)=1, but the frame from 5 frames ago has weight 1/(1.2^5) = .4
47+
By default, the smooth aggressiveness is 8 frames with a falloff of 1.3.
4048

4149
TODO:
42-
Automatic library import for x86/x86_64 (libraries already import for proper OS automatically).
4350
Add proper relative mouse movement. Should be pretty easy on Windows, not sure how to do so on OS X.
4451
Add multiple monitor support for absolute mouse mode (and OS X's pseudo-relative mode).

0 commit comments

Comments
 (0)