1 package com.megacz.eltron;
3 import org.ibex.util.*;
4 import org.ibex.graphics.*;
11 public static SerialPort detectObitsPort() throws Exception {
12 Enumeration e = CommPortIdentifier.getPortIdentifiers();
13 while(e.hasMoreElements()) {
14 CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
15 Log.info(Eltron.class, "detected " + cpi.getName());
16 if (cpi.getName().indexOf("usbserial")!=-1) {
17 SerialPort ret = new RXTXPort(cpi.getName());
18 Log.info(Eltron.class, "returning " + ret);
22 SerialPort ret = new RXTXPort("/dev/ttyS0");
23 Log.info(Eltron.class, "returning " + ret);
27 public static void main(String[] s) throws Exception {
28 SerialPort sp = detectObitsPort();
29 //sp.setFlowControlMode(sp.FLOWCONTROL_NONE);
31 sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
32 //sp.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
33 //sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
34 OutputStream out = sp.getOutputStream();
35 InputStream in = sp.getInputStream();
37 PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
42 System.out.println("rebooting device...");
47 System.out.println("rebooted.");
48 try { Thread.sleep(3000); } catch (Exception e) { }
49 System.out.println("setting comm parameters...");
53 pw.println("Y38,N,8,1");
55 System.out.println("set.");
56 try { Thread.sleep(2000); } catch (Exception e) { }
64 try { Thread.sleep(2000); } catch (Exception e) { }
70 //pw.println("Q609,24");
74 //int MAXWIDTH = 200 * 4 - 10;
75 //int MAXHEIGHT = 200 * 6 - 10;
76 int MAXWIDTH = 200 * 5 - 10;
77 int MAXHEIGHT = 200 * 7 - 10;
78 Picture p = new Picture(System.in);
80 int owidth = ((int)Math.floor(Math.min(MAXWIDTH, p.height)/8.0)) * 8; // FIXME: should be ceil
81 int oheight = Math.min(MAXHEIGHT, p.width);
82 int[] data2 = new int[owidth * oheight];
83 for(int y=0; y<owidth; y++)
84 for(int x=0; x<oheight; x++)
85 data2[y+x*owidth] = data[x+(owidth-y-1)*p.width];
88 for(int y=0; y<oheight; y++) {
89 pw.println("GW0,"+y+","+owidth/8+",1");
91 DataOutputStream dout = new DataOutputStream(out);
92 System.out.println("y="+y);
93 for(int x=0; x<owidth; x+=8) {
95 for(int i=0; i<Math.min(8, owidth-x); i++) {
96 int dat = data[y*owidth+x+i];
121 //Log.debug(this, "consuming any leftover data on the serial port");
124 AvrDrone device = new AvrDrone(detectObitsPort());
127 long begin = System.currentTimeMillis();
128 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
129 for(String str = br.readLine(); str != null; str = br.readLine()) {
130 long foo = Long.parseLong(str, 16);
131 device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0));
133 if (count % 100 == 0) Log.info(Eltron.class, "wrote " + count + " configuration octets");
136 long end = System.currentTimeMillis();
137 Log.info(Eltron.class, "finished in " + ((end-begin)/1000) + "s");
139 } catch (Exception e) { e.printStackTrace(); }