![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
Here is some source code in java for a remote compass display.
I wrote it so a cheap gps and old laptop could do something useful in a plane. The cheap gps usually has no remote antenna, so the gps is remoted to say, the window area. It is a low budget version of the old style DG. And the nice large display on the laptop can be placed someplace for easy viewing. I hope to have a Palm version soon. That way the computer could be hungup on the window visor. Although this source should compile directly for the Palm, it requires the serial extensions that might conflict. It is set for com2, 4800, 8, no parity, NEMA. A spare electronic DG is the number one playtoy to try to make a truely useful cockpit instrument in my mind. Douglas Eagleson Gaitherbsurg, MD USA ************************************************** ******* import java.awt.*; import java.io.*; import java.awt.event.*; import javax.comm.*; public class Compass2 extends Frame implements ActionListener { static String title = "GPS Remote Compass"; boolean sentence=false; boolean instring=false; boolean valid; float critlsum= (float) 1.0; //determines point where code is displayed near the FIX float one = (float) -1.0; float zero = (float) 0.0; int i; int j; String datatoo[] = new String[12]; int length; int index[]=new int[13]; //number of commas in input string int dash[]=new int[59]; int dart0[]; int dart1[]; int dart2[]; float lumsum[]=new float[3]; String data; Label labelt; Label labela; Panel panel; Panel panel2; List list; int countindex; int jax; Character doof; String outs; String outs1; String outs2; Integer ut; int counter; TextField t4; TextField t5; String Bottom;//display label string TextField ltop; TextField lbot; protected static String BottomM= "0|||||||350|||||||340|||||||330|||||||320|||||||3 10|||||||300|||||||290|||||||280|||||||270|||||||2 60|||||||250|||||||240|||||||230|||||||220|||||||2 10|||||||200|||||||190|||||||180|||||||170|||||||1 60|||||||150|||||||140|||||||130|||||||120|||||||1 10|||||||100|||||||090|||||||080|||||||070|||||||0 60|||||||050|||||||040|||||||030|||||||020|||||||0 10|||||||36"; protected static String Top = " | "; private SerialPort sport; InputStream inie; BufferedInputStream in; private CommPortIdentifier portid; Integer bit; int pig; byte boll[]; String inn; GridLayout layout; int elix; //approach array index public Compass2() { System.out.println("initialize start"); this.setTitle(title); //************************************************** ****************** try{ portid= CommPortIdentifier.getPortIdentifier("COM2"); }catch(Exception e){System.out.println("error at commportidentifier");} try{ sport= (SerialPort)portid.open("GPSchecklist",30000); }catch(Exception e){System.out.println("error at open port");} try{ sport.setSerialPortParams(4800,8,1,0); }catch(Exception dg){System.out.println("error at set baud");} try{ inie=sport.getInputStream(); in= new BufferedInputStream( inie, 1024 ); }catch(Exception e) {System.out.println("error at input stream");} System.out.println("comm initialized"); panel = new Panel();//main panel Panel panel1 = new Panel(); Panel panel2 = new Panel(); Panel panel3 = new Panel(); //************************************************** ********** labelt=new Label("GPS Remote Compass"); labelt.setFont(new Font("Times-Roman",Font.BOLD+Font.ITALIC,16)); GridLayout grid = new GridLayout(2,3,0,0); panel2.setLayout(grid); Label l4=new Label(" Speed"); l4.setFont(new Font("Monospaced",Font.BOLD,16)); Label l5=new Label("Knots."); l5.setFont(new Font("Monospaced",Font.BOLD,16)); Label l6=new Label(" Track"); l6.setFont(new Font("Monospaced",Font.BOLD,16)); Label l7=new Label("Degrees"); l7.setFont(new Font("Monospaced",Font.BOLD,16)); t4=new TextField(); t4.setFont(new Font("Monospaced",Font.BOLD,16)); t5=new TextField(); t5.setFont(new Font("Monospaced",Font.BOLD,16)); panel2.add(l4); panel2.add(t5); panel2.add(l5); panel2.add(l6); panel2.add(t4); panel2.add(l7); //************************************************** ***************** GridLayout grid2 = new GridLayout(2,1,0,0); panel1.setLayout(grid2); ltop=new TextField("test",30); ltop.setFont(new Font("Monospaced",Font.BOLD,16)); lbot=new TextField("tedd",30); lbot.setFont(new Font("Monospaced",Font.BOLD,16)); panel1.add(ltop); panel1.add(lbot); //************************************************** **************** Button off = new Button("Start"); off.addActionListener(this); panel3.add(off); //add action event source IF inside actionperformed to stop thread //************************************************** ***************** panel.add(panel3); panel.add(panel2); panel.add(panel1); // off.addActionListener(this); System.out.println("A location"); this.add(panel); this.setBounds(0,0,350,250); this.setVisible(true); panel.setVisible(true); boll= new byte[1]; System.out.println("b location"); } //end of constructor public static void main(String args[]) { Compass2 check = new Compass2(); } public void actionPerformed(ActionEvent e) { boolean bwhil = true; counter = 4; //sequence counter while(bwhil){ //big while countindex=0; jax = 0; float bogus2 = 1; sentence = false; instring=false; valid=false; while(valid==false){ while(sentence==false) { instring=false; data= new String(""); while(instring==false) { try { pig=in.read(); bit = new Integer(pig); boll[0] = bit.byteValue(); }catch(Exception he) { } if(pig == 13) instring = true; inn = new String(boll); data = data + inn; } // end of inner while if(data.substring(1,7).equals("$GPRMC") ) sentence=true; } // end of while valid=true; length=data.length(); for(i=0; ilength; i++) { if (data.substring(i,i+1).equals(",")) { index[jax]=i; jax=jax+1; } if( jax == 13) { i= length; valid=false; } //adjust index[] array size to match the input sentence, number of "commas". } } // end valid while index[10]=length; for(j=0;j10;j++){ datatoo[j]=new String(data.substring((index[j]+1),index[j+1]) ); // [j]+1 is an inclusive index, while the end of the substring is exclusive } t4.setText(datatoo[7]); t5.setText(datatoo[6]); Float f = new Float(datatoo[7]); int heading = f.intValue(); heading= -1*(heading-360); if ((heading = 344) && (heading = 15)) { Bottom = BottomM.substring( (heading-15), (heading+15) ); }; if((heading 344) && (heading=360)){ Bottom = BottomM.substring( (heading-15) , 360); Bottom=Bottom+BottomM.substring( 0, (15-(360-heading)) ); }; if((heading 15) && (heading0)){ Bottom = BottomM.substring( (360-15+heading) , 360); Bottom=Bottom+BottomM.substring( 0, (heading+15) ); }; ltop.setText(Top); lbot.setText(Bottom); //************************************************** ******************** } //end of big while } //end of action event } //end of class |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
4130 sheet source | Leon McAtee | Home Built | 7 | May 2nd 04 08:29 PM |
Remote controled weapons in WWII | Charles Gray | Military Aviation | 12 | January 21st 04 05:07 AM |
"Whiskey" for compass? | dale | Home Built | 10 | December 17th 03 11:16 PM |
3 1/8 inch compass | Steve Beaver | Home Built | 2 | October 21st 03 12:20 AM |
Source for copper crush gaskets??? | Jim | Home Built | 2 | August 22nd 03 09:44 PM |