Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log display as delays, used toast instead of log #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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