com.dexterind.gopigo.components
Class Board

java.lang.Object
  extended by com.dexterind.gopigo.components.Board

public class Board
extends java.lang.Object

Defines all the methods to get access to the resources connected to the board. It also returns the status, the voltage and the firmware version of the board.

Author:
marcello

Field Summary
private static byte ADDRESS
          The device's address.
private  Debug debug
          The debug object.
private  I2CDevice device
          The I2CDevice object.
private static Board instance
          The instance of the current object.
private static byte PIN_MODE_INPUT
          The input mode for the pin.
private static byte PIN_MODE_OUTPUT
          The output mode for the pin.
 
Constructor Summary
Board()
           
 
Method Summary
 int analogRead(int pin)
          Executes an analog read on the pin.
 int analogWrite(int pin, int value)
          Executes an analog write on the pin.
 int digitalRead(int pin)
          Executes a digital read on the pin.
 int digitalWrite(int pin, int value)
          Executes a digital write on the pin.
static Board getInstance()
          Provides a global point of access to the Board instance.
 void init()
          Initializes the board executing a writing test catching the error.
 byte[] readI2c(int numberOfBytes)
          Reads the number of bytes from the I2C device.
 int[] readStatus()
          Reads the current status.
 int revision()
          Returns the board revision.
 int setPinMode(int pin, int pinMode)
          Sets the pin mode to use on the pin.
 void sleep(int msec)
          Executes a sleep on the thread for the number of milliseconds.
 float version()
          Returns the firmware version.
 double volt()
          Returns the current voltage on the board.
 int writeI2c(int... bytes)
          Writes the bytes to the I2C device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static Board instance
The instance of the current object.


device

private final I2CDevice device
The I2CDevice object.


PIN_MODE_OUTPUT

private static final byte PIN_MODE_OUTPUT
The output mode for the pin.

See Also:
Constant Field Values

PIN_MODE_INPUT

private static final byte PIN_MODE_INPUT
The input mode for the pin.

See Also:
Constant Field Values

ADDRESS

private static final byte ADDRESS
The device's address.

See Also:
Constant Field Values

debug

private Debug debug
The debug object.

Constructor Detail

Board

public Board()
      throws java.io.IOException,
             java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException
Method Detail

getInstance

public static Board getInstance()
                         throws java.io.IOException,
                                java.lang.InterruptedException
Provides a global point of access to the Board instance.

Returns:
the Board instance.
Throws:
java.io.IOException
java.lang.InterruptedException

writeI2c

public int writeI2c(int... bytes)
             throws java.io.IOException
Writes the bytes to the I2C device.

Parameters:
bytes - The buffer to write.
Returns:
A status code.
Throws:
java.io.IOException

readI2c

public byte[] readI2c(int numberOfBytes)
               throws java.io.IOException
Reads the number of bytes from the I2C device.

Parameters:
numberOfBytes - The length of the buffer to read.
Returns:
The buffer.
Throws:
java.io.IOException

digitalRead

public int digitalRead(int pin)
                throws java.io.IOException
Executes a digital read on the pin.

Parameters:
pin - The pin to use for the reading.
Returns:
The read bytes.
Throws:
java.io.IOException

digitalWrite

public int digitalWrite(int pin,
                        int value)
                 throws java.io.IOException
Executes a digital write on the pin.

Parameters:
pin - The ping to use for the writing.
value - The value to write.
Returns:
A status code.
Throws:
java.io.IOException

analogRead

public int analogRead(int pin)
               throws java.io.IOException
Executes an analog read on the pin.

Parameters:
pin - The ping to use for the reading.
Returns:
The read value.
Throws:
java.io.IOException

analogWrite

public int analogWrite(int pin,
                       int value)
                throws java.io.IOException
Executes an analog write on the pin.

Parameters:
pin - The ping to use for the writing.
value - The value to write.
Returns:
A status code.
Throws:
java.io.IOException

setPinMode

public int setPinMode(int pin,
                      int pinMode)
               throws java.io.IOException
Sets the pin mode to use on the pin.

Parameters:
pin - The ping to set.
pinMode - The mode to set. 1 is OUTPUT, 0 is INPUT
Returns:
A status code.
Throws:
java.io.IOException

sleep

public void sleep(int msec)
Executes a sleep on the thread for the number of milliseconds.

Parameters:
msec - The value of the sleep in milliseconds.

init

public void init()
Initializes the board executing a writing test catching the error.


volt

public double volt()
            throws java.io.IOException
Returns the current voltage on the board.

Returns:
The current voltage in volts.
Throws:
java.io.IOException

version

public float version()
              throws java.io.IOException
Returns the firmware version.

Returns:
The firmware version.
Throws:
java.io.IOException

revision

public int revision()
             throws java.io.IOException
Returns the board revision.

Returns:
The board revision.
Throws:
java.io.IOException

readStatus

public int[] readStatus()
                 throws java.io.IOException
Reads the current status.

Returns:
Returns the current status.
Throws:
java.io.IOException