- for(int i=7; i>=0; i--) {
- d.config((((in & 0xff) & (1<<i))!=0)?1:0, 1);
- boolean init = true; // d.initErr()
- if (bytes < 100 || (bytes % 1000)==0) {
- d.flush();
- init = d.initErr();
- System.out.print("wrote " + bytes + " bytes, init="+init+" \r");
- d.rcon();
+ os.write((byte)Integer.parseInt(s, 2));
+ if ((bytes % 1000)==0) os.flush();
+ }
+ os.close();
+ }
+
+
+ // AvrDrone leftovers //////////////////////////////////////////////////////////////////////////////
+
+ private void init() throws IOException {
+ byte[] bytes = new byte[6];
+ int i=0;
+
+ out.write(0);
+ out.flush();
+
+ // read any crap that might be left in the buffer
+ while(true) {
+ System.arraycopy(bytes, 1, bytes, 0, 5);
+ bytes[5] = in.readByte();
+ i++;
+ System.out.print("\rsignature: read \"" + new String(bytes) + "\" ");
+ if (bytes[0] == (byte)'O' &&
+ bytes[1] == (byte)'B' &&
+ bytes[2] == (byte)'I' &&
+ bytes[3] == (byte)'T' &&
+ bytes[4] == (byte)'S') {
+ System.out.println("\rsignature: got proper signature ");
+ chip.purge();
+ break;
+ }
+ }
+
+ // FIXME: what if init() is called twice?
+ new Thread() {
+ public void run() {
+ while(true) {
+ try {
+ while(callbacks.size() == 0) Thread.sleep(50);
+ byte b = in.readByte();
+ ByteCallback bc = (ByteCallback)callbacks.remove(0);
+ //System.out.println("readback " + b + " in " + (System.currentTimeMillis()-bc.time));
+ bc.call(b);
+ synchronized(lock) {
+ lock.notifyAll();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }