package com.codegenius.smartburglaralarm;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.Switch;

import com.google.android.things.pio.Gpio;
import com.google.android.things.pio.PeripheralManagerService;

import java.io.IOException;

public class MainActivity extends Activity {

    private static final String GPIO_ALARM_TRIGGER = "BCM21";
    private static final String TAG = "Smart Burglar" ;
    private Gpio mGpio;
    private Switch mAlarmTriggerSwitch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAlarmTriggerSwitch = (Switch) findViewById(R.id.alarmTrigger);

        mAlarmTriggerSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                try {
                    mGpio.setValue(b);
                    Log.i(TAG,"GPIO SET TO " + mGpio.getValue());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

        PeripheralManagerService manager = new PeripheralManagerService();
        try {
            mGpio = manager.openGpio(GPIO_ALARM_TRIGGER);
            mGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
        } catch (IOException e) {
            Log.w(TAG, "Unable to access GPIO", e);
        }

    }
}

@@ -237,16 +237,68 @@
 .Gpio;%0D%0A
+import com.google.android.things.pio.GpioCallback;%0D%0A
 import c
@@ -353,16 +353,16 @@
 rvice;%0D%0A
-
 %0D%0Aimport
@@ -497,16 +497,77 @@
 CM21%22;%0D%0A
+    private static final String GPIO_ALARM_MOTION= %22BCM20%22;%0D%0A
     priv
@@ -637,16 +637,27 @@
 io mGpio
+,mInputGpio
 ;%0D%0A    p
@@ -1276,24 +1276,91 @@
 tValue());%0D%0A
+                    Log.i(TAG,%22INPUT :%22 + mInputGpio.getValue());%0D%0A
             
@@ -1627,24 +1627,24 @@
 _TRIGGER);%0D%0A
-
             
@@ -1694,24 +1694,207 @@
 ALLY_LOW);%0D%0A
+            mInputGpio = manager.openGpio(GPIO_ALARM_MOTION);%0D%0A            mInputGpio.setDirection(Gpio.DIRECTION_IN);%0D%0A%0D%0A            Log.i(TAG,%22INPUT :%22 + mInputGpio.getValue());%0D%0A%0D%0A
         %7D ca

Add sense motion.