Dear IOIO Users,

I'm having a problem to implement GPS Bee Kit that I have purchased from 
Seeedstudio:
http://www.seeedstudio.com/depot/GPS-Bee-kit-with-Mini-Embedded-Antenna-p-560.html

I dont see any problems in Java Code, but nothing seams to be happening, 
heres my code below: 


package android.ioio.robot;


import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.InputStream;


import ioio.lib.api.Uart;

import ioio.lib.api.exception.ConnectionLostException;

import ioio.lib.util.BaseIOIOLooper;

import ioio.lib.util.IOIOLooper;


import com.example.ioiotest.R;


import android.net.Uri;

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.graphics.Color;

import android.graphics.drawable.ColorDrawable;

import android.text.Html;

import android.view.Menu;

import android.view.MenuInflater;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.Window;

import android.view.WindowManager;

import android.widget.Button;

import android.widget.RelativeLayout;

import android.widget.TextView;

import android.widget.Toast;


public class Sensor1 extends Activity {

TextView txtLatitude, txtLongitude; 

Button btnGMaps; 


     public void onCreate(Bundle savedInstanceState) { 

        super.onCreate(savedInstanceState); 

        setContentView(R.layout.sensor1_layout); 

        

        txtLatitude = (TextView)findViewById(R.id.txtLatitude); 

        txtLongitude = (TextView)findViewById(R.id.txtLongitude); 

        btnGMaps = (Button)findViewById(R.id.btnGMaps); 

        btnGMaps.setEnabled(false); 

    } 

    

    class Looper extends BaseIOIOLooper { 

    Uart uart; 

    InputStream in; 

    

    byte[] read; 

    double latitude, longitude; 

    

        protected void setup() throws ConnectionLostException { 

        uart = ioio_.openUart(2, 1, 9600, Uart.Parity.NONE, Uart.StopBits.
ONE); 

        in = uart.getInputStream(); 


         btnGMaps.setOnClickListener(new OnClickListener() { 

        public void onClick(View v) { 

        Intent intent = new Intent(android.content.Intent.ACTION_VIEW 

        , Uri.parse("geo:" + String.valueOf(latitude) + "," 

        + String.valueOf(longitude))); 

        startActivity(intent); 

        } 

        }); 

        

            runOnUiThread(new Runnable() { 

                public void run() { 

                    Toast.makeText(getApplicationContext(), 

                            "Connected!", Toast.LENGTH_SHORT).show(); 

                }        

            }); 

        } 


         public void loop() throws ConnectionLostException { 

try { 

        read = new byte[1]; 

        in.read(read); 

        

        if(read[0] == (byte)'$') { 

        read = new byte[6]; 

in.read(read); 


 if(new String(read).equals("GPGLL,")) { 

        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 


         while(!new String(read).equals(",")) { 

        read = new byte[1]; 

        in.read(read); 

        baos.write(read); 

        } 

        

        byte[] buffer = baos.toByteArray(); 

        String str = (new String(buffer)); 

        str = str.substring(0, str.length() - 1); 

        

        if(!str.equals("")) { 

        double data = Double.valueOf(str); 

        

        if(str.equals(String.valueOf(data))) { 

        latitude = Double.valueOf(String.format("%.6f", 
toDegreeDecimal(data))); 

        read = new byte[2]; 

        in.read(read); 

        

if(new String(read).equals("N,")) { 

        baos = new ByteArrayOutputStream(); 


         while(!new String(read).equals(",")) { 

        read = new byte[1]; 

        in.read(read); 

        baos.write(read); 

        } 


         buffer = baos.toByteArray(); 

        str = new String(buffer); 

        str = str.substring(0, str.length() - 1); 

        data = Double.valueOf(str); 

        

        if(str.equals(String.valueOf(data))) { 

        longitude = Double.valueOf(String.format("%.6f", 
toDegreeDecimal(data))); 

            runOnUiThread(new Runnable() { 

                public void run() { 

                txtLatitude.setText(String.format("%.6f", latitude)); 

                txtLongitude.setText(String.format("%.6f", longitude)); 

                    btnGMaps.setEnabled(true); 

                }        

            }); 

        } 

} 

        } 

        } 

        

        else { 

            runOnUiThread(new Runnable() { 

                public void run() { 

                txtLatitude.setText("No signal"); 

                txtLongitude.setText("No signal"); 

                    btnGMaps.setEnabled(false); 

                }        

            }); 

        } 

} 

        } 


 } catch (IOException e) { 

        e.printStackTrace(); 

        } 

        } 

        

        public double toDegreeDecimal(double value) {        

return (int)(value / 100) + (value % 100 / 60); 

        } 

    } 


     protected IOIOLooper createIOIOLooper() { 

        return new Looper(); 

    } 

}

-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to