updates
authoradam <adam@megacz.com>
Fri, 20 Apr 2007 05:56:04 +0000 (22:56 -0700)
committeradam <adam@megacz.com>
Fri, 20 Apr 2007 05:56:04 +0000 (22:56 -0700)
darcs-hash:20070420055604-5007d-c8e2ea2fff242d5ea98bc037cff7301e197c7fe6.gz

lib/ibex.jar [moved from jar/ibex.jar with 100% similarity]
src/com/megacz/eltron/Eltron.java
src/com/megacz/eltron/MailingLabel.java [new file with mode: 0644]

similarity index 100%
rename from jar/ibex.jar
rename to lib/ibex.jar
index a7881a8..33c090b 100644 (file)
@@ -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<owidth; y++)
             for(int x=0; x<oheight; x++)
-                data2[y+x*owidth] = data[x+(owidth-y-1)*p.width];
+                data2[y+x*owidth] = data[x+(owidth-y-1)*width];
         data = data2;
 
         for(int y=0; y<oheight; y++) {
@@ -108,37 +109,8 @@ public class Eltron {
         pw.println();
         pw.flush();
 
-
-        //pw.println("GI");
-        //pw.flush();
-
-
         pw.println("P1");
         pw.flush();
-
-        /*
-        */
-        //Log.debug(this, "consuming any leftover data on the serial port");
-
-        /*
-        AvrDrone device = new AvrDrone(detectObitsPort());
-        int count = 0;
-        try {
-            long begin = System.currentTimeMillis();
-            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
-            for(String str = br.readLine(); str != null; str = br.readLine()) {
-                long foo = Long.parseLong(str, 16);
-                device.mode4((int)(foo >> 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);
     }
 
 }
diff --git a/src/com/megacz/eltron/MailingLabel.java b/src/com/megacz/eltron/MailingLabel.java
new file mode 100644 (file)
index 0000000..641abd7
--- /dev/null
@@ -0,0 +1,45 @@
+package com.megacz.eltron;
+
+import org.ibex.util.*;
+import org.ibex.graphics.*;
+import java.io.*;
+import java.util.*;
+import gnu.io.*;
+import java.awt.image.*;
+import java.awt.*;
+import java.io.*;
+import java.awt.Color;
+import java.awt.Font;
+
+/** stupid little program to print out mailing labels from a text file */
+public class MailingLabel {
+
+    public static void main(String[] args) throws Exception {
+        System.setProperty("java.awt.headless", "true");
+        BufferedImage img = new BufferedImage(1200, 800, BufferedImage.TYPE_INT_RGB);
+        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+        boolean indent = false;
+        Font f = new Font("sansserif", 0, 50);
+        FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
+        Graphics g = img.getGraphics();
+        g.setFont(f);
+        g.setColor(Color.white);
+        g.fillRect(0, 0, img.getWidth(null), img.getHeight(null));
+        g.setColor(Color.black);
+
+        int yp = 200;
+        for(String s = br.readLine(); s!=null; s = br.readLine()) {
+            if (s.trim().equals("")) indent = true;
+
+            if (indent) s = "      "+s;
+            g.drawString(s, 100, yp);
+            yp += fm.getHeight();
+        }
+        int[] data = new int[img.getWidth(null) * img.getHeight(null)];
+        for(int x=0; x<img.getWidth(null); x++)
+            for(int y=0; y<img.getHeight(null); y++)
+                data[x+y*img.getWidth(null)] = img.getRGB(x, y);
+        Eltron.print(data, img.getWidth(null), img.getHeight(null));
+    }
+
+}