package org.shokai.firmata.sample;

import org.shokai.firmata.ArduinoFirmata;
import org.shokai.firmata.ArduinoFirmataEventHandler;

import java.io.*;
import java.lang.*;
import android.hardware.usb.*;

import android.app.*;
import android.content.*;
import android.os.*;
import android.util.*;

public class Main extends Activity{
    private String TAG = "ArduinoFirmataSample";
    private ArduinoFirmata arduino;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.v(TAG, "start activity");
        Log.v(TAG, ArduinoFirmata.VERSION);
        
        this.arduino = new ArduinoFirmata(this);
        final Activity self = this;
        arduino.addEventHandler(new ArduinoFirmataEventHandler(){
                public void onError(String errorMessage){
                    Log.e(TAG, errorMessage);
                }
                public void onClose(){
                    Log.v(TAG, "arduino closed");
                    self.finish();
                }
            });
        try{
            arduino.start();
            new Thread(new Runnable(){
                    public void run(){
                        while(arduino.isOpen()){
                            try{
                                Thread.sleep(1500);
                                arduino.digitalWrite(13, true);
                                arduino.analogWrite(11, 20);
                                Thread.sleep(1500);
                                arduino.digitalWrite(13, false);
                                arduino.analogWrite(11, 255);
                                Log.v(TAG+" analog read", String.valueOf(arduino.analogRead(0)));
                            }
                            catch(InterruptedException e){
                                e.printStackTrace();
                            }
                        }
                    }
                }).start();
        }
        catch(IOException e){
            e.printStackTrace();
            finish();
        }
        catch(InterruptedException e){
            e.printStackTrace();
            finish();
        }
    }
}

@@ -1122,32 +1122,79 @@
 rduino.start();%0A
+            arduino.pinMode(7, arduino.INPUT);%0A
             new 
@@ -1748,16 +1748,19 @@
 log read
+(0)
 %22, Strin
@@ -1794,16 +1794,119 @@
 d(0)));%0A
+                                Log.v(TAG+%22 digital read(7)%22, String.valueOf(arduino.digitalRead(7)));%0A
         

test digitalRead