-
-
Save domadev812/73efe308fbbbf6be11f28fb1f03a1e5e to your computer and use it in GitHub Desktop.
Leap Motion - R Pi Remote Control Hands Edits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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