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
| def handleLeft(left_hand): | |
| left_yaw = left_hand["left_yaw"] | |
| left_pitch = left_hand["left_pitch"] | |
| pwm.setPWM(1, 1, left_yaw) | |
| pwm.setPWM(2, 2, left_pitch) | |
| def handleRight(right_hand): | |
| right_yaw = right_hand["right_yaw"] | |
| right_pitch = right_hand["right_pitch"] | |
| pwm.setPWM(3, 3, right_yaw) |
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(subchannel) | |
| # ==============================Define Main================================== | |
| def main(): | |
| print("Starting Main") | |
| pubnub = Pubnub(publish_key = 'demo', | |
| subscribe_key = 'demo', |
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 void cleanup(){ | |
| try { | |
| JSONObject payload = new JSONObject(); | |
| JSONObject left = new JSONObject(); | |
| JSONObject right = new JSONObject(); | |
| left.put("left_yaw", 400); | |
| left.put("left_pitch",400); | |
| right.put("right_yaw", 400); | |
| right.put("right_pitch",400); | |
| payload.put("left_hand", left); |
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
| /** | |
| * Take radian reading and return degree value adjusted for our desired range/midpoint of servo range | |
| * @param radians Radian value to be converted | |
| * @return Adjusted degree value | |
| */ | |
| public static int radiansToAdjustedDegrees(int radians){ | |
| int degrees = (int) (radians * (180 / Math.PI)); | |
| degrees = (int) Math.floor(degrees + 90); | |
| return degrees; | |
| } |
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 JSONObject handleHand(Hand hand){ | |
| boolean isLeft = hand.isLeft(); | |
| String handName = (isLeft) ? "left" : "right"; | |
| Vector direction = hand.direction(); | |
| int yaw = (int) Math.toDegrees(direction.yaw()); | |
| int pitch = (int) Math.toDegrees(direction.pitch()); | |
| // Normalize Yaw and Pitch |
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 void startTracking(){ | |
| // Create a controller | |
| this.controller = new Controller(); | |
| this.running = true; | |
| Thread t = new Thread(this); | |
| t.start(); | |
| // Keep this process running until Enter is pressed | |
| System.out.println("Press Enter to quit..."); | |
| try { |
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; |
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
| class AppDelegate: UIResponder, UIApplicationDelegate, PNObjectEventListener { | |
| var client : PubNub | |
| var config : PNConfiguration | |
| override init() { | |
| config = PNConfiguration(publishKey: "Demo", subscribeKey: "Demo") | |
| client = PubNub.clientWithConfiguration(config) | |
| client.subscribeToChannels(["Your_Channel"], withPresence: false) | |
| client.publish("Swift+PubNub!", toChannel: "Your_Channel", compressed: false, withCompletion: nil) |
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
| var client : PubNub //Change from let to var | |
| var config : PNConfiguration //Change from let to var | |
| override init() { | |
| config = PNConfiguration(publishKey: "pub-c-c03b6441-51f1-4e33-9631-ed7cc1d42b04", subscribeKey: "sub-c-df9311e8-360c-11e5-9d54-0693d8625082") | |
| client = PubNub.clientWithConfiguration(config) | |
| client.subscribeToChannels(["Your_Channel"], withPresence: false) | |
| client.publish("Swift+PubNub!", toChannel: "demo", compressed: false, withCompletion: nil) | |
| //Important thing to note here is that we call super.init() before passing self to addListener. | |
| super.init() |
NewerOlder