17 """ For backwards compatibility with the old driver files 18 Will be DELETED in the future """ 32 from Leap
import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture
41 setattr(self, boneName, [0.0, 0.0, 0.0])
42 self.
tip = [0.0, 0.0, 0.0]
45 Leap.Bone.TYPE_PROXIMAL,
46 Leap.Bone.TYPE_INTERMEDIATE,
47 Leap.Bone.TYPE_DISTAL]
49 if finger
is not None:
55 bone = finger.bone(getattr(
Leap.Bone,
'TYPE_%s' % boneName.upper()))
56 setattr(self, boneName, bone.prev_joint.to_float_array())
58 self.
tip = finger.bone(Leap.Bone.TYPE_DISTAL).next_joint.to_float_array()
75 self.
fingerNames = [
'thumb',
'index',
'middle',
'ring',
'pinky']
78 print "Initialized Leap Motion Device" 81 print "Connected to Leap Motion Controller" 84 controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE);
85 controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP);
86 controller.enable_gesture(Leap.Gesture.TYPE_SCREEN_TAP);
87 controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);
91 print "Disconnected Leap Motion" 94 print "Exited Leap Motion Controller" 98 frame = controller.frame()
100 print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" % (
101 frame.id, frame.timestamp, len(frame.hands), len(frame.fingers), len(frame.tools), len(frame.gestures()))
103 if not frame.hands.is_empty:
108 there_is_right_hand=
False 109 there_is_left_hand=
False 111 for hand
in frame.hands:
114 there_is_right_hand=
True 117 there_is_left_hand=
True 121 if not there_is_right_hand:
124 if not there_is_left_hand:
127 self.
hand = frame.hands[0]
130 fingers = self.hand.fingers
131 if not fingers.is_empty:
135 finger = fingers.finger_type(getattr(
Leap.Finger,
'TYPE_%s' % fingerName.upper()))[0]
136 getattr(self, fingerName).importFinger(finger)
142 normal = self.hand.palm_normal
143 direction = self.hand.direction
144 pos = self.hand.palm_position
155 self.
hand_pitch = direction.pitch * Leap.RAD_TO_DEG
156 self.
hand_yaw = normal.yaw * Leap.RAD_TO_DEG
157 self.
hand_roll = direction.roll * Leap.RAD_TO_DEG
164 for gesture in frame.gestures(): 165 if gesture.type == Leap.Gesture.TYPE_CIRCLE: 166 circle = CircleGesture(gesture) 168 # Determine clock direction using the angle between the pointable and the circle normal 169 if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/4: 170 clockwiseness = "clockwise" 172 clockwiseness = "counterclockwise" 174 # Calculate the angle swept since the last frame 176 if circle.state != Leap.Gesture.STATE_START: 177 previous_update = CircleGesture(controller.frame(1).gesture(circle.id)) 178 swept_angle = (circle.progress - previous_update.progress) * 2 * Leap.PI 180 print "Circle id: %d, %s, progress: %f, radius: %f, angle: %f degrees, %s" % ( 181 gesture.id, self.state_string(gesture.state), 182 circle.progress, circle.radius, swept_angle * Leap.RAD_TO_DEG, clockwiseness) 184 if gesture.type == Leap.Gesture.TYPE_SWIPE: 185 swipe = SwipeGesture(gesture) 186 print "Swipe id: %d, state: %s, position: %s, direction: %s, speed: %f" % ( 187 gesture.id, self.state_string(gesture.state), 188 swipe.position, swipe.direction, swipe.speed) 190 if gesture.type == Leap.Gesture.TYPE_KEY_TAP: 191 keytap = KeyTapGesture(gesture) 192 print "Key Tap id: %d, %s, position: %s, direction: %s" % ( 193 gesture.id, self.state_string(gesture.state), 194 keytap.position, keytap.direction ) 196 if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: 197 screentap = ScreenTapGesture(gesture) 198 print "Screen Tap id: %d, %s, position: %s, direction: %s" % ( 199 gesture.id, self.state_string(gesture.state), 200 screentap.position, screentap.direction ) 202 if not (frame.hands.empty and frame.gestures().empty): 205 def state_string(self, state): 206 if state == Leap.Gesture.STATE_START: 209 if state == Leap.Gesture.STATE_UPDATE: 210 return "STATE_UPDATE" 212 if state == Leap.Gesture.STATE_STOP: 215 if state == Leap.Gesture.STATE_INVALID: 216 return "STATE_INVALID" 238 return getattr(getattr(self, fingerName), fingerPointName)
244 threading.Thread.__init__(self)
248 self.controller.add_listener(self.
listener)
251 self.controller.remove_listener(self.
listener)
254 return self.listener.get_hand_direction()
257 return self.listener.get_hand_normal()
260 return self.listener.get_hand_palmpos()
263 return self.listener.get_hand_roll()
266 return self.listener.get_hand_pitch()
269 return self.listener.get_hand_yaw()
272 return self.listener.get_finger_point(fingerName, fingerPointName)
def get_hand_palmpos(self)
def __init__(self, arg=None)
def get_hand_palmpos(self)
def on_frame(self, controller)
def get_finger_point(self, fingerName, fingerPointName)
def on_connect(self, controller)
def on_init(self, controller)
def importFinger(self, finger)
def get_hand_normal(self)
def __init__(self, finger=None)
def get_hand_normal(self)
def get_hand_direction(self)
def get_hand_direction(self)
def on_exit(self, controller)
def on_disconnect(self, controller)
def get_finger_point(self, fingerName, fingerPointName)