Metawear(GPIO)

Hi Eric,

I also get some problem with the GPIO pin notification. Here is my code:

 public static class PlaceholderFragment extends Fragment implements ServiceConnection {

private GPIO gpioCtrllr;
public PlaceholderFragment() {
}

public void setBtDevice(BluetoothDevice device) {

mwController= mwService.getMetaWearController(device);
mwController.setRetainState(false);

mwController.addDeviceCallback(new MetaWearController.DeviceCallbacks() {

@Override
public void connected() {

gpioCtrllr= (GPIO) mwController.getModuleController(Module.GPIO);
gpioCtrllr.setPinChangeType((byte) 10, GPIO.ChangeType.ANY);
gpioCtrllr.enablePinChangeNotification((byte) 0);

Toast.makeText(getActivity(), R.string.toast_connected, Toast.LENGTH_SHORT).show();
}
}).addModuleCallback(new GPIO.Callbacks() {
@Override
public void pinChangeDetected(byte pin, byte state) {
Log.i("MainActivity", String.format(Locale.US, "pin= %d, pin changed= %d",
pin, state));
}
});
mwController.connect();}


and the logcat show "D/BluetoothGatt﹕ onNotify() - Device=D0:98:80:5B:E7:91 UUID=326a9006-85cb-9195-d9dd-464cfbbae75a" all the time even when I press the sensor to change the voltage up to 2.5V
and how the metawear notify me when the state changed by the way.

thanks,
Mark




Comments

  • You configured pin change notifications for pin 10 but are enabling notifications for pin 0.
  • Ok, thanks Eric, so meaing I change the 10 to 0 if I want to monitor the pin 0 state. but the Document is '10', I just copy from there. thanks
  • and how the metawear notify me when the state changed? thanks Eric
  • Ah I see, that's a type on my part; code snippet has been fixed.  The MetaWear notifies you through the pinChangeDetected callback function, as outlined in the code block you were referencing.
  • Hi Eric, 

    I understand it will notifies me by the pinChangeDetected, what you mean that is when the pin state be changed every time, it will execute what inside the 
    public void pinChangeDetected(byte pin, byte state) {
    Log.i("MainActivity", String.format(Locale.US, "pin= %d, pin changed= %d",
    pin, state));
    }
    for this case, it will log and print the sentence, which is pin=%d, pin changed= %d in the logcat right? but seem can't. 



  • edited July 2015
    Hi Eric, 

    Thank you so much! and now I can get the notification when the state changed, after adding 
    gpioCtrllr.readDigitalInput((byte) 1);
    gpioCtrllr.setDigitalInput((byte) 1, PullMode.NONE);

    so now I can get what I want to get, but can you move to the kitkat one, I have a question about the accelerometer part for acceleration storing in array Thanks again.
  • Good to hear you got everything working!
This discussion has been closed.