SunSPOT API V5.0


com.sun.spot.sensorboard
Class EDemoBoard

java.lang.Object
  extended by com.sun.spot.sensorboard.EDemoBoard
All Implemented Interfaces:
IDemoBoard

public class EDemoBoard
extends Object
implements IDemoBoard

This class reflects all of the functionality of the EDemoBoard to a SPOT application. The old methods bindServo() & bindToneGenerator() have been removed. Please now use "new Servo()" & "new ToneGenerator()" passing in the IOutputPin or IOPin that they should use. This is a facade class. All the real work is done in the EDemoController class.

Author:
Ron Goldman

Field Summary
static int A0
          A0 index for array returned by getScalarInputs()
static int A1
          A1 index for array returned by getScalarInputs()
static int A2
          A2 index for array returned by getScalarInputs()
static int A3
          A3 index for array returned by getScalarInputs()
static int A4
          A4 index for array returned by getScalarInputs()
static int A5
          A5 index for array returned by getScalarInputs()
static int D0
          D0 index for array returned by getIOPins()
static int D1
          D1 index for array returned by getIOPins()
static int D2
          D2 index for array returned by getIOPins()
static int D3
          D3 index for array returned by getIOPins()
static int D4
          D4 index for array returned by getIOPins()
static int H0
          H0 index for array returned by getOutputPins()
static int H1
          H1 index for array returned by getOutputPins()
static int H2
          H2 index for array returned by getOutputPins()
static int H3
          H3 index for array returned by getOutputPins()
static int LED1
          LED1 index for array returned by getLEDs()
static int LED2
          LED2 index for array returned by getLEDs()
static int LED3
          LED3 index for array returned by getLEDs()
static int LED4
          LED4 index for array returned by getLEDs()
static int LED5
          LED5 index for array returned by getLEDs()
static int LED6
          LED6 index for array returned by getLEDs()
static int LED7
          LED7 index for array returned by getLEDs()
static int LED8
          LED8 index for array returned by getLEDs()
static String PART_ID
          Identifier string for demoboard
static int SERIAL_DATABITS_5
           
static int SERIAL_DATABITS_6
           
static int SERIAL_DATABITS_7
           
static int SERIAL_DATABITS_8
           
static int SERIAL_PARITY_EVEN
           
static int SERIAL_PARITY_NONE
           
static int SERIAL_PARITY_ODD
           
static int SERIAL_SPEED_1200
           
static int SERIAL_SPEED_19200
           
static int SERIAL_SPEED_2400
           
static int SERIAL_SPEED_28800
           
static int SERIAL_SPEED_38400
           
static int SERIAL_SPEED_4800
           
static int SERIAL_SPEED_57600
           
static int SERIAL_SPEED_600
           
static int SERIAL_SPEED_9600
           
static int SERIAL_STOPBITS_1
           
static int SERIAL_STOPBITS_2
           
static int SW1
          SW1 index for array returned by getSwitches()
static int SW2
          SW2 index for array returned by getSwitches()
 
Method Summary
 void andRegister(int reg, int val)
          Perform an AND assignment to one of the registers in the Atmega88 controller.
 int availableUART()
          Check if there are any available characters read by the UART.
 IAccelerometer3D getAccelerometer()
          Method to return the built in accelerometer.
 IADT7411 getADC()
          Method to get an object that corresponds to the ADC on the EDemoBoard.
 ITemperatureInput getADCTemperature()
          Method to get internal temperature sensor on the ADC from the EDemoBoard.
 EDemoController getEDemoController()
          Return the underlying controller used by this EDemoBoard.
 int[] getFirmwareVersion()
          Get the major and minor version information from the firmware running on the EDemoBoard.
 II2C getI2C()
          Return the controller for the I2C.
static Properties getInitialProperties()
          Get the correct set of properties for this board for its flash memory
static EDemoBoard getInstance()
          Return the global singleton for the EDemoBoard.
 IIOPin[] getIOPins()
          Method to return an array of the built in bidirectional digital pins.
 ITriColorLED[] getLEDs()
          Method that returns an array of all the built in LEDs.
 ILightSensor getLightSensor()
          Method to return the built in light sensor object.
 IOutputPin[] getOutputPins()
          Method to return an array of the built in high current output pins.
 Properties getProperties()
          Get the properties of this board.
 int getPulse(IInputPin pin, boolean dir, int timeout)
          Ask the controller for a measurement of an incoming pulse on some input pin.
 int getRegister(int reg)
          Peek method for the atmega firmware.
 IScalarInput[] getScalarInputs()
          Method to return an array of the built in analog input pins.
 ISwitch[] getSwitches()
          Method to return an array of all the built in switches on the board.
 void initUART(int baud, boolean two_stopbit)
          Initialize the UART module, set the speed and select the number of stop bits.
 void initUART(int baud, int databits, int parity, int stopbits)
          Initialize the UART module
 void orRegister(int reg, int val)
          Perform an OR assignment to one of the registers in the Atmega88 controller.
 byte readUART()
          Get the next byte from the UART.
 int readUART(byte[] b, int off, int len)
          Read the next byte from the UART plus any more currently available bytes.
 byte readUART(long timeout)
          Get the next byte from the UART.
 byte receiveUART()
          Deprecated.  
 void sendUART(byte val)
          Deprecated.  
 void setProperties(Properties p)
          Set the properties of this board
 void setPWM(IOutputPin pin, int duty)
          Request the controller maintain a pwm signal on a gpio pin.
 void setRegister(int reg, int val)
          Poke method for the Atmega88 controller, allows user to set low level registers on the part.
 void startPulse(IOutputPin pin, boolean dir, int usec)
          Ask the controller to issue a pulse on the indicated pin.
 int UARTAvailable()
          Deprecated.  
 void writeUART(byte val)
          Send a byte over the UART.
 void writeUART(byte[] msg)
          Send a byte array over the UART.
 void writeUART(byte[] msg, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to the UART.
 void writeUART(String msg)
          Send a string over the UART.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERIAL_SPEED_600

public static final int SERIAL_SPEED_600
See Also:
Constant Field Values

SERIAL_SPEED_1200

public static final int SERIAL_SPEED_1200
See Also:
Constant Field Values

SERIAL_SPEED_2400

public static final int SERIAL_SPEED_2400
See Also:
Constant Field Values

SERIAL_SPEED_4800

public static final int SERIAL_SPEED_4800
See Also:
Constant Field Values

SERIAL_SPEED_9600

public static final int SERIAL_SPEED_9600
See Also:
Constant Field Values

SERIAL_SPEED_19200

public static final int SERIAL_SPEED_19200
See Also:
Constant Field Values

SERIAL_SPEED_28800

public static final int SERIAL_SPEED_28800
See Also:
Constant Field Values

SERIAL_SPEED_38400

public static final int SERIAL_SPEED_38400
See Also:
Constant Field Values

SERIAL_SPEED_57600

public static final int SERIAL_SPEED_57600
See Also:
Constant Field Values

SERIAL_PARITY_NONE

public static final int SERIAL_PARITY_NONE
See Also:
Constant Field Values

SERIAL_PARITY_ODD

public static final int SERIAL_PARITY_ODD
See Also:
Constant Field Values

SERIAL_PARITY_EVEN

public static final int SERIAL_PARITY_EVEN
See Also:
Constant Field Values

SERIAL_STOPBITS_1

public static final int SERIAL_STOPBITS_1
See Also:
Constant Field Values

SERIAL_STOPBITS_2

public static final int SERIAL_STOPBITS_2
See Also:
Constant Field Values

SERIAL_DATABITS_5

public static final int SERIAL_DATABITS_5
See Also:
Constant Field Values

SERIAL_DATABITS_6

public static final int SERIAL_DATABITS_6
See Also:
Constant Field Values

SERIAL_DATABITS_7

public static final int SERIAL_DATABITS_7
See Also:
Constant Field Values

SERIAL_DATABITS_8

public static final int SERIAL_DATABITS_8
See Also:
Constant Field Values

SW1

public static final int SW1
SW1 index for array returned by getSwitches()

See Also:
Constant Field Values

SW2

public static final int SW2
SW2 index for array returned by getSwitches()

See Also:
Constant Field Values

D0

public static final int D0
D0 index for array returned by getIOPins()

See Also:
Constant Field Values

D1

public static final int D1
D1 index for array returned by getIOPins()

See Also:
Constant Field Values

D2

public static final int D2
D2 index for array returned by getIOPins()

See Also:
Constant Field Values

D3

public static final int D3
D3 index for array returned by getIOPins()

See Also:
Constant Field Values

D4

public static final int D4
D4 index for array returned by getIOPins()

See Also:
Constant Field Values

H0

public static final int H0
H0 index for array returned by getOutputPins()

See Also:
Constant Field Values

H1

public static final int H1
H1 index for array returned by getOutputPins()

See Also:
Constant Field Values

H2

public static final int H2
H2 index for array returned by getOutputPins()

See Also:
Constant Field Values

H3

public static final int H3
H3 index for array returned by getOutputPins()

See Also:
Constant Field Values

A0

public static final int A0
A0 index for array returned by getScalarInputs()

See Also:
Constant Field Values

A1

public static final int A1
A1 index for array returned by getScalarInputs()

See Also:
Constant Field Values

A2

public static final int A2
A2 index for array returned by getScalarInputs()

See Also:
Constant Field Values

A3

public static final int A3
A3 index for array returned by getScalarInputs()

See Also:
Constant Field Values

A4

public static final int A4
A4 index for array returned by getScalarInputs()

See Also:
Constant Field Values

A5

public static final int A5
A5 index for array returned by getScalarInputs()

See Also:
Constant Field Values

LED1

public static final int LED1
LED1 index for array returned by getLEDs()

See Also:
Constant Field Values

LED2

public static final int LED2
LED2 index for array returned by getLEDs()

See Also:
Constant Field Values

LED3

public static final int LED3
LED3 index for array returned by getLEDs()

See Also:
Constant Field Values

LED4

public static final int LED4
LED4 index for array returned by getLEDs()

See Also:
Constant Field Values

LED5

public static final int LED5
LED5 index for array returned by getLEDs()

See Also:
Constant Field Values

LED6

public static final int LED6
LED6 index for array returned by getLEDs()

See Also:
Constant Field Values

LED7

public static final int LED7
LED7 index for array returned by getLEDs()

See Also:
Constant Field Values

LED8

public static final int LED8
LED8 index for array returned by getLEDs()

See Also:
Constant Field Values

PART_ID

public static final String PART_ID
Identifier string for demoboard

See Also:
Constant Field Values
Method Detail

getInstance

public static EDemoBoard getInstance()
Return the global singleton for the EDemoBoard.

Returns:
the singleton instance of EDemoBoard.

getEDemoController

public EDemoController getEDemoController()
Return the underlying controller used by this EDemoBoard.

Returns:
the underlying controller

getADC

public IADT7411 getADC()
Method to get an object that corresponds to the ADC on the EDemoBoard.

Returns:
a-to-d converter

getADCTemperature

public ITemperatureInput getADCTemperature()
Method to get internal temperature sensor on the ADC from the EDemoBoard.

Specified by:
getADCTemperature in interface IDemoBoard
Returns:
accessor object for ADC internal temperature sensor

getLEDs

public ITriColorLED[] getLEDs()
Method that returns an array of all the built in LEDs. Note that this is only those that are actually built into the edemo board

Specified by:
getLEDs in interface IDemoBoard
Returns:
ITriColorLED array that can control all built in LEDs

getSwitches

public ISwitch[] getSwitches()
Method to return an array of all the built in switches on the board. Note this is only the switches, SW1 & SW2, that are built into the edemo board

Specified by:
getSwitches in interface IDemoBoard
Returns:
An ISwitch array of all built in switches

getLightSensor

public ILightSensor getLightSensor()
Method to return the built in light sensor object.

Specified by:
getLightSensor in interface IDemoBoard
Returns:
accessor object to built in light sensor

getAccelerometer

public IAccelerometer3D getAccelerometer()
Method to return the built in accelerometer.

Specified by:
getAccelerometer in interface IDemoBoard
Returns:
valid IAccelerometer3D accessor object

getIOPins

public IIOPin[] getIOPins()
Method to return an array of the built in bidirectional digital pins. Note this is only the bidirectional digital pins, D0-D4, that are built into the edemo board

Specified by:
getIOPins in interface IDemoBoard
Returns:
IIOPin array of all built in bidirectional digital pins

getOutputPins

public IOutputPin[] getOutputPins()
Method to return an array of the built in high current output pins. Note this is only the high current output pins, H0-H3, that are built into the edemo board

Specified by:
getOutputPins in interface IDemoBoard
Returns:
IOutputPin array of all built in high current output pins

getScalarInputs

public IScalarInput[] getScalarInputs()
Method to return an array of the built in analog input pins. Note this is only the analog input pins, A0-A5, that are built into the edemo board

Specified by:
getScalarInputs in interface IDemoBoard
Returns:
IScalarInput array of all built in analog input pins

setPWM

public void setPWM(IOutputPin pin,
                   int duty)
Request the controller maintain a pwm signal on a gpio pin. Set the duty to 0, to turn off an existing pwm signal. The control of this pulse generation is coarser then that available using the startPulse method. Note: that the pwm signal will stop during deep sleep and resume when deep sleep is over.

Parameters:
pin - output pin to send PWM signal to
duty - duty cycle out of 255 slices

startPulse

public void startPulse(IOutputPin pin,
                       boolean dir,
                       int usec)
Ask the controller to issue a pulse on the indicated pin. The pulse is accurate in terms of microseconds but the start time of the pulse may be affected by a bit of latency. Only one pulse may be active at a time. Minimum pulse length is about 25usec.

Parameters:
pin - output pin to issue pulse on
dir - direction of desired pulse: true = high, false = low
usec - length of pulse in microseconds [1:65535]

getPulse

public int getPulse(IInputPin pin,
                    boolean dir,
                    int timeout)
Ask the controller for a measurement of an incoming pulse on some input pin. The pulse width can range from 25usec to 65536usec. Pulses longer than 65536usec will be recorded as 65536usec. Timing will begin at the edge of the pulse in the indicated direction and timing will stop when the opposing edge is seen. If timing is not started in time for first edge, the next pulse will be the one measured. Only one pulse measurement may be active at one time. Calling getPulse() again while a previous call was still pending will terminate the old call and may introduce additional latency before checking for the initial edge begins.

Parameters:
pin - input pin to measure pulse on
dir - direction of desired pulse: true = high, false = low
timeout - how many milliseconds to wait for start of pulse (set to 0 for no timeout)
Returns:
length of measured pulse in microseconds or zero if no pulse seen before timeout

initUART

public void initUART(int baud,
                     boolean two_stopbit)
Initialize the UART module, set the speed and select the number of stop bits.

Parameters:
baud - baud speed to set module to, supported speeds are 2400, 4800, 9600, 19200, 28800, 38400 and 57600
two_stopbit - set to true if you want the module setup to send 2 stop bits

initUART

public void initUART(int baud,
                     int databits,
                     int parity,
                     int stopbits)
Initialize the UART module

Parameters:
baud - baud speed to set module to, supported speeds are 2400, 4800, 9600, 19200, 28800, 38400 and 57600
databits - supported values are 5,6,7,8
parity - supported options are none, odd, even
stopbits - supported options are 1 or 2

sendUART

public void sendUART(byte val)
Deprecated. 

Parameters:
val - the value to send over the uart
See Also:
writeUART(byte)

writeUART

public void writeUART(byte val)
Send a byte over the UART.

Parameters:
val - the value to send over the uart

writeUART

public void writeUART(String msg)
Send a string over the UART.

Parameters:
msg - the string message to send over the uart

writeUART

public void writeUART(byte[] msg)
Send a byte array over the UART.

Parameters:
msg - the byte array message to send over the uart

writeUART

public void writeUART(byte[] msg,
                      int off,
                      int len)
Writes len bytes from the specified byte array starting at offset off to the UART.

Parameters:
msg - the byte array message to send over the uart
off - the start offset in the data
len - the number of bytes to write

receiveUART

public byte receiveUART()
                 throws IOException
Deprecated. 

Returns:
the next currently available byte
Throws:
IOException - if any UART read or overrun errors
See Also:
readUART()

readUART

public byte readUART()
              throws IOException
Get the next byte from the UART. Blocks until input is available.

Returns:
the next currently available byte
Throws:
IOException - if any UART read or overrun errors

readUART

public int readUART(byte[] b,
                    int off,
                    int len)
             throws IOException
Read the next byte from the UART plus any more currently available bytes. Blocks until at least one byte of input is available.

Parameters:
b - byte array to store results
off - offset in byte array to store results
len - maximum bytes to read
Returns:
the number of bytes read
Throws:
IOException - if any UART read or overrun errors

readUART

public byte readUART(long timeout)
              throws IOException
Get the next byte from the UART. Blocks until input is available or timeout elapsed.

Parameters:
timeout - how many milliseconds to wait for input
Returns:
the next currently available byte or 0 if timeout
Throws:
IOException - if any UART read or overrun errors
TimeoutException - if timeout occurs

UARTAvailable

public int UARTAvailable()
                  throws IOException
Deprecated. 

Throws:
IOException
See Also:
availableUART()

availableUART

public int availableUART()
                  throws IOException
Check if there are any available characters read by the UART.

Note that there are two buffers: one located on the eDemo sensor board that is filled directly by the UART, and a second in Java on the ARM processor board that is filled from the sensor board's buffer. Both buffers can hold 64 bytes. availableUART() returns the number of bytes in the Java-side buffer, unless it is empty, in which case it is refilled from the sensor board.

Returns:
number of currently available characters in the UART buffer
Throws:
IOException - if any UART read or overrun errors

getInitialProperties

public static Properties getInitialProperties()
Get the correct set of properties for this board for its flash memory

Returns:
Properties object as intialized by part.

getProperties

public Properties getProperties()
Get the properties of this board.

Returns:
The properties which will be empty if unable to read them

setProperties

public void setProperties(Properties p)
                   throws IOException
Set the properties of this board

Parameters:
p - The properties to set.
Throws:
IOException

getFirmwareVersion

public int[] getFirmwareVersion()
Get the major and minor version information from the firmware running on the EDemoBoard. The array will have the major revision at position 0 and minor revision at position 1.

Returns:
major and minor version information

getI2C

public II2C getI2C()
Return the controller for the I2C.

Returns:
the controller for the I2C

setRegister

public void setRegister(int reg,
                        int val)
Poke method for the Atmega88 controller, allows user to set low level registers on the part. Note that this is a dangerous thing to do, you can in fact change something that is unrecoverable. You should only use these functions if you know what you are doing, and you should not use register values that are not defined in Atmega.java

Parameters:
reg - Register to set value of, use only those defined statically by Atmega[88].java
val - value to set

orRegister

public void orRegister(int reg,
                       int val)
Perform an OR assignment to one of the registers in the Atmega88 controller. This method will result in a '|=' of the value passed in with the current value in the register. Note that this is a dangerous thing to do, you can in fact change something that is unrecoverable. You should only use these functions if you know what you are doing, and you should not use register values that are not defined in Atmega.java

Parameters:
reg - register to set value of
val - value to use in operation

andRegister

public void andRegister(int reg,
                        int val)
Perform an AND assignment to one of the registers in the Atmega88 controller. This method will result in a '&=' of the value passed in with the current value in the register. Note that this is a dangerous thing to do, you can in fact change something that is unrecoverable. You should only use these functions if you know what you are doing, and you should not use register values that are not defined in Atmega.java

Parameters:
reg - register to set value of
val - value to use in operation

getRegister

public int getRegister(int reg)
Peek method for the atmega firmware. This method allows for reading values straight out of the low level control registers on the microcontroller. Use only the register values as defined statically in the Atmega.java and Atmega88.java files.

Parameters:
reg - Register to read value from
Returns:
current register value

SunSPOT API V5.0


Copyright � 2006-2008 Sun Microsystems, Inc. All Rights Reserved.