com.alarexgroup.m2mplf.adapters.io
Class PinAdapter

java.lang.Object
  extended by com.alarexgroup.m2mplf.adapters.io.PinAdapter
All Implemented Interfaces:
ATCommanderListener
public class PinAdapter
extends java.lang.Object
implements ATCommanderListener

This adapter lets you work with GPIO pins, setup their mode, value or monitor changes in their signals.

Example of monitoring pin's status. If the status of GPI01 is changed, this change will be copied to GPIO2.

import com.alarexgroup.m2mplf.M2Mlet;
import com.alarexgroup.m2mplf.adapters.io.PinAdapter;
import com.alarexgroup.m2mplf.adapters.io.PinAdapterListener;
import com.alarexgroup.m2mplf.adapters.io.PinConfiguration;
import com.alarexgroup.m2mplf.adapters.io.exceptions.PinIOException;
import com.alarexgroup.m2mplf.logging.Logger;

public class MyFirstM2M extends M2Mlet implements PinAdapterListener{
    public PinAdapter pinAdapter;
  
    public MyFirstM2M() {
    }
    
    
    public void appStart() {
        PinConfiguration pinConf = new PinConfiguration();
        pinConf.configurePin(0,PinConfiguration.PIN_MODE_OPEN,PinConfiguration.PIN_DIRECTION_INPUT);
        pinConf.configurePin(1,PinConfiguration.PIN_MODE_OPEN,PinConfiguration.PIN_DIRECTION_OUTPUT);
        pinAdapter = PinAdapter.getPinAdapter(this);
        pinAdapter.openDriver();
        pinAdapter.submitPinConfiguration(pinConf);
        try {
            pinAdapter.startPoolingPin(0);
        catch (PinIOException ex) {
            ex.printStackTrace();
        }
        
    }
    
    public void appStop(boolean unconditional) {
        
    }
    
    public void appPause() {
        
    }
    
    public void onPinValueChanged(int pinIndex, boolean value) {
        try {
            pinAdapter.writePinValue(1,value);
        catch (PinIOException ex) {
            ex.printStackTrace();
        }
    }
       
}

Constructor Summary
PinAdapter()
           
 
Method Summary
 void closeDriver()
          Ends current work od the adapter and releases HW resources of module
static PinAdapter getPinAdapter(PinAdapterListener listener)
          Creates an instance of this adapter and returns referrence
 PinConfiguration getPinConfiguration()
          Returns current pin configuration profile
 int getPinDirection(int pinIndex)
          Returns pin mode
 int getPinMode(int pinIndex)
          Returns working state of the specified pin, whether it is opened or closed.
 void onURCEvent(java.lang.String urc)
          This method is for internal use to listen for PIN pooling notifications
 void openDriver()
          Method initializes the adapter
 boolean readPinValue(int pinIndex)
          Returns current value of the specified pin.
 void startPoolingPin(int pinIndex)
          Start pin monitoring.
 void stopPoolingPin(int pinIndex)
          Stops specified pin monitoring.
 void submitPinConfiguration(PinConfiguration newPinConfiguration)
          Setup each pin according to the created profile PinConfiguration.
 void writePinValue(int pinIndex, boolean value)
          Sets the value of the sĂșecified OUTPUT pin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PinAdapter

public PinAdapter()
Method Detail

getPinAdapter

public static PinAdapter getPinAdapter(PinAdapterListener listener)
Creates an instance of this adapter and returns referrence

Parameters:
listener - Interface for hanling events from PINs
Returns:
odkaz na aktivnĂ­ PinAdapter

openDriver

public void openDriver()
Method initializes the adapter

closeDriver

public void closeDriver()
Ends current work od the adapter and releases HW resources of module

submitPinConfiguration

public void submitPinConfiguration(PinConfiguration newPinConfiguration)
Setup each pin according to the created profile PinConfiguration.

Parameters:
newPinConfiguration - Pin configuration

getPinConfiguration

public PinConfiguration getPinConfiguration()
Returns current pin configuration profile

Returns:
current profile

getPinDirection

public int getPinDirection(int pinIndex)
Returns pin mode

Parameters:
pinIndex - pin id
Returns:
pin mode
PinConfiguration.PIN_DIRECTION_OUTPUT - output pin
PinConfiguration.PIN_DIRECTION_OUTPUT - input pin

getPinMode

public int getPinMode(int pinIndex)
Returns working state of the specified pin, whether it is opened or closed.

Parameters:
pinIndex - pin id
Returns:
Pin status
PinConfiguration.PIN_MODE_OPEN - pin is opened and is active
PinConfiguration.PIN_MODE_CLOSE _ pin is closed, not usable

readPinValue

public boolean readPinValue(int pinIndex)
                     throws PinIOException
Returns current value of the specified pin. Works only for pins in VSTUP (IPNUT) mode

Parameters:
pinIndex - pin id
Returns:
TRUE or FALSE
Throws:
PinIOException - in case there was a problem with pin

writePinValue

public void writePinValue(int pinIndex,
                          boolean value)
                   throws PinIOException
Sets the value of the sĂșecified OUTPUT pin

Parameters:
value - True or False
pinIndex - pin id
Throws:
PinIOException - in case there was a problem with pin

startPoolingPin

public void startPoolingPin(int pinIndex)
                     throws PinIOException
Start pin monitoring. If there is a change noticed, method PinAdapterListener.onPinValueChanged(int, boolean) is called
Can be used only on input pins. It is possible to monitor multiple pins simultaneously.

Parameters:
pinIndex - pin id
Throws:
PinIOException - in case there was a problem with pin

stopPoolingPin

public void stopPoolingPin(int pinIndex)
                    throws PinIOException
Stops specified pin monitoring.

Parameters:
pinIndex - pin id
Throws:
PinIOException - in case there was a problem with pin

onURCEvent

public void onURCEvent(java.lang.String urc)
This method is for internal use to listen for PIN pooling notifications

Specified by:
onURCEvent in interface ATCommanderListener
Parameters:
urc -