Skip to content

Instantly share code, notes, and snippets.

@stephenlb
Forked from domadev812/Main.java
Created November 15, 2017 21:06
Show Gist options
  • Select an option

  • Save stephenlb/5ef20b506717d3e24dddd03678b65f2d to your computer and use it in GitHub Desktop.

Select an option

Save stephenlb/5ef20b506717d3e24dddd03678b65f2d 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){
PNConfiguration pnConfiguration = new PNConfiguration();
pnConfiguration.setSubscribeKey(subKey);
pnConfiguration.setPublishKey(pubKey);
pnConfiguration.setSecure(false);
PubNub pubnub = new PubNub(pnConfiguration);
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().channels(subchannel).execute()
# ==============================Define Main==================================
def main():
print("Starting Main")
pnconfig = PNConfiguration()
pnconfig.subscribe_key = 'pubnub_subscribe_key'
pnconfig.publish_key = 'pubnub_publish_key'
pubnub = PubNub(pnconfig)
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(channels).callback(_callback).execute()
# ==============================Call Main====================================
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment