Skip to content
This repository
Browse code

New processing examples (doc)

Port of the usage examples from the doc of the API.
  • Loading branch information...
commit 2f5f9ff8987d94245ffb9738357fba2056b9e90d 1 parent 6203f6e
Raphaël de Courville authored December 26, 2012
43  examples/processing/accelerometer_frame/accelerometer_frame.pde
... ...
@@ -0,0 +1,43 @@
  1
+
  2
+// Import the PS Move API Package
  3
+import io.thp.psmove.*;
  4
+
  5
+PSMove [] moves;
  6
+
  7
+void setup() {
  8
+  moves = new PSMove[psmoveapi.count_connected()];
  9
+  for (int i=0; i<moves.length; i++) {
  10
+    moves[i] = new PSMove(i);
  11
+  }
  12
+}
  13
+
  14
+void draw() {
  15
+  
  16
+  for (int i=0; i<moves.length; i++) {
  17
+    handle(i, moves[i]); // Take care of each move controller
  18
+  }
  19
+  
  20
+}
  21
+
  22
+void handle(int i, PSMove move)
  23
+{
  24
+  float [] ax = {0.f}, ay = {0.f}, az = {0.f};
  25
+
  26
+  while (move.poll () != 0) {
  27
+    move.get_accelerometer_frame(io.thp.psmove.Frame.Frame_SecondHalf, ax, ay, az);
  28
+      
  29
+    float accX = ax[0];
  30
+    float accY = ay[0];
  31
+    float accZ = az[0];
  32
+    // Convert rad/s to RPM
  33
+    accX = accX * 60 / (2*PI);
  34
+    accY = accY * 60 / (2*PI);
  35
+    accZ = accZ * 60 / (2*PI);
  36
+
  37
+    println("Move #"+i+" rotation X: %.2f RPM: "+accX);
  38
+    println("Move #"+i+" rotation Y: %.2f RPM: "+accY);
  39
+    println("Move #"+i+" rotation Z: %.2f RPM: "+accZ);
  40
+    println("-----------------------------------------");
  41
+  }
  42
+}
  43
+
18  examples/processing/connection_type/connection_type.pde
@@ -27,14 +27,14 @@ int total_connected, unique_connected;
27 27
 int [] batteryLevels;
28 28
 
29 29
 // Battery enum values
30  
-final int Batt_MIN           = 0;
31  
-final int Batt_20Percent     = 1;
32  
-final int Batt_40Percent     = 2;
33  
-final int Batt_60Percent     = 3;
34  
-final int Batt_80Percent     = 4;
35  
-final int Batt_MAX           = 5;
36  
-final int Batt_CHARGING      = 6;
37  
-final int Batt_CHARGING_DONE = 7;
  30
+final int Batt_MIN           = 0x00;
  31
+final int Batt_20Percent     = 0x01;
  32
+final int Batt_40Percent     = 0x02;
  33
+final int Batt_60Percent     = 0x03;
  34
+final int Batt_80Percent     = 0x04;
  35
+final int Batt_MAX           = 0x05;
  36
+final int Batt_CHARGING      = 0xEE;
  37
+final int Batt_CHARGING_DONE = 0xEF;
38 38
 
39 39
 // Connection type enum values. connection_type() returns...
40 40
 final int Conn_Bluetooth = 0; // if the controller is connected via Bluetooth
@@ -104,7 +104,7 @@ void setup() {
104 104
 //--- DRAW ----------------------------------------------------------
105 105
 
106 106
 void draw() {
107  
-  update_battery_levels();
  107
+  update_battery_levels();  
108 108
 } // END of DRAW
109 109
 
110 110
 //---------------------------------------------------------------------
29  examples/processing/detect_dropped_frames/detect_dropped_frames.pde
... ...
@@ -0,0 +1,29 @@
  1
+
  2
+// Import the PS Move API Package
  3
+import io.thp.psmove.*;
  4
+
  5
+PSMove [] moves;
  6
+
  7
+void setup() {
  8
+  moves = new PSMove[psmoveapi.count_connected()];
  9
+  for (int i=0; i<moves.length; i++) {
  10
+    moves[i] = new PSMove(i);
  11
+  }
  12
+}
  13
+
  14
+void draw() {
  15
+  for (int i=0; i<moves.length; i++) {
  16
+    handle(i, moves[i]); // Take care of each move controller
  17
+  }
  18
+}
  19
+
  20
+void handle(int i, PSMove move)
  21
+{
  22
+  int seq_old = 0;
  23
+  int seq = move.poll();
  24
+  if ((seq_old > 0) && ((seq_old % 16) != (seq - 1))) {
  25
+  println("Controller #"+i+": frame dropped"); // dropped frame
  26
+  }
  27
+  seq_old = seq;
  28
+}
  29
+
34  examples/processing/get_button_events/get_button_events.pde
... ...
@@ -0,0 +1,34 @@
  1
+
  2
+// Import the PS Move API Package
  3
+import io.thp.psmove.*;
  4
+
  5
+PSMove [] moves;
  6
+
  7
+void setup() {
  8
+  moves = new PSMove[psmoveapi.count_connected()];
  9
+  for (int i=0; i<moves.length; i++) {
  10
+    moves[i] = new PSMove(i);
  11
+  }
  12
+}
  13
+
  14
+void draw() {
  15
+  
  16
+  for (int i=0; i<moves.length; i++) {
  17
+    handle(i, moves[i]); // Take care of each move controller
  18
+  }
  19
+  
  20
+}
  21
+
  22
+void handle(int i, PSMove move)
  23
+{
  24
+  while (move.poll () != 0) {
  25
+  long [] pressed = {0};
  26
+  long [] released = {0};
  27
+  move.get_button_events(pressed, released);
  28
+  if ((pressed[0] & Button.Btn_MOVE.swigValue()) != 0) {
  29
+      println("The Move button has been pressed now. (Controller #"+i+")");
  30
+    } else if ((released[0] & Button.Btn_MOVE.swigValue()) != 0) {
  31
+      println("The Move button has been released now. (Controller #"+i+")");
  32
+    }
  33
+  }
  34
+}
30  examples/processing/get_buttons/get_buttons.pde
... ...
@@ -0,0 +1,30 @@
  1
+
  2
+// Import the PS Move API Package
  3
+import io.thp.psmove.*;
  4
+
  5
+PSMove [] moves;
  6
+
  7
+void setup() {
  8
+  moves = new PSMove[psmoveapi.count_connected()];
  9
+  for (int i=0; i<moves.length; i++) {
  10
+    moves[i] = new PSMove(i);
  11
+  }
  12
+}
  13
+
  14
+void draw() {
  15
+  
  16
+  for (int i=0; i<moves.length; i++) {
  17
+    handle(i, moves[i]); // Take care of each move controller
  18
+  }
  19
+  
  20
+}
  21
+
  22
+void handle(int i, PSMove move)
  23
+{
  24
+   while (move.poll () != 0) {
  25
+        int buttons = move.get_buttons();
  26
+        if ((buttons & Button.Btn_MOVE.swigValue()) != 0) {
  27
+            println("The MOVE button is currently pressed. (Controller #"+i+")");
  28
+       }
  29
+   }
  30
+}

0 notes on commit 2f5f9ff

Please sign in to comment.
Something went wrong with that request. Please try again.