com.sentilla.platform.tmote
Class DigitalPin

java.lang.Object
  extended by com.sentilla.platform.tmote.Action
      extended by com.sentilla.platform.tmote.DigitalPin
All Implemented Interfaces:
Action, DigitalPin
Direct Known Subclasses:
InterruptPin

public class DigitalPin
extends Action
implements DigitalPin

An object representation of a digital input/output pin for the Tmote platform.

Creates an action of a specific unit of digital input/output. The action verbs are read and write. Its setters are setWrite and setRead. Its main getter is getValue. Its auxiliary getter getId returns the identifier of a particular digital input/output pin. And getTime provides a marker of when the input/output operation occured.

NOTE: DigitalPin objects should be created by the DigitalPinDriver factory.

This instance is specific to the Tmote platform.

See Also:
DigitalPinDriver

Field Summary
protected  byte digitalPinCmd
          The Action command for this DigitalPin object.
protected  byte digitalPinId
          The digital pin id for this DigitalPin object.
protected  byte digitalPinPortmask
          The portmask to use for port-wise read/write operations.
protected  int digitalPinTime
          The time that the last operation completed.
protected  byte digitalPinValue
          The value of the digital pin after the last operation.
protected static byte EDGE_CHANGE
          Action identifier for interrupt operations (implemented by InterruptPin)
protected static byte EDGE_FALLING
          Action identifier for interrupt operations (implemented by InterruptPin)
protected static byte EDGE_RISING
          Action identifier for interrupt operations (implemented by InterruptPin)
protected static byte GET_PORT
          Action identifier for initiating a port read operation
protected static byte GET_VALUE
          Action identifier for initiating a read operation
protected static byte SET_PORT
          Action identifier for initiating a port write operation
protected static byte SET_VALUE
          Action identifier for initiating a write operation
 
Fields inherited from class com.sentilla.platform.tmote.Action
actionAuto, actionId, actionState, isolateOwner
 
Fields inherited from interface com.sentilla.system.Action
DONE, ERROR, IDLE, PENDING
 
Constructor Summary
DigitalPin(int id)
          Create an object to read and write the values of a digital input/output pin.
 
Method Summary
protected  boolean checkId(int id)
          Checks that the Id is within bounds for this platform.
 int getId()
          Asynchronous interface to get the pin id for this DigitalPin object.
 int getTime()
          Asynchronous interface to get the time that the last operation, read or write, occured.
 boolean getValue()
          Asynchronous interface to get the last value read from or written to the digital pin.
 boolean read()
          Read the value of a specified digital pin.
 boolean read(int id)
          Read the value of a specified digital pin.
 byte readPort(byte portmask)
           
 void setId(int id)
          Asynchronous interface to set the pin id for this DigitalPin object.
 DigitalPin setRead()
          Asynchronous interface to initiate a read operation.
 DigitalPin setWrite(boolean high)
          Asynchronous interface to initiate a write operation.
 void write(boolean high)
          Write a value to a specified digital pin.
 void write(int id, boolean high)
          Write a value to a specified digital pin.
 void writePort(byte portmask, byte value)
          Write the values of only a subset of pins of a port.
 
Methods inherited from class com.sentilla.platform.tmote.Action
block, block, cancel, getActionState, initAction, isDone, lookup, submit
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sentilla.system.Action
block, block, cancel, getActionState, isDone, submit
 

Field Detail

SET_VALUE

protected static final byte SET_VALUE
Action identifier for initiating a write operation

See Also:
Constant Field Values

GET_VALUE

protected static final byte GET_VALUE
Action identifier for initiating a read operation

See Also:
Constant Field Values

EDGE_FALLING

protected static final byte EDGE_FALLING
Action identifier for interrupt operations (implemented by InterruptPin)

See Also:
InterruptPin, Constant Field Values

EDGE_RISING

protected static final byte EDGE_RISING
Action identifier for interrupt operations (implemented by InterruptPin)

See Also:
InterruptPin, Constant Field Values

EDGE_CHANGE

protected static final byte EDGE_CHANGE
Action identifier for interrupt operations (implemented by InterruptPin)

See Also:
InterruptPin, Constant Field Values

SET_PORT

protected static final byte SET_PORT
Action identifier for initiating a port write operation

See Also:
Constant Field Values

GET_PORT

protected static final byte GET_PORT
Action identifier for initiating a port read operation

See Also:
Constant Field Values

digitalPinId

protected byte digitalPinId
The digital pin id for this DigitalPin object.


digitalPinCmd

protected byte digitalPinCmd
The Action command for this DigitalPin object.


digitalPinValue

protected byte digitalPinValue
The value of the digital pin after the last operation.


digitalPinPortmask

protected byte digitalPinPortmask
The portmask to use for port-wise read/write operations.


digitalPinTime

protected int digitalPinTime
The time that the last operation completed.

Constructor Detail

DigitalPin

public DigitalPin(int id)
Create an object to read and write the values of a digital input/output pin.

id is specified by port and pin value in hex. For example, Port 2, Pin 3 is represented by id 0x23.

Parameters:
id - The digital pin identifier
Throws:
IllegalArgumentException - when the given id does not exist on the tmote platform
Method Detail

checkId

protected boolean checkId(int id)
Checks that the Id is within bounds for this platform.

Parameters:
id - Pin identity to check
Returns:
true if the id is valid

write

public void write(int id,
                  boolean high)
Write a value to a specified digital pin. After setting the id of the digital pin, all future read() and write() operations will use the new pin id.

The write operation sets the pin in output mode and the pin remains in this mode after the write operation completes.

id is specified by port and pin value in hex. For example, Port 2, Pin 3 is represented by id 0x23.

Parameters:
id - The digital pin identifier.
high - true to set the pin high, false to set the pin low

write

public void write(boolean high)
Description copied from interface: DigitalPin
Write a value to a specified digital pin. The pin identity is specified at object creation by the factory.

The write operation sets the pin in output mode and the pin remains in this mode after the write operation completes.

Specified by:
write in interface DigitalPin
Parameters:
high - true to set the pin high, false to set the pin low

read

public boolean read(int id)
Read the value of a specified digital pin. After setting the id of the digital pin, all future read() and write() operations will use the new pin id.

The read operation is also used to set the pin to input mode. The value of the pin may be ignored if read() is used to set the direction of the pin to input.

id is specified by port and pin value in hex. For example, Port 2, Pin 3 is represented by id 0x23.

Parameters:
id - The digital pin identifier.
Returns:
true if the pin is high, false if the pin is low

read

public boolean read()
Description copied from interface: DigitalPin
Read the value of a specified digital pin. The pin identity is specified at object creation by the factory.

The read operation is also used to set the pin to input mode. The value of the pin may be ignored if read() is used to set the direction of the pin to input.

Specified by:
read in interface DigitalPin
Returns:
true if the pin is high, false if the pin is low

writePort

public void writePort(byte portmask,
                      byte value)
Description copied from interface: DigitalPin
Write the values of only a subset of pins of a port. The port identity is specified at object creation by the factory.

The portmask designates a subset of the pins that need to be changed (set to 1). The subset pins are set bit-to-bit.

Specified by:
writePort in interface DigitalPin
Parameters:
portmask - mask of the pins that should be changed
value - specifies the values of the pins

readPort

public byte readPort(byte portmask)

setWrite

public DigitalPin setWrite(boolean high)
Description copied from interface: DigitalPin
Asynchronous interface to initiate a write operation.

Prepares the Action to write a value but does not initiate the write operation until submit() is called.

Specified by:
setWrite in interface DigitalPin
Parameters:
high - true to set the pin high, false to set the pin low
Returns:
The DigitalPin object that has been set to the specified state

setRead

public DigitalPin setRead()
Description copied from interface: DigitalPin
Asynchronous interface to initiate a read operation.

Prepares the Action to read a value but does not initiate the read operation until submit() is called.

Specified by:
setRead in interface DigitalPin
Returns:
The DigitalPin object that has been set to the specified state

getValue

public boolean getValue()
Description copied from interface: DigitalPin
Asynchronous interface to get the last value read from or written to the digital pin.

This function will not initiate a read or write operation.

Specified by:
getValue in interface DigitalPin
Returns:
true if the value was high, false if it was low

setId

public void setId(int id)
Asynchronous interface to set the pin id for this DigitalPin object.

id is specified by port and pin value in hex. For example, Port 2, Pin 3 is represented by id 0x23.

Parameters:
id - The digital pin identifier

getId

public int getId()
Description copied from interface: DigitalPin
Asynchronous interface to get the pin id for this DigitalPin object.

id is specified by port and pin value in hex. For example, Port 2, Pin 3 is represented by id 0x23.

Specified by:
getId in interface DigitalPin
Returns:
id The digital pin identifier

getTime

public int getTime()
Description copied from interface: DigitalPin
Asynchronous interface to get the time that the last operation, read or write, occured.

Specified by:
getTime in interface DigitalPin
Returns:
the local system time in milliseconds


Copyright © 2007 Sentilla Corporation. All Rights Reserved.