Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.android.things.pio.PeripheralManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import java.io.IOException;

Expand All @@ -39,16 +40,28 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Starting ButtonActivity");



try {

String pinName = BoardDefaults.getGPIOForButton();
mButtonGpio = PeripheralManager.getInstance().openGpio(pinName);
// Initialize the pin as an input
mButtonGpio.setDirection(Gpio.DIRECTION_IN);
mButtonGpio.setEdgeTriggerType(Gpio.EDGE_FALLING);
// High voltage is considered active
mButtonGpio.setActiveType(Gpio.ACTIVE_LOW);

// Register for all state changes
mButtonGpio.setEdgeTriggerType(Gpio.EDGE_RISING);


mButtonGpio.registerGpioCallback(new GpioCallback() {
int counter=0;
@Override
public boolean onGpioEdge(Gpio gpio) {
Log.i(TAG, "GPIO changed, button pressed");
// Return true to continue listening to events
counter++;
Toast.makeText(ButtonActivity.this, "Button clicked counter :"+counter, Toast.LENGTH_SHORT).show();
return true;
}
});
Expand Down