a7a4decef021bbdb85f279d241c2949c73fb6517
[slipway.git] / src / edu / berkeley / obits / AtmelSerial.java
1 package edu.berkeley.obits;
2
3 import edu.berkeley.obits.device.atmel.*;
4 import org.ibex.util.*;
5 import java.io.*;
6 import java.util.*;
7 import gnu.io.*;
8
9 public class AtmelSerial {
10
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(AtmelSerial.class, "trying " + cpi.getName());
16             if (cpi.getName().startsWith("/dev/cu.usbserial-")) return new RXTXPort(cpi.getName());
17             if (cpi.getName().startsWith("/dev/ttyS0")) return new RXTXPort(cpi.getName());
18         }
19         Log.info(AtmelSerial.class, "returning null...");
20         return null;
21     }
22
23     public static void main(String[] s) throws Exception {
24         AvrDrone device = new AvrDrone(detectObitsPort());
25         At40k at40k = new At40k.At40k10(device);
26         int count = 0;
27         try {
28             long begin = System.currentTimeMillis();
29             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
30             for(String str = br.readLine(); str != null; str = br.readLine()) {
31                 long foo = Long.parseLong(str, 16);
32                 device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >>  8), (int)(foo >>  0));
33                 count++;
34                 if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
35             }
36             device.flush();
37             long end = System.currentTimeMillis();
38             Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
39             Thread.sleep(3000);
40             Log.info(AtmelSerial.class, "issuing command");
41
42             //at40k.iob_top(2, true).oe(false);
43             //at40k.iob_top(2, false).oe(false);
44             //at40k.iob_top(1, true).oe(false);
45
46             // this command confirmed to turn *on* led0
47             //at40k.iob_top(1, false).output(0);
48             /*
49             for(int i=0; i<20; i++) {
50                 at40k.iob_bot(i, false).output(0);
51                 at40k.iob_bot(i, true).output(0);
52             }
53             */
54
55             //System.out.println("tick");
56                 //Thread.sleep(3000);
57                 //System.out.println("tick");
58                 //at40k.cell(0x01, 0x17).xlut((byte)0x);
59
60             at40k.cell(0x04, 0x17).xlut((byte)~0x10);
61             at40k.cell(0x04, 0x17).ylut((byte)0x10);
62             at40k.cell(0x04, 0x17).xo(true);
63
64
65             /*
66             at40k.cell(0x01, 0x17).xin(4);
67             at40k.cell(0x01, 0x17).yin(4);
68             at40k.cell(0x01, 0x16).ylut((byte)0x00);
69             device.mode4(2, 0x17, 0x01, 0);
70
71             for(int i=0; i<10; i++) {
72                 Thread.sleep(3000);
73                 System.out.println("tick");
74                 //at40k.cell(0x01, 0x17).xlut((byte)0xFF);
75                 at40k.cell(0x00, 0x17).ylut((byte)0x00);
76                 device.flush();
77                 Thread.sleep(3000);
78                 System.out.println("tick");
79                 //at40k.cell(0x01, 0x17).xlut((byte)0x00);
80                 at40k.cell(0x00, 0x17).ylut((byte)0xFF);
81                 device.flush();
82             }
83             */
84
85
86             /*
87             at40k.iob_top(0, true).output(0);
88             at40k.iob_top(0, true).oe(false);
89             at40k.iob_top(0, true).pullup();
90             device.flush();
91             Thread.sleep(3000);
92
93             Log.info(AtmelSerial.class, "issuing command");
94             at40k.iob_top(1, true).pulldown();
95             device.flush();
96             */
97             Log.info(AtmelSerial.class, "done");
98             System.exit(0);
99         } catch (Exception e) { e.printStackTrace(); }
100     }
101
102 }