//scan(at40k, cell, YLUT, true);
//scan(at40k, cell, YLUT, false);
- device.scanFPGA();
+ device.scanFPGA(true);
Visualizer v = new Visualizer(at40k, device);
v.show();
v.setSize(1380, 1080);
}
case ' ': {
enabled = !enabled;
+ break;
}
case 'C': {
if (selx==-1 || sely==-1) break;
break;
}
}
- for(int x=5; x<=PIPELEN; x++) {
- At40k.Cell cell = dev.cell(x, 22);
+ for(int xx=5; xx<=PIPELEN; xx++) {
+ final int x = xx;
+ final At40k.Cell cell = dev.cell(x, 22);
+ AvrDrone.ByteCallback bc = new AvrDrone.ByteCallback() {
+ public void call(byte b) throws Exception {
+ boolean y = (b & 0x80) != 0;
+
+ Graphics g = getGraphics();
+ g.setFont(new Font("sansserif", Font.BOLD, 24));
+ g.setColor(Color.white);
+ g.drawString("0", left(cell) + 12, top(cell) + 30);
+ g.drawString("1", left(cell) + 12, top(cell) + 30);
+ //g.setColor(RED);
+ //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
+
+ //g.drawString((y?"1":"0"), left(cell) + 12, top(cell) + 30);
+ drawCell(g, x, 22, y?new Color(0xff, 0x99, 0x99):new Color(0x99, 0xff, 0x99));
+ }
+ };
+
scan(dev, cell, YLUT, true);
- boolean y = (drone.readBus() & 0x80) != 0;
+ drone.readBus(bc);
scan(dev, cell, YLUT, false);
-
- Graphics g = getGraphics();
- g.setFont(new Font("sansserif", Font.BOLD, 24));
- g.setColor(Color.white);
- g.drawString("0", left(cell) + 12, top(cell) + 30);
- g.drawString("1", left(cell) + 12, top(cell) + 30);
- //g.setColor(RED);
- //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
-
- //g.drawString((y?"1":"0"), left(cell) + 12, top(cell) + 30);
- drawCell(g, x, 22, y?new Color(0xff, 0x99, 0x99):new Color(0x99, 0xff, 0x99));
}
}
public void mousePressed(MouseEvent e) {
- At40k.Cell cell = dev.cell(selx, sely);
- if (cell==null) return;
- int old = cell.c();
- scan(dev, cell, YLUT, true);
- boolean y = (drone.readBus() & 0x80) != 0;
- //scan(dev, cell, XLUT, true);
- //boolean x = (drone.readBus() & 0x80) != 0;
- scan(dev, cell, YLUT, false);
- cell.c(old);
- Graphics g = getGraphics();
- g.setFont(new Font("sansserif", Font.BOLD, 14));
- g.setColor(Color.white);
- //g.drawString("X=0", left(cell) + 10, top(cell) + 20);
- //g.drawString("X=1", left(cell) + 10, top(cell) + 20);
- /*
- g.setColor(Color.white);
- g.drawString("Y=0", left(cell) + 8, top(cell) + 35);
- g.drawString("Y=1", left(cell) + 8, top(cell) + 35);
- */
- //g.setColor(RED);
- //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
- g.setColor(BLUE);
- g.drawString("Y="+(y?"1":"0"), left(cell) + 8, top(cell) + 35);
+ /*
+ At40k.Cell cell = dev.cell(selx, sely);
+ if (cell==null) return;
+ int old = cell.c();
+ scan(dev, cell, YLUT, true);
+ boolean y = (drone.readBus() & 0x80) != 0;
+ //scan(dev, cell, XLUT, true);
+ //boolean x = (drone.readBus() & 0x80) != 0;
+ scan(dev, cell, YLUT, false);
+ cell.c(old);
+ Graphics g = getGraphics();
+ g.setFont(new Font("sansserif", Font.BOLD, 14));
+ g.setColor(Color.white);
+ //g.drawString("X=0", left(cell) + 10, top(cell) + 20);
+ //g.drawString("X=1", left(cell) + 10, top(cell) + 20);
+
+ //g.setColor(Color.white);
+ //g.drawString("Y=0", left(cell) + 8, top(cell) + 35);
+ //g.drawString("Y=1", left(cell) + 8, top(cell) + 35);
+
+ //g.setColor(RED);
+ //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
+ g.setColor(BLUE);
+ g.drawString("Y="+(y?"1":"0"), left(cell) + 8, top(cell) + 35);
+ */
}
public void mouseMoved(MouseEvent e) {
}
public void refresh() {
Graphics g = getGraphics();
+ /*
int data = drone.readBus() & 0xff;
for(int i=0; i<8; i++) {
g.setColor((data & (1<<i))==0 ? Color.black : Color.green);
g.drawString("D"+i, (24*(WIDTH+2))+20, ((23-(i+7))*(HEIGHT+2))+60-HEIGHT/2);
}
+ */
}
public static int left(At40k.Cell cell) { return (cell.col) *(WIDTH+2)+20; }
public static int top(At40k.Cell cell) { return (23-cell.row)*(HEIGHT+2)+60; }
}
public static void selfTest(AvrDrone device, At40k at40k, Visualizer v) {
+ /*
int fail = 0;
long now = System.currentTimeMillis();
for(int x=0; x<24; x++)
System.out.println("failures: " + fail);
System.out.println("scan time: " + (System.currentTimeMillis()-now) + "ms");
+ */
}
}
this.sp = sp;
sp.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
sp.setFlowControlMode(sp.FLOWCONTROL_RTSCTS_OUT);
+ sp.setInputBufferSize(1024);
//sp.setFlowControlMode(sp.FLOWCONTROL_NONE);
this.out = new DataOutputStream(sp.getOutputStream());
this.in = new DataInputStream(sp.getInputStream());
Log.info(this, "device correctly identified itself; ready for operation");
}
- public synchronized void scanFPGA() throws DeviceException {
+ public synchronized void scanFPGA(boolean on) throws DeviceException {
try {
- out.writeByte(3);
- out.flush();
+ if (on) {
+ out.writeByte(3);
+ out.flush();
+ } else {
+ // FIXME
+ }
} catch (IOException e) { throw new DeviceException(e); }
}
- public synchronized byte readBus() throws DeviceException {
+ public static interface ByteCallback {
+ public void call(byte b) throws Exception;
+ }
+
+ private Vector callbacks = new Vector();
+
+ private Thread reader = new Thread() {
+ public void run() {
+ while(true) {
+ try {
+ byte b = in.readByte();
+ ByteCallback bc = (ByteCallback)callbacks.remove(0);
+ bc.call(b);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ };
+
+ public synchronized void readBus(ByteCallback bc) throws DeviceException {
try {
+ System.out.println("capacity: " + callbacks.size());
+ callbacks.add(bc);
out.writeByte(2);
out.flush();
- return in.readByte();
+ if (reader != null) {
+ reader.start();
+ reader = null;
+ }
} catch (IOException e) { throw new DeviceException(e); }
}