SunSPOT API V5.0


com.sun.spot.sensorboard
Class EDemoController

java.lang.Object
  extended by com.sun.spot.peripheral.external.ExternalBoard
      extended by com.sun.spot.sensorboard.hardware.AtmegaExternalBoard
          extended by com.sun.spot.sensorboard.EDemoController
All Implemented Interfaces:
IExternalBoard, IDriver, IADCController, IGPIOController, ILightSensorController, IServoController, ISwitchController, IToneGeneratorController, ITriColorLEDController, Isolate.LifecycleListener

public class EDemoController
extends AtmegaExternalBoard
implements IDriver, IADCController, ISwitchController, ITriColorLEDController, IServoController, IGPIOController, ILightSensorController, IToneGeneratorController, Isolate.LifecycleListener

This class manages the SPI interfaces and communications to the reachable parts on the EDemoBoard, namely the Atmega88, the Analog to Digital Converter, and the flash eeprom. ( some of this is done by superclasses ) Controller interfaces use a model of interaction that allows for behaviours of the controlled functionality to be modified by implementing the accessor interfaces. The end user is meant to request on of these accessor objects and then use their methods to interact with the Controller. The implementor of the Controller should also be responsible for implementing the accessor object as these concrete classes are assumed to be tightly bound. At the same time it is possible to call the methods that actually implement the low level behaviour in the controller, this is generally disuaded, however there are circumstances where the user may want to bypass the sanity checking in order to reduce the latency as much as possible. Note: whenever a servo is active, deep sleep will not happen.

Author:
arshan, Ron Goldman

Field Summary
static PinDescriptor A0
          Analog to Digital convertor input pin, matches silkscreening on the hardware
static PinDescriptor A1
          Analog to Digital convertor input pin, matches silkscreening on the hardware
static PinDescriptor A2
          Analog to Digital convertor input pin, matches silkscreening on the hardware
static PinDescriptor A3
          Analog to Digital convertor input pin, matches silkscreening on the hardware
static PinDescriptor A4
          Analog-to-Digital convertor input pin, matches silkscreening on the hardware
static PinDescriptor A5
          Analog-to-Digital convertor input pin, matches silkscreening on the hardware
static PinDescriptor ACCEL_FULLSCALE
          Internal pin used to operate the accelerometer.
static PinDescriptor ACCEL_SELFTEST
          Internal pin used to operate the accelerometer.
static PinDescriptor ACCEL_X
          Descriptor for X Axis accelerometer reading, this is an internal connection.
static PinDescriptor ACCEL_Y
          Descriptor for Y Axis accelerometer reading, this is an internal connection.
static PinDescriptor ACCEL_Z
          Descriptor for Z Axis accelerometer reading, this is an internal connection.
static PinDescriptor D0
          TTL level general purpose input/output pin, matches silkscreening on the hardware
static PinDescriptor D1
          TTL level general purpose input/output pin, matches silkscreening on the hardware
static PinDescriptor D2
          TTL level general purpose input/output pin, matches silkscreening on the hardware
static PinDescriptor D3
          TTL level general purpose input/output pin, matches silkscreening on the hardware
static PinDescriptor D4
          TTL level general purpose input/output pin, matches silkscreening on the hardware
static PinDescriptor H0
          High current output pin, matches silkscreening on the hardware
static PinDescriptor H1
          High current output pin, matches silkscreening on the hardware
static PinDescriptor H2
          High current output pin, matches silkscreening on the hardware
static PinDescriptor H3
          High current output pin, matches silkscreening on the hardware
static PinDescriptor LED1
          Tri-color LED Identifier, matches silkscreening on the hardware
static PinDescriptor LED2
          Tri-color LED Identifier, matches silkscreening on the hardware
static PinDescriptor LED3
          Tri-color LED Identifier, matches silkscreening on the hardware
static PinDescriptor LED4
          Tri-color LED Identifier, matches silkscreening on the hardware
static PinDescriptor LED5
          Tri-color LED Identifier, matches silkscreening on the hardware
static PinDescriptor LED6
          Tri-color LED Identifier, matches silkscreening on the hardware
static PinDescriptor LED7
          Tri-color LED Identifier, matches silkscreening on the hardware
static PinDescriptor LED8
          Tri-color LED Identifier, matches silkscreening on the hardware
static PinDescriptor LIGHTSENSOR
          Descriptor for LightSensor, this is an internal connection.
static PinDescriptor POWER_ENABLE
          Internal pin used to enable the op-amp and shift registers that drive the LEDs.
static PinDescriptor SW1
          Switch 0, matches silkscreening on the hardware.
static PinDescriptor SW2
          Switch 1, matches silkscreening on the hardware.
static PinDescriptor TEMPERATURE
          Descriptor for internal thermometer reading, this is internal to the ADC chip---a virtual pin.
static byte TWISTATUS_ERROR
           
static byte TWISTATUS_OFF
           
static byte TWISTATUS_OK
           
static byte TWISTATUS_TIMEOUT
           
 
Fields inherited from class com.sun.spot.sensorboard.hardware.AtmegaExternalBoard
atmega
 
Fields inherited from class com.sun.spot.peripheral.external.ExternalBoard
BOARD_MAGIC_WORD, ID_PROPERTY_NAME, MEMORY_PROPERTY_NAME
 
Method Summary
 void accelerometerScaleChanged(int newScale)
          Called by accelerometer when it changes its scale.
 void andRegister(int reg, int val)
          Perform an AND assignment to one of the registers in the Atmega88 controller.
 boolean areThresholdEventsEnabled(IScalarInput pin)
          Return whether threshold events are enabled or disabled.
 int availableUART()
          Check if there are any available characters read by the UART.
 void disablePinChangeInterrupts(IInputPin pin)
          Stop a pin generating pin change interrupts.
 void enablePinChangeInterrupts(IInputPin pin)
          Allow the input pin specified to generate pin change interrupts.
 void enableThresholdEvents(IScalarInput pin, boolean enable)
          Enable or disable threshold events.
static void error(String txt)
          Report an error with regard to the EDemoBoard.
 IAccelerometer3D getAccelerometer()
          Convenience method to return the built in accelerometer.
 IADT7411 getADC()
          Convenience function to get an object that corresponds to the ADC on the EDemoBoard.
 ITemperatureInput getADCTemperature()
          Get the internal temperature sensor on the ADC on the EDemoBoard.
 int getBlueLEDValue(PinDescriptor pidx)
          Get the current blue color value for the indicated LED This method is meant to be used by an accessor object to the ITriColorLEDController.
 String getDriverName()
          Returns the name that should be used by the IDriver subsystem.
 int[] getFirmwareVersion()
          Get the major and minor version information from the firmware running on the EDemoBoard.
 int getGreenLEDValue(PinDescriptor pidx)
          Get the current green color value for the indicated LED This method is meant to be used by an accessor object to the ITriColorLEDController.
 int getHighThreshold(IScalarInput pin)
          Return the current high threshold value.
 IIOPin[] getIOPins()
          Method to return an array of the builtin bidirectional digital pins.
 ITriColorLED[] getLEDs()
          Convienence method that returns an array of all the built in LEDs.
 ILightSensor getLightSensor()
          Return light sensor object.
 int getLightSensorValue(PinDescriptor pidx)
          Get the current value of a lightsensor accessor connected to a particular pin.
 int getLowThreshold(IScalarInput pin)
          Return the current low threshold value.
 IOutputPin[] getOutputPins()
          Method to return an array of the builtin high current output pins.
 boolean getPinDirection(PinDescriptor pidx)
          Get the current direction for the specified input/output pin.
 boolean getPinValue(PinDescriptor pidx)
          Returns the value of the pin.
 int getPulse(PinDescriptor pidx, boolean dir, int timeout)
          Ask the controller for a measurement of an incoming pulse on some input pin.
 int getRedLEDValue(PinDescriptor pidx)
          Get the current red color value for the indicated LED This method is meant to be used by an accessor object to the ITriColorLEDController.
 int getRegister(int reg)
          Peek method for the atmega firmware.
 IScalarInput[] getScalarInputs()
          Method to return an array of the builtin analog input pins.
 int getScalarValue(PinDescriptor pidx)
          Returns a scalar value for indicated pin from the ADC.
 ISwitch[] getSwitches()
          Return an array of all the built in switches on the board.
 boolean getSwitchState(PinDescriptor pidx)
          Get the current state of a switch connected to the indicated pin.
 byte getTWIstatus()
          Return status of whether the last TWI transaction completed ok or not.
 void handleLifecycleListenerEvent(Isolate iso, int eventKind)
          This method will be called when the lifecycle event occurs on the isolate that this listener was registered for using addLifecycleListener.
 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 on the Atmega note that all valid parameters are defined in EDemoBoard class SERIAL_SPEED_* SERIAL_DATABITS_* SERIAL_PARITY_* SERIAL_STOPBITS_*
 boolean isOnLED(PinDescriptor pidx)
          Return if the LED is on or off.
 boolean isTWIBusy()
          Test if TWI interrupt has been cleared.
static void main(String[] args)
          Called by Spot class when master isolate is started up.
static void msg(String txt)
          Deliver message to user.
 void orRegister(int reg, int val)
          Perform an OR assignment to one of the registers in the Atmega88 controller.
 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.
 boolean receiveTWI(int sla, byte[] rcv, int offset, int rcvlen)
          Receive bytes into rcv for rcvlen bytes from TWI at slave address sla.
 boolean sendTWI(int sla, byte[] snd, int offset, int sndlen)
          Send bytes in snd for sndlen bytes to TWI to slave address sla blocks and returns after transaction.
protected  void setDebugLevel(int x)
          Change the verbosity of the EDemoBoard.
 void setLEDValue(PinDescriptor pidx, int r, int g, int b)
          Set the RGB values of the indicated LED.
 void setOnLED(PinDescriptor pidx, boolean on)
          Turn the LED on or off
 void setPinDirection(PinDescriptor pidx, boolean output)
          Set the mask for the indicated pin to the indicated direction.
 void setPinValue(PinDescriptor pidx, boolean high)
          Set the output value of the indicated pin.
 void setPWM(PinDescriptor pidx, 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 setServoPulseWidth(PinDescriptor pidx, int usec)
          Ask the controller to maintain a servo pulsewidth of some length.
 void setThresholdValues(IScalarInput ipin, int low, int high)
          Set the low and high threshold values for this scalar input.
 void setTone(PinDescriptor pidx, int period)
          Ask the controller to start a tone on the indicated pin.
 void setUp()
          Perform any tasks necessary for initial setup, and return from hibernation.
 void setupTWI(byte command, byte data)
          Send a command to the TWI controller.
 void shutDown()
          Notify the driver that the VM is about to exit.
 void startPulse(PinDescriptor pidx, boolean dir, int usec)
          Ask the controller to issue a pulse on the indicated pin.
 boolean supportsThresholdEvents(PinDescriptor pidx)
          Returns whether the underlying hardware supports threshold events.
 boolean tearDown()
          Record interrupt state so it can be restored later.
 boolean transceiveTWI(int sla, byte[] snd, int sndlen, byte[] rcv, int offset, int rcvlen)
          Send bytes in snd for sndlen bytes to TWI to slave address sla, restart and receive rcvlen bytes in rcv byte array.
static void warning(String txt)
          Report a warning with regard to the EDemoBoard.
 void writeUART(byte val)
          Send a byte 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 com.sun.spot.sensorboard.hardware.AtmegaExternalBoard
getAtmega, getAtmegaSPI, getProgrammingSPI, setAtmega
 
Methods inherited from class com.sun.spot.peripheral.external.ExternalBoard
forceChipSelectPin, getBoardIndex, getProperties, getSerialFlash, hardwareNotValid, isInstalled, newBoardDeviceSPI, setProperties
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LED1

public static final PinDescriptor LED1
Tri-color LED Identifier, matches silkscreening on the hardware


LED2

public static final PinDescriptor LED2
Tri-color LED Identifier, matches silkscreening on the hardware


LED3

public static final PinDescriptor LED3
Tri-color LED Identifier, matches silkscreening on the hardware


LED4

public static final PinDescriptor LED4
Tri-color LED Identifier, matches silkscreening on the hardware


LED5

public static final PinDescriptor LED5
Tri-color LED Identifier, matches silkscreening on the hardware


LED6

public static final PinDescriptor LED6
Tri-color LED Identifier, matches silkscreening on the hardware


LED7

public static final PinDescriptor LED7
Tri-color LED Identifier, matches silkscreening on the hardware


LED8

public static final PinDescriptor LED8
Tri-color LED Identifier, matches silkscreening on the hardware


A0

public static final PinDescriptor A0
Analog to Digital convertor input pin, matches silkscreening on the hardware


A1

public static final PinDescriptor A1
Analog to Digital convertor input pin, matches silkscreening on the hardware


A2

public static final PinDescriptor A2
Analog to Digital convertor input pin, matches silkscreening on the hardware


A3

public static final PinDescriptor A3
Analog to Digital convertor input pin, matches silkscreening on the hardware


LIGHTSENSOR

public static final PinDescriptor LIGHTSENSOR
Descriptor for LightSensor, this is an internal connection. There is no matching silkscreened value.


ACCEL_X

public static final PinDescriptor ACCEL_X
Descriptor for X Axis accelerometer reading, this is an internal connection. There is no matching silkscreened value.


ACCEL_Y

public static final PinDescriptor ACCEL_Y
Descriptor for Y Axis accelerometer reading, this is an internal connection. There is no matching silkscreened value.


ACCEL_Z

public static final PinDescriptor ACCEL_Z
Descriptor for Z Axis accelerometer reading, this is an internal connection. There is no matching silkscreened value.


TEMPERATURE

public static final PinDescriptor TEMPERATURE
Descriptor for internal thermometer reading, this is internal to the ADC chip---a virtual pin.


H0

public static final PinDescriptor H0
High current output pin, matches silkscreening on the hardware


H1

public static final PinDescriptor H1
High current output pin, matches silkscreening on the hardware


H2

public static final PinDescriptor H2
High current output pin, matches silkscreening on the hardware


H3

public static final PinDescriptor H3
High current output pin, matches silkscreening on the hardware


D0

public static final PinDescriptor D0
TTL level general purpose input/output pin, matches silkscreening on the hardware


D1

public static final PinDescriptor D1
TTL level general purpose input/output pin, matches silkscreening on the hardware


D2

public static final PinDescriptor D2
TTL level general purpose input/output pin, matches silkscreening on the hardware


D3

public static final PinDescriptor D3
TTL level general purpose input/output pin, matches silkscreening on the hardware


D4

public static final PinDescriptor D4
TTL level general purpose input/output pin, matches silkscreening on the hardware


SW1

public static final PinDescriptor SW1
Switch 0, matches silkscreening on the hardware. This switch can also be driven by an external switch by using the SW1 pin on the header.


SW2

public static final PinDescriptor SW2
Switch 1, matches silkscreening on the hardware. This switch can also be driven by an external switch by using the SW2 pin on the header.


A4

public static final PinDescriptor A4
Analog-to-Digital convertor input pin, matches silkscreening on the hardware


A5

public static final PinDescriptor A5
Analog-to-Digital convertor input pin, matches silkscreening on the hardware


ACCEL_SELFTEST

public static final PinDescriptor ACCEL_SELFTEST
Internal pin used to operate the accelerometer. There is no matching mark on the hardware.


ACCEL_FULLSCALE

public static final PinDescriptor ACCEL_FULLSCALE
Internal pin used to operate the accelerometer. There is no matching mark on the hardware.


POWER_ENABLE

public static final PinDescriptor POWER_ENABLE
Internal pin used to enable the op-amp and shift registers that drive the LEDs. Clears the shift registers, hi -> on There is no matching mark on the hardware.


TWISTATUS_OK

public static final byte TWISTATUS_OK
See Also:
Constant Field Values

TWISTATUS_ERROR

public static final byte TWISTATUS_ERROR
See Also:
Constant Field Values

TWISTATUS_TIMEOUT

public static final byte TWISTATUS_TIMEOUT
See Also:
Constant Field Values

TWISTATUS_OFF

public static final byte TWISTATUS_OFF
See Also:
Constant Field Values
Method Detail

main

public static void main(String[] args)
Called by Spot class when master isolate is started up. Lets us setup the master EDemoBoard threads to process interrupts & deal with proxies in child isolates. Be careful not to throw any errors if there is no EDemoBoard present.

Parameters:
args - ignored

enablePinChangeInterrupts

public void enablePinChangeInterrupts(IInputPin pin)
Allow the input pin specified to generate pin change interrupts. An interrupt can be generated on a low-to-high transition, a high-to-low transition, or both. After enabling the interrupt use:
 synchronized(pin.getIndex()) { pin.getIndex().wait(); } 
to wait for it. Enabling a pin change interrupt does not inhibit deep sleep. Note: only the master isolate actually interacts with the hardware. Any child isolates send a request to enable interrupts to the master isolate. Upon an interrupt the master isolate will send a message to the child isolate.

Specified by:
enablePinChangeInterrupts in interface IGPIOController
Parameters:
pin - the input pin

disablePinChangeInterrupts

public void disablePinChangeInterrupts(IInputPin pin)
Stop a pin generating pin change interrupts.

Specified by:
disablePinChangeInterrupts in interface IGPIOController
Parameters:
pin - the input pin

handleLifecycleListenerEvent

public void handleLifecycleListenerEvent(Isolate iso,
                                         int eventKind)
Description copied from interface: Isolate.LifecycleListener
This method will be called when the lifecycle event occurs on the isolate that this listener was registered for using addLifecycleListener.

Specified by:
handleLifecycleListenerEvent in interface Isolate.LifecycleListener
Parameters:
iso - the isolate that had the lifecycle event
eventKind - the lifecycle event that occurred. One of Isolate.SHUTDOWN_EVENT_MASK, Isolate.HIBERNATE_EVENT_MASK, or Isolate.UNHIBERNATE_EVENT_MASK
See Also:
Isolate.addLifecycleListener(com.sun.squawk.Isolate.LifecycleListener, int), Isolate.exit(int), Isolate.hibernate(), Isolate.unhibernate()

getDriverName

public String getDriverName()
Returns the name that should be used by the IDriver subsystem.

Specified by:
getDriverName in interface IDriver
Returns:
a human readable string identifying the EDemoBoard

tearDown

public boolean tearDown()
Record interrupt state so it can be restored later.

Specified by:
tearDown in interface IDriver
Returns:
true if successful, false if any servos are currently active

shutDown

public void shutDown()
Notify the driver that the VM is about to exit.

Specified by:
shutDown in interface IDriver

setUp

public void setUp()
Perform any tasks necessary for initial setup, and return from hibernation.

Specified by:
setUp in interface IDriver

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

getADC

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

Returns:
a-to-d converter

getADCTemperature

public ITemperatureInput getADCTemperature()
Get the internal temperature sensor on the ADC on the EDemoBoard.

Returns:
accessor object for ADC internal temperature sensor

getScalarInputs

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

Returns:
IScalarInput array of all built in analog input pins

getScalarValue

public int getScalarValue(PinDescriptor pidx)
Returns a scalar value for indicated pin from the ADC. This method is meant to be used by accessor objects of the IADCController interface. This method results directly in a read from the ADC part on the EDemoboard. This method can be used directly, however this will bypass the sanity checking done by the EDemoBoard class.

Specified by:
getScalarValue in interface IADCController
Parameters:
pidx - pin to probe
Returns:
current value from ADC registers

supportsThresholdEvents

public boolean supportsThresholdEvents(PinDescriptor pidx)
Returns whether the underlying hardware supports threshold events.

Specified by:
supportsThresholdEvents in interface IADCController
Returns:
true if threshold events are supported

setThresholdValues

public void setThresholdValues(IScalarInput ipin,
                               int low,
                               int high)
Set the low and high threshold values for this scalar input. Callbacks occur when the scalar input reading falls below or equal to the low threshold value, or when it rises above or equal to the high threshold value.

Specified by:
setThresholdValues in interface IADCController
Parameters:
ipin - pin to be read
low - the new low threshold value.
high - the new high threshold value.

getLowThreshold

public int getLowThreshold(IScalarInput pin)
Return the current low threshold value.

Specified by:
getLowThreshold in interface IADCController
Parameters:
pin - pin to be read
Returns:
the current low threshold value.

getHighThreshold

public int getHighThreshold(IScalarInput pin)
Return the current high threshold value.

Specified by:
getHighThreshold in interface IADCController
Parameters:
pin - pin to be read
Returns:
the current high threshold value.

enableThresholdEvents

public void enableThresholdEvents(IScalarInput pin,
                                  boolean enable)
Enable or disable threshold events.

Specified by:
enableThresholdEvents in interface IADCController
Parameters:
pin - the pin to be read
enable - if true then listeners will be notified if the scalar input reading goes above the high threshold or below the low threshold.

areThresholdEventsEnabled

public boolean areThresholdEventsEnabled(IScalarInput pin)
Return whether threshold events are enabled or disabled.

Specified by:
areThresholdEventsEnabled in interface IADCController
Parameters:
pin - pin to be read
Returns:
true if events are enabled

getLightSensor

public ILightSensor getLightSensor()
Return light sensor object.

Returns:
accessor object to built in light sensor

getLightSensorValue

public int getLightSensorValue(PinDescriptor pidx)
Get the current value of a lightsensor accessor connected to a particular pin. This method is meant to be used by accessor objects to the ILightSensorController interface. It bypasses the sanity checks that are assumed to be done by the accessors and results directly in traffic on the SPI bus.

Specified by:
getLightSensorValue in interface ILightSensorController
Parameters:
pidx - pin that the sensor is attached to
Returns:
current value for sensor as reported by ADC

getLEDs

public ITriColorLED[] getLEDs()
Convienence method that returns an array of all the built in LEDs.

Returns:
ITriColorLED array that can control all built in LEDs

setOnLED

public void setOnLED(PinDescriptor pidx,
                     boolean on)
Turn the LED on or off

Specified by:
setOnLED in interface ITriColorLEDController
Parameters:
pidx - desired LED descriptor
on - turn LED on if true

isOnLED

public boolean isOnLED(PinDescriptor pidx)
Return if the LED is on or off.

Specified by:
isOnLED in interface ITriColorLEDController
Parameters:
pidx - desired LED descriptor
Returns:
true if the LED is currently on

setLEDValue

public void setLEDValue(PinDescriptor pidx,
                        int r,
                        int g,
                        int b)
Set the RGB values of the indicated LED. This method is meant to be used by an accessor object to the ITriColorLEDController. This method bypasses sanity checks and results directly in traffic on the SPI bus to the Atmega microcontroller.

Specified by:
setLEDValue in interface ITriColorLEDController
Parameters:
pidx - Tri Color LED pin
r - value of red segment
g - value of green segment
b - value of blue segment

getRedLEDValue

public int getRedLEDValue(PinDescriptor pidx)
Get the current red color value for the indicated LED This method is meant to be used by an accessor object to the ITriColorLEDController. This method bypasses sanity checks.

Specified by:
getRedLEDValue in interface ITriColorLEDController
Parameters:
pidx - desired LED descriptor
Returns:
current red intensity of the LED

getGreenLEDValue

public int getGreenLEDValue(PinDescriptor pidx)
Get the current green color value for the indicated LED This method is meant to be used by an accessor object to the ITriColorLEDController. This method bypasses sanity checks.

Specified by:
getGreenLEDValue in interface ITriColorLEDController
Parameters:
pidx - desired LED descriptor
Returns:
current green intensity of the LED

getBlueLEDValue

public int getBlueLEDValue(PinDescriptor pidx)
Get the current blue color value for the indicated LED This method is meant to be used by an accessor object to the ITriColorLEDController. This method bypasses sanity checks.

Specified by:
getBlueLEDValue in interface ITriColorLEDController
Parameters:
pidx - desired LED descriptor
Returns:
current blue intensity of the LED

getSwitches

public ISwitch[] getSwitches()
Return an array of all the built in switches on the board.

Returns:
An ISwitch array of all built in switches

getSwitchState

public boolean getSwitchState(PinDescriptor pidx)
Get the current state of a switch connected to the indicated pin. This method is meant to be used by classes implementing ISwitch to correspond to their SwitchControllers. This method results in an SPI transaction with the microcontroller on the DemoBoard, and can be called directly if you wish to bypass any state caching done for you, but be careful.

Specified by:
getSwitchState in interface ISwitchController
Parameters:
pidx - pin that switch is connected to
Returns:
value representing the current state of switch

getIOPins

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

Returns:
IIOPin array of all built in bidirectional digital pins

getOutputPins

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

Returns:
IOutputPin array of all built in high current output pins

setPinValue

public void setPinValue(PinDescriptor pidx,
                        boolean high)
Set the output value of the indicated pin. This method is meant to be used by accessor objects to the IGPIOController, and bypasses the sanity checks that are assumed to be done by those accessors.

Specified by:
setPinValue in interface IGPIOController
Parameters:
pidx - pin to set the value of
high - value to set the pin to, true sets pin to Vdd

getPinValue

public boolean getPinValue(PinDescriptor pidx)
Returns the value of the pin. This method is meant to be used by accessor objects to the IGPIOController, and bypasses the sanity checks that are assumed to be done by those accessors.

Specified by:
getPinValue in interface IGPIOController
Parameters:
pidx - pin to get the value of
Returns:
current binary value of the pin

setPinDirection

public void setPinDirection(PinDescriptor pidx,
                            boolean output)
                     throws IOPinException
Set the mask for the indicated pin to the indicated direction. This method is meant to be used by accessor objects to the IGPIOController, and bypasses the sanity checks that are assumed to be done by those accessors.

Specified by:
setPinDirection in interface IGPIOController
Parameters:
pidx - pin to be modified
output - true if user wants the pin to be an output
Throws:
IOPinException - attempt to set pin to illegal direction

getPinDirection

public boolean getPinDirection(PinDescriptor pidx)
Get the current direction for the specified input/output pin. This method is meant to be used by accessor objects to the IGPIOController, and bypasses the sanity checks that are assumed to be done by those accessors.

Specified by:
getPinDirection in interface IGPIOController
Parameters:
pidx - pin to be modified
Returns:
true if pin is currently an output pin

startPulse

public void startPulse(PinDescriptor pidx,
                       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:
pidx - pin to issure pulse on
dir - direction of desired pulse, true = high, false = low
usec - length of pulse in microseconds [1:65535]

getPulse

public int getPulse(PinDescriptor pidx,
                    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:
pidx - 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

getAccelerometer

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

Returns:
valid Accelerometer3D accessor object

accelerometerScaleChanged

public void accelerometerScaleChanged(int newScale)
Called by accelerometer when it changes its scale. Should not be called by user code.

Parameters:
newScale - the new scale

setServoPulseWidth

public void setServoPulseWidth(PinDescriptor pidx,
                               int usec)
Ask the controller to maintain a servo pulsewidth of some length. The controller will assure that the pulses are generated regularly enough to maintain stable control of a servo. This method is meant to be used by servo accessor objects, using this directly will bypass the sanity checks that are done by the servo object.

Specified by:
setServoPulseWidth in interface IServoController
Parameters:
pidx - pin that the servo is connected to
usec - length of servo pulse in micro seconds

setPWM

public void setPWM(PinDescriptor pidx,
                   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:
pidx - pin to intiate PWM on
duty - duty cycle out of 255 slices

setTone

public void setTone(PinDescriptor pidx,
                    int period)
Ask the controller to start a tone on the indicated pin. Generate a tone on pin idx, note that this is significantly different from just the PWM. This is somewhat taxing on the atmega processor. This method is intended to be used by ToneGenerator accessor objects, using it directly will bypass the sanity checking that is assumed by those objects.

Specified by:
setTone in interface IToneGeneratorController
Parameters:
pidx - pin to generate tone on
period - period of the tone generated, this is modified by internal divisors.

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

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 on the Atmega note that all valid parameters are defined in EDemoBoard class SERIAL_SPEED_* SERIAL_DATABITS_* SERIAL_PARITY_* SERIAL_STOPBITS_*

Parameters:
baud - requested baud rate
databits - requested databits
parity - requested parity
stopbits - number of stopbits

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,
                      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

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

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 has elapsed.

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

isTWIBusy

public boolean isTWIBusy()
Test if TWI interrupt has been cleared. When TWI interrupt is no longer set, the TWI has sent a stop and has completed its transaction.

Returns:
true if busy, false if ready

getTWIstatus

public byte getTWIstatus()
Return status of whether the last TWI transaction completed ok or not. Called after a TWI transaction. State remains until next TWI transaction.

Returns:
TWI status bit field TWISTATUS_OK and TWISTATUS_ERROR

setupTWI

public void setupTWI(byte command,
                     byte data)
Send a command to the TWI controller.

Parameters:
command - the operation to perform: init, close or set clock speed
data - the bitrate for the clock speed

transceiveTWI

public boolean transceiveTWI(int sla,
                             byte[] snd,
                             int sndlen,
                             byte[] rcv,
                             int offset,
                             int rcvlen)
Send bytes in snd for sndlen bytes to TWI to slave address sla, restart and receive rcvlen bytes in rcv byte array. Blocks and returns after transaction.

Parameters:
sla - slave address
snd - byte array of data to send over TWI
sndlen - number of bytes to send over TWI
rcv - byte array of data to receive from TWI
offset - Offset to where to start storing data
rcvlen - number of bytes to receive into array rcv
Returns:
true if success, false if error

sendTWI

public boolean sendTWI(int sla,
                       byte[] snd,
                       int offset,
                       int sndlen)
Send bytes in snd for sndlen bytes to TWI to slave address sla blocks and returns after transaction.

Parameters:
sla - slave address
snd - byte array of data to send over TWI
offset - Offset from which to start reading data
sndlen - number of bytes to send over TWI
Returns:
true if success, false if error

receiveTWI

public boolean receiveTWI(int sla,
                          byte[] rcv,
                          int offset,
                          int rcvlen)
Receive bytes into rcv for rcvlen bytes from TWI at slave address sla. Blocks and returns after transaction.

Parameters:
sla - slave address
rcv - byte array of data to receive over TWI
offset - Offset to where to start storing data
rcvlen - number of bytes to receive over TWI
Returns:
true if success, false if error
Throws:
IO - exception if no slave device responds

setDebugLevel

protected void setDebugLevel(int x)
Change the verbosity of the EDemoBoard. Range is from 0 to 100. Default is 5

Parameters:
x - desired verbosity setting

error

public static void error(String txt)
Report an error with regard to the EDemoBoard.

Parameters:
txt - text of error message

warning

public static void warning(String txt)
Report a warning with regard to the EDemoBoard.

Parameters:
txt - Text content of warning message.

msg

public static void msg(String txt)
Deliver message to user. This is the place re-route all warning/errors

Parameters:
txt - Text content of message.

SunSPOT API V5.0


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