pandaBoards = new PandaDriver[pandaMappings.length];
int pbi = 0;
for (PandaMapping pm : pandaMappings) {
- pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm.channelList);
+ pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
}
mappingTool = new MappingTool(glucose, pandaMappings);
logTime("Built PandaDriver");
// How many cubes per channel xc_PB is configured for
public final static int CUBES_PER_CHANNEL = 4;
+ // How many total pixels on each channel
+ public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
+
+ // How many total pixels on the whole board
+ public final static int PIXELS_PER_BOARD = PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
+
final String ip;
final int[][] channelList = new int[CHANNELS_PER_BOARD][CUBES_PER_CHANNEL];
// List of point indices on the board
private final int[] points;
-
+
// Packet data
private final byte[] packet = new byte[4*352]; // TODO: de-magic-number, UDP related?
- public PandaDriver(String ip, Model model, int[][] channelList) {
+ public PandaDriver(String ip) {
this.ip = ip;
this.address = new NetAddress(ip, 9001);
message = new OscMessage("/shady/pointbuffer");
- List<Integer> pointList = buildMappedList(model, channelList);
- points = new int[pointList.size()];
- int i = 0;
- for (int value : pointList) {
- points[i++] = value;
+ points = new int[PandaMapping.PIXELS_PER_BOARD];
+ for (int i = 0; i < points.length; ++i) {
+ points[i] = 0;
+ }
+ }
+
+ public PandaDriver(String ip, int[] pointList) {
+ this(ip);
+ for (int i = 0; i < pointList.length && i < points.length; ++i) {
+ this.points[i] = pointList[i];
}
}
+
+ public PandaDriver(String ip, Model model, PandaMapping pm) {
+ this(ip);
+ buildPointList(model, pm);
+ }
public void toggle() {
enabled = !enabled;
println("PandaBoard/" + ip + ": " + (enabled ? "ON" : "OFF"));
}
- private ArrayList<Integer> buildMappedList(Model model, int[][] channelList) {
- ArrayList<Integer> points = new ArrayList<Integer>();
- for (int[] channel : channelList) {
+ private void buildPointList(Model model, PandaMapping pm) {
+ int pi = 0;
+ for (int[] channel : pm.channelList) {
for (int cubeNumber : channel) {
- if (cubeNumber == 0) {
+ if (cubeNumber <= 0) {
for (int i = 0; i < Cube.POINTS_PER_CUBE; ++i) {
- points.add(0);
+ points[pi++] = 0;
}
} else {
Cube cube = model.getCubeByRawIndex(cubeNumber);
for (int stripIndex : stripOrder) {
Strip s = cube.strips.get(stripIndex);
for (int j = s.points.size() - 1; j >= 0; --j) {
- points.add(s.points.get(j).index);
+ points[pi++] = s.points.get(j).index;
}
}
}
}
}
- return points;
}
public final void send(int[] colors) {