1 package com.megacz.eltron;
3 import org.ibex.util.*;
4 import org.ibex.graphics.*;
9 /** code to control an Eltron */
12 public static void main(String[] s) throws Exception {
13 Picture p = new Picture(System.in);
14 print(p.data, p.width, p.height);
17 public static SerialPort detectPort() throws Exception {
18 Enumeration e = CommPortIdentifier.getPortIdentifiers();
19 while(e.hasMoreElements()) {
20 CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
21 Log.info(Eltron.class, "detected " + cpi.getName());
22 if (cpi.getName().indexOf("usbserial")!=-1) {
23 SerialPort ret = new RXTXPort(cpi.getName());
24 Log.info(Eltron.class, "returning " + ret);
28 SerialPort ret = new RXTXPort("/dev/ttyS0");
29 Log.info(Eltron.class, "returning " + ret);
33 public static void print(int[] data, int width, int height) throws Exception {
34 SerialPort sp = detectPort();
36 // you'll need to run this once at 9600 to tell the built-in eeprom to switch to 38,400kbps
37 //sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
38 sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
40 OutputStream out = sp.getOutputStream();
41 InputStream in = sp.getInputStream();
43 PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
47 // uncomment this code the first time you run it (at 9600bps)
49 System.out.println("rebooting device...");
54 System.out.println("rebooted.");
55 try { Thread.sleep(3000); } catch (Exception e) { }
56 System.out.println("setting comm parameters...");
60 pw.println("Y38,N,8,1");
62 System.out.println("set.");
63 try { Thread.sleep(2000); } catch (Exception e) { }
71 try { Thread.sleep(2000); } catch (Exception e) { }
79 int MAXWIDTH = 200 * 5 - 10;
80 int MAXHEIGHT = 200 * 7 - 10;
81 int owidth = ((int)Math.floor(Math.min(MAXWIDTH, height)/8.0)) * 8; // FIXME: should be ceil
82 int oheight = Math.min(MAXHEIGHT, width);
83 int[] data2 = new int[owidth * oheight];
84 for(int y=0; y<owidth; y++)
85 for(int x=0; x<oheight; x++)
86 data2[y+x*owidth] = data[x+(owidth-y-1)*width];
89 for(int y=0; y<oheight; y++) {
90 pw.println("GW0,"+y+","+owidth/8+",1");
92 DataOutputStream dout = new DataOutputStream(out);
93 System.out.println("y="+y);
94 for(int x=0; x<owidth; x+=8) {
96 for(int i=0; i<Math.min(8, owidth-x); i++) {
97 int dat = data[y*owidth+x+i];