Skip to content

Instantly share code, notes, and snippets.

@ToeJamson
Last active October 18, 2017 22:41
Show Gist options
  • Select an option

  • Save ToeJamson/1c4df00d75c1803fca9c to your computer and use it in GitHub Desktop.

Select an option

Save ToeJamson/1c4df00d75c1803fca9c to your computer and use it in GitHub Desktop.
Leap Motion - R Pi Remote Control Hands Edits
public class LeapToServo implements Runnable{
//Define Channel name
public static final String CHANNEL = "my_channel";
//Create PubNub instance
private Pubnub pubnub;
//Create Leap Controller instance
private Controller controller;
//is Runnable running?
private boolean running;
//Last value of Left Yaw
int oldLeftYaw = 0;
//Last value of Left Pitch
int oldLeftPitch = 0;
//Last value of Right Yaw
int oldRightYaw = 0;
//Last value of Right Pitch
int oldRightPitch = 0;
//Takes in Pubkey and Subkey and sets up PubNub Configuration
public LeapToServo(String pubKey, String subKey){
pubnub = new Pubnub(pubKey, subKey);
pubnub.setUUID("LeapController");
}
/**
* Implementation of the Runnable interface.
*/
public void run(){
for(;;) {
if (!running) break;
captureFrame(this.controller);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
String pubKey = "pubnub_publish_key";
String subKey = "pubnub_subscribe_key";
LeapToServo s = new LeapToServo(pubKey, subKey);
s.startTracking();
}
}
#Kill PubNub subscription thread
def _kill(m, n):
pubnub.unsubscribe(subchannel)
# ==============================Define Main==================================
def main():
print("Starting Main")
pubnub = Pubnub(publish_key = 'pubnub_publish_key',
subscribe_key = 'pubnub_subscribe_key',
uuid = "pi")
channel = 'my_channel'
def _callback(m,n):
# ==============================Left Hand==============================
left_hand = m.get("left_hand",{})
if left_hand != {}:
handleLeft(left_hand)
# ==============================Right Hand=============================
right_hand = m.get("right_hand",{})
if right_hand != {}:
handleRight(right_hand)
#Catch and Print Error
def _error(m):
print(m)
#Subscribe to subchannel, set callback function to _callback and set error fucntion to _error
pubnub.subscribe(channels=channel, callback=_callback, error=_error, connect=_error)
# ==============================Call Main====================================
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment