1 package com.megacz.eltron;
3 import org.ibex.util.*;
4 import org.ibex.graphics.*;
11 If you're on a mac and you get the error below, you need to create
12 /var/lock and make it writable.
14 Exception in thread "main" gnu.io.PortInUseException: No such file or directory in open
15 at gnu.io.RXTXPort.open(Native Method)
16 at gnu.io.RXTXPort.<init>(RXTXPort.java:84)
17 at com.megacz.eltron.Eltron.detectPort(Eltron.java:26)
18 at com.megacz.eltron.Eltron.print(Eltron.java:37)
19 at com.megacz.eltron.Eltron.main(Eltron.java:14)
24 /** code to control an Eltron */
27 public static void main(String[] s) throws Exception {
28 Picture p = new Picture(System.in);
29 print(p.data, p.width, p.height);
32 public static SerialPort detectPort() throws Exception {
33 Enumeration e = CommPortIdentifier.getPortIdentifiers();
34 while(e.hasMoreElements()) {
35 CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
36 Log.info(Eltron.class, "detected " + cpi.getName());
37 if (cpi.getName().indexOf("usbserial")!=-1) {
38 SerialPort ret = new RXTXPort(cpi.getName());
39 Log.info(Eltron.class, "returning " + ret);
43 SerialPort ret = new RXTXPort("/dev/ttyS0");
44 Log.info(Eltron.class, "returning " + ret);
48 public static void print(int[] data, int width, int height) throws Exception {
49 SerialPort sp = detectPort();
51 // you'll need to run this once at 9600 to tell the built-in eeprom to switch to 38,400kbps
52 //sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
53 sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
55 OutputStream out = sp.getOutputStream();
56 InputStream in = sp.getInputStream();
58 PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
62 // uncomment this code the first time you run it (at 9600bps)
64 System.out.println("rebooting device...");
69 System.out.println("rebooted.");
70 try { Thread.sleep(3000); } catch (Exception e) { }
71 System.out.println("setting comm parameters...");
75 pw.println("Y38,N,8,1");
77 System.out.println("set.");
78 try { Thread.sleep(2000); } catch (Exception e) { }
86 try { Thread.sleep(2000); } catch (Exception e) { }
94 int MAXWIDTH = 200 * 5 - 10;
95 int MAXHEIGHT = 200 * 7 - 10;
96 int owidth = ((int)Math.floor(Math.min(MAXWIDTH, height)/8.0)) * 8; // FIXME: should be ceil
97 int oheight = Math.min(MAXHEIGHT, width);
98 int[] data2 = new int[owidth * oheight];
99 for(int y=0; y<owidth; y++)
100 for(int x=0; x<oheight; x++)
101 data2[y+x*owidth] = data[x+(owidth-y-1)*width];
104 for(int y=0; y<oheight; y++) {
105 pw.println("GW0,"+y+","+owidth/8+",1");
107 DataOutputStream dout = new DataOutputStream(out);
108 System.out.println("y="+y);
109 for(int x=0; x<owidth; x+=8) {
111 for(int i=0; i<Math.min(8, owidth-x); i++) {
112 int dat = data[y*owidth+x+i];
114 if (dat==0) continue;