Oracle Java Wireless Client

com.oracle.deviceaccess.gpio
Interface GPIOPin

All Superinterfaces:
Peripheral

public interface GPIOPin
extends Peripheral

Interface for GPIO pin.

Application can access each GPIO pin through this interface. Each GPIO pin has its own ID. ID is integer value.

Application can obtain value of current GPIO pin by using getValue() method and set specific value to GPIO pin by using setValue(boolean) method.

Hint may be used for getting more detailed information about given GPIO pin. For example, If button for toggling LED is attached to "pin10". then OEM can assign hint as "LED switch". this can be used for generating more readable source code.

Application can read value from pin by using polling. but event driven way (interrupt) is also supported by registering listener for GPIO pin.In order to use interrupt. first, application implement PinListener and then register it with setInputListener() method. then notification begins. application can stop notification and remove listener by calling removeInputListener().Listener can be set just only for input pin.this means interrupt is only supported by input pins. If try to set listener to output pins then it will get InvalidOperationException

Listener for GPIO port is also available.

 class GPIOInterruptTest implement PinListener{
  ...
   public void startRead(){
       GPIOPin pin = GPIO.getPin(pinID);
     
       pin.setInputListener(this);
   }
   ...
   void valueChanged(GPIOPin pin,boolean value){
      System.out.println("pin value" + value);
   }
...
}

 

Application should return GPIOPin by calling release() method of Peripheral interface when GPIOPin is no longer used.


Field Summary
static int INPUT
           
static int OUTPUT
           
 
Method Summary
 int getDirection()
          Returns the current direction of pin.
 boolean getValue()
          Returns the current value of the pin, this can be called on both outputs and inputs.
 void setDirection(int direction)
          Set the current direction of pin.
 void setInputListener(PinListener listener)
          Register listener for receiving callback from input pin.
 void setValue(boolean value)
          Set pin value.
 
Methods inherited from interface com.oracle.deviceaccess.Peripheral
close, getID, getName
 

Field Detail

INPUT

static final int INPUT
See Also:
Constant Field Values

OUTPUT

static final int OUTPUT
See Also:
Constant Field Values
Method Detail

getValue

boolean getValue()
                 throws java.io.IOException,
                        PeripheralNotAvailableException
Returns the current value of the pin, this can be called on both outputs and inputs.

Returns:
true if pin is currently high
Throws:
java.lang.SecurityException - throws when application has not enough permission.
java.io.IOException - error occured while writing data to port.
PeripheralNotAvailableException

setValue

void setValue(boolean value)
              throws java.io.IOException,
                     PeripheralNotAvailableException
Set pin value. InvalidOperationException will be thrown if try to set value to output pin.

Parameters:
value - binary value
Throws:
java.lang.SecurityException - throws when application has not enough permission.
java.io.IOException - error occured while writing data to port.
PeripheralNotAvailableException

getDirection

int getDirection()
                 throws java.io.IOException,
                        PeripheralNotAvailableException
Returns the current direction of pin. Check whether current pin is output pin or input pin.

Returns:
OUTPUT or INPUT
Throws:
java.io.IOException
PeripheralNotAvailableException

setDirection

void setDirection(int direction)
                  throws PeripheralNotAvailableException,
                         java.io.IOException
Set the current direction of pin. Change the direction of current GPIO pin.

Parameters:
direction - OUTPUT for output pin and INPUT for input pin
Throws:
java.lang.SecurityException - throws when application has not enough permission.
PeripheralNotAvailableException
java.io.IOException

setInputListener

void setInputListener(PinListener listener)
                      throws PeripheralNotAvailableException
Register listener for receiving callback from input pin. Notification will be automatically begin after registering completed.
InvalidOperationException will be thrown if try to set listener to output pin. If try to register listener when another listener is already registered then the second call for this method will override first one.

Parameters:
listener - Listener for this pin.ad
Throws:
java.lang.SecurityException - throws when application has not enough permission.
PeripheralNotAvailableException

Oracle Java Wireless Client

Copyright (c) 1990, 2012, Oracle and/or its affiliates. All rights reserved.