X-Git-Url: http://git.megacz.com/?p=eltron.git;a=blobdiff_plain;f=src%2Fcom%2Fmegacz%2Feltron%2FEltron.java;fp=src%2Fcom%2Fmegacz%2Feltron%2FEltron.java;h=33c090b18a23f0b56f415182fff5e76aecfbfe52;hp=a7881a81072961f4618c3af87df0ac8809fb65c0;hb=61e6074f12446ccf9f6b5a41996e3c8b8f8e2f3a;hpb=0178b34d5fde3c1cfbc18ae48ec1798b28a1af21 diff --git a/src/com/megacz/eltron/Eltron.java b/src/com/megacz/eltron/Eltron.java index a7881a8..33c090b 100644 --- a/src/com/megacz/eltron/Eltron.java +++ b/src/com/megacz/eltron/Eltron.java @@ -6,9 +6,15 @@ import java.io.*; import java.util.*; import gnu.io.*; +/** code to control an Eltron */ public class Eltron { - public static SerialPort detectObitsPort() throws Exception { + public static void main(String[] s) throws Exception { + Picture p = new Picture(System.in); + print(p.data, p.width, p.height); + } + + public static SerialPort detectPort() throws Exception { Enumeration e = CommPortIdentifier.getPortIdentifiers(); while(e.hasMoreElements()) { CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement(); @@ -24,13 +30,13 @@ public class Eltron { return ret; } - public static void main(String[] s) throws Exception { - SerialPort sp = detectObitsPort(); - //sp.setFlowControlMode(sp.FLOWCONTROL_NONE); + public static void print(int[] data, int width, int height) throws Exception { + SerialPort sp = detectPort(); - sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); - //sp.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); + // you'll need to run this once at 9600 to tell the built-in eeprom to switch to 38,400kbps //sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); + sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); + OutputStream out = sp.getOutputStream(); InputStream in = sp.getInputStream(); int count = 0; @@ -38,6 +44,7 @@ public class Eltron { pw.println(); pw.flush(); + // uncomment this code the first time you run it (at 9600bps) /* System.out.println("rebooting device..."); pw.println("^@"); @@ -67,22 +74,16 @@ public class Eltron { pw.println("N"); pw.println("D14"); pw.println("S1"); - //pw.println("Q609,24"); pw.println("q780"); - //pw.println("R0,0"); - //int MAXWIDTH = 200 * 4 - 10; - //int MAXHEIGHT = 200 * 6 - 10; int MAXWIDTH = 200 * 5 - 10; int MAXHEIGHT = 200 * 7 - 10; - Picture p = new Picture(System.in); - int[] data = p.data; - int owidth = ((int)Math.floor(Math.min(MAXWIDTH, p.height)/8.0)) * 8; // FIXME: should be ceil - int oheight = Math.min(MAXHEIGHT, p.width); + int owidth = ((int)Math.floor(Math.min(MAXWIDTH, height)/8.0)) * 8; // FIXME: should be ceil + int oheight = Math.min(MAXHEIGHT, width); int[] data2 = new int[owidth * oheight]; for(int y=0; y> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0)); - count++; - if (count % 100 == 0) Log.info(Eltron.class, "wrote " + count + " configuration octets"); - } - device.flush(); - long end = System.currentTimeMillis(); - Log.info(Eltron.class, "finished in " + ((end-begin)/1000) + "s"); - System.exit(0); - } catch (Exception e) { e.printStackTrace(); } - */ - System.exit(0); } }