New code for Grizzlies
authorAlexander Kiselev <akiselev@opeindustrial.org>
Fri, 7 Feb 2014 14:10:31 +0000 (06:10 -0800)
committerAlexander Kiselev <akiselev@opeindustrial.org>
Fri, 7 Feb 2014 14:10:31 +0000 (06:10 -0800)
_Mappings.pde
_PandaDriver.pde

index 171ff13e26808b056c55392661fecb621050a8a4..5e7e05ef81eb0764442409056e5fe245499e8ddb 100644 (file)
@@ -243,52 +243,153 @@ public PandaMapping[] buildPandaList() {
   // 8 channels map to:  3, 4, 7, 8, 13, 14, 15, 16.
   return new PandaMapping[] {
     new PandaMapping(
-      "10.200.1.28", new ChannelMapping[] {
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {  }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {  }), // new front thing
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {  }), // new back thing
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 13, 14, 15 }), // new back thing
+      "192.168.88.100", new ChannelMapping[] {
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+   }),
+   new PandaMapping(
+      "192.168.88.101", new ChannelMapping[] {
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+   }),
+  new PandaMapping(
+      "192.168.88.102", new ChannelMapping[] {
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+   }),
+  new PandaMapping(
+      "192.168.88.103", new ChannelMapping[] {
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
     }),
     new PandaMapping(
-      "10.200.1.29", new ChannelMapping[] {
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {  }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7, 8, 9 }),
-
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 10, 11, 12 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18 }),
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36}),
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21}),
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24}), 
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27}),
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30}),
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33}),
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
-    }),    
-    new PandaMapping(
-      "10.200.1.30", new ChannelMapping[] {
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36 }),
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1}), // 30 J3 *
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1}),  // 30 J4 //ORIG *
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39}),                // 30 J7 *
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42}),  // 30 J8 *
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45}),                // 30 J13 (not working)
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48}),                // 30 J14 (unplugged)
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51}),                // 30 J15 (unplugged)
-//        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 52, 53, 54}), // 30 J16
-   }),    
+      "192.168.88.104", new ChannelMapping[] {
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+   }),
+   new PandaMapping( 
+      "192.168.88.105", new ChannelMapping[] {
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+   }),
+   // new PandaMapping(
+   //    "192.168.88.102", new ChannelMapping[] {
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+   // }),
+   // new PandaMapping(
+   //    "192.168.88.104", new ChannelMapping[] {
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+   // }),
+   // new PandaMapping(
+   //    "192.168.88.105", new ChannelMapping[] {
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
+   //      new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
+   // }),
+      
 //     new PandaMapping(
 //       "10.200.1.31", new ChannelMapping[] {
 //         new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 65, 66}),       // J3 
@@ -362,7 +463,7 @@ class StaggeredTower {
 class PandaMapping {
   
   // How many channels are on the panda board
-  public final static int CHANNELS_PER_BOARD = 8;
+  public final static int CHANNELS_PER_BOARD = 16;
   
   // How many total pixels on the whole board
   public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
@@ -396,7 +497,7 @@ class PandaMapping {
 class ChannelMapping {
 
   // How many cubes per channel xc_PB is configured for
-  public final static int CUBES_PER_CHANNEL = 4;  
+  public final static int CUBES_PER_CHANNEL = 1;  
 
   // How many total pixels on each channel
   public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
index 5d8ad249bbe3171446033c720c1d15f60cfda226..6751102c69a4551e141b22e6ba2cfb9bb579a8b3 100644 (file)
@@ -1,6 +1,7 @@
 import netP5.*;
 import oscP5.*;
 
+
 /**
  *     DOUBLE BLACK DIAMOND        DOUBLE BLACK DIAMOND
  *
@@ -24,12 +25,17 @@ public static class PandaDriver {
   
   // IP address
   public final String ip;
+
+  public PandaMapping pm;
   
   // Address to send to
   private final NetAddress address;
   
   // Whether board output is enabled
   private boolean enabled = false;
+
+  // Frame count for Grizzlies
+  private int frameNum = 1;
   
   // OSC message
   private final OscMessage message;
@@ -38,10 +44,12 @@ public static class PandaDriver {
   private final int[] points;
     
   // Packet data
-  private final byte[] packet = new byte[4*352]; // magic number, our UDP packet size
+  private final byte[] packet = new byte[4*280]; // magic number, our UDP packet size
 
   private static final int NO_POINT = -1;
 
+  private Model _model;
+
   ////////////////////////////////////////////////////////////////
   //
   // READ THIS RIGHT NOW BEFORE YOU MODIFY THE BELOW!!!!!!!!!!!!!
@@ -168,7 +176,7 @@ public static class PandaDriver {
     this.ip = ip;
     
     // Initialize our OSC output stuff
-    address = new NetAddress(ip, 9001);
+    address = new NetAddress(ip, 779);
     message = new OscMessage("/shady/pointbuffer");
     
     // Build the array of points, initialize all to nothing
@@ -178,15 +186,16 @@ public static class PandaDriver {
     }
   }
     
-  public PandaDriver(String ip, Model model, PandaMapping pm) {
+  public PandaDriver(String ip, Model model, PandaMapping _pm) {
     this(ip);
-    
+    pm = _pm;
+    _model = model;
     // Ok, we are initialized, time to build the array if points in order to
     // send out. We start at the head of our point buffer, and work our way
     // down. This is the order in which points will be sent down the wire.
     int ci = -1;
     
-    // Iterate through all our channels
+    // Iterate through all our channels
     for (ChannelMapping channel : pm.channelList) {
       ++ci;
       int pi = ci * ChannelMapping.PIXELS_PER_CHANNEL;
@@ -319,37 +328,64 @@ public static class PandaDriver {
     if (!enabled) {
       return;
     }
+    frameNum++;
     int len = 0;
     int packetNum = 0;
-    for (int index : points) {
-      int c = (index < 0) ? 0 : colors[index];
-      byte r = (byte) ((c >> 16) & 0xFF);
-      byte g = (byte) ((c >> 8) & 0xFF);
-      byte b = (byte) ((c) & 0xFF);
-      packet[len++] = 0; // alpha channel, unused but makes for 4-byte alignment
-      packet[len++] = r;
-      packet[len++] = g;
-      packet[len++] = b;
-
-      // Flush once packet is full buffer size
-      if (len >= packet.length) {
-        sendPacket(packetNum++);
-        len = 0;
-      }
+    for (ChannelMapping channel : pm.channelList) {
+      for (int j: channel.objectIndices) {
+        if (j > 0) {
+          Cube cube = _model.getCubeByRawIndex(j);
+          for (LXPoint p : cube.points) {
+              int c = (p.index < 0) ? 0 : colors[p.index];
+              byte r = (byte) ((c >> 16) & 0xFF);
+              byte g = (byte) ((c >> 8) & 0xFF);
+              byte b = (byte) ((c) & 0xFF);
+                packet[len++] = (byte) 0; // alpha channel, unused but makes for 4-byte alignment
+                packet[len++] = (byte) r;
+                packet[len++] = (byte) g;
+                packet[len++] = (byte) b;
+            }
+          }
+        }
+      // println("Packet number: " + packetNum);
+      sendPacket(frameNum, packetNum++);
+      len = 0;
     }
+    // for (int index : points) {
+    //   int c = (index < 0) ? 0 : colors[index];
+    //   byte r = (byte) ((c >> 16) & 0xFF);
+    //   byte g = (byte) ((c >> 8) & 0xFF);
+    //   byte b = (byte) ((c) & 0xFF);
+    //   packet[len++] = 0; // alpha channel, unused but makes for 4-byte alignment
+    //   packet[len++] = r;
+    //   packet[len++] = g;
+    //   packet[len++] = b;
 
-    // Flush any remaining data
-    if (len > 0) {
-      sendPacket(packetNum++);
-    }
+    //   // Flush once packet is full buffer size
+    //   if (len >= packet.length) {
+    //     sendPacket(packetNum++);
+    //     len = 0;
+    //   }
+    // }
+
+    // // Flush any remaining data
+    // if (len > 0) {
+    //   sendPacket(packetNum++);
+    // }
   }
   
 
-  private void sendPacket(int packetNum) {
+  private void sendPacket(int frameNum, int packetNum) {
+    // println("Sending frame #" + frameNum + ", channel # " + packetNum);
     message.clearArguments();
+    message.add(frameNum);
+    message.add(0xDEADBEEF);
     message.add(packetNum);
+    message.add(0xFEEDBEEF);
     message.add(packet.length);
     message.add(packet);
+    message.add(0xBEFFFFEB);
+
     try {
       OscP5.flush(message, address);
     } catch (Exception x) {