orbotix.robot.base
Class RobotProvider

java.lang.Object
  extended by orbotix.robot.base.RobotProvider
All Implemented Interfaces:
java.util.Observer

public class RobotProvider
extends java.lang.Object
implements java.util.Observer

Class to maintain the available and connected robot devices. Uses the BluetoothAdapter to discover and get Orbotix devices.


Field Summary
static java.lang.String ACTION_ROBOT_CONNECT_FAILED
          Action for broadcasting when a connection failed or disconnected.
static java.lang.String ACTION_ROBOT_CONNECT_SUCCESS
          Action for broadcasting when a connection to an Orbotix device is successful.
static java.lang.String ACTION_ROBOT_CONNECTING
          Action for broadcasting when the provider has started an attempt to connect to a Orbotix device
static java.lang.String ACTION_ROBOT_DISCONNECTED
          Broadcast message action for when the robot disconnects
static java.lang.String ACTION_ROBOT_FOUND
          Action for broadcasting when a Orbotix device is found.
static java.lang.String ACTION_ROBOT_MAIN_APP_CORRUPT
          Broadcast message when a corrupt main application is reported.
static java.lang.String ACTION_ROBOT_MULTIPLE_FOUND
          Action for broadcasting when multiple Orbotix devices were found in during discovery
static java.lang.String ACTION_ROBOT_NONE_FOUND
          Action for broadcasting when Orbotix devices weren't found during discovery
static java.lang.String ACTION_ROBOT_NONE_PAIRED
          Action for broadcasting when no Orbotix devices have been paired with the device
static java.lang.String EXTRA_ROBOT_ID
          Key for a Robot id to send a robot to which you want to immediately connect.
 
Method Summary
 java.lang.Boolean connectControlledRobots()
          Attempts to connect to any Robots who have been set up to be controlled.
 void control(Robot robot)
          Adds the robot to the controlled robot array.
 void disconnectControlledRobots()
          Disconnects all robots that are under control without removing them from control.
 void endDiscovery()
          Stops discovery for bluetooth Orbotix devices.
 Robot findRobot(java.lang.String robotId)
          Finds a robot in the robot list by it's bluetooth address.
 void findRobots()
           
 android.content.Intent getAdapterIntent()
          Provides an Intent object that can be used to start an activity to enable the adapter.
 android.content.Context getBroadcastContext()
          Accessor to the broadcast context used for action messages.
 java.util.ArrayList getControlledRobots()
          Gets an array of Robot objects that are being controlled.
static RobotProvider getDefaultProvider()
          Get a handle on the default provider object.
 RobotControl getRobotControl(Robot robot)
          Gets the RobotControl object for a Robot object.
 java.util.ArrayList getRobotControls()
          Accessor to the RobotControl objects.
 java.util.ArrayList getRobots()
          Accessor to available robots.
 boolean hasAdapter()
          This allows a check for a communication adapter that can be used to connect to a robot.
 boolean hasRobotControl()
          Method for testing that there is at least one robot to control.
 void initiateConnection(java.lang.String robotId)
          Method to initiate a connection.
 boolean isAdapterEnabled()
          Checks to see if the communication adapter is turned on.
 void removeAllControls()
          Removes all robots under control.
 void removeControl(Robot robot)
          Release the robot from control.
 void removeControl(RobotControl control)
          Removes a Robot control the controlled robot array.
 void setBroadcastContext(android.content.Context context)
          Method to set a context to broadcast action messages with.
 void startDiscovery()
          Starts discovery for bluetooth Orbotix devices.
 void update(java.util.Observable observable, java.lang.Object data)
          DO NOT USE.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_ROBOT_FOUND

public static final java.lang.String ACTION_ROBOT_FOUND
Action for broadcasting when a Orbotix device is found.

See Also:
Constant Field Values

ACTION_ROBOT_MULTIPLE_FOUND

public static final java.lang.String ACTION_ROBOT_MULTIPLE_FOUND
Action for broadcasting when multiple Orbotix devices were found in during discovery

See Also:
Constant Field Values

ACTION_ROBOT_NONE_FOUND

public static final java.lang.String ACTION_ROBOT_NONE_FOUND
Action for broadcasting when Orbotix devices weren't found during discovery

See Also:
Constant Field Values

ACTION_ROBOT_NONE_PAIRED

public static final java.lang.String ACTION_ROBOT_NONE_PAIRED
Action for broadcasting when no Orbotix devices have been paired with the device

See Also:
Constant Field Values

ACTION_ROBOT_CONNECTING

public static final java.lang.String ACTION_ROBOT_CONNECTING
Action for broadcasting when the provider has started an attempt to connect to a Orbotix device

See Also:
Constant Field Values

ACTION_ROBOT_CONNECT_SUCCESS

public static final java.lang.String ACTION_ROBOT_CONNECT_SUCCESS
Action for broadcasting when a connection to an Orbotix device is successful.

See Also:
Constant Field Values

ACTION_ROBOT_CONNECT_FAILED

public static final java.lang.String ACTION_ROBOT_CONNECT_FAILED
Action for broadcasting when a connection failed or disconnected.

See Also:
Constant Field Values

ACTION_ROBOT_DISCONNECTED

public static final java.lang.String ACTION_ROBOT_DISCONNECTED
Broadcast message action for when the robot disconnects

See Also:
Constant Field Values

ACTION_ROBOT_MAIN_APP_CORRUPT

public static final java.lang.String ACTION_ROBOT_MAIN_APP_CORRUPT
Broadcast message when a corrupt main application is reported.

See Also:
Constant Field Values

EXTRA_ROBOT_ID

public static final java.lang.String EXTRA_ROBOT_ID
Key for a Robot id to send a robot to which you want to immediately connect.

See Also:
Constant Field Values
Method Detail

getDefaultProvider

public static RobotProvider getDefaultProvider()
Get a handle on the default provider object.

Returns:
RobotProvider A singleton instance of the RobotProvider.

initiateConnection

public void initiateConnection(java.lang.String robotId)
Method to initiate a connection. This will start the discovery process, and attempt a connection to a lone Orbotix device or to the preferred Orbotix device when multiple devices are present.

Parameters:
robotId - The unique id of the preferred Orbotix device when multiple devices are present.

hasAdapter

public boolean hasAdapter()
This allows a check for a communication adapter that can be used to connect to a robot.

Returns:
true if a communication adapter exists, otherwise false if no suitable adapter exists on the phone.

isAdapterEnabled

public boolean isAdapterEnabled()
Checks to see if the communication adapter is turned on.

Returns:
true if the adapter is enabled, otherwise, false.

getAdapterIntent

public android.content.Intent getAdapterIntent()
Provides an Intent object that can be used to start an activity to enable the adapter.

Returns:
The Intent object.

setBroadcastContext

public void setBroadcastContext(android.content.Context context)
Method to set a context to broadcast action messages with.

Parameters:
context - The context to broadcast action messages.

getBroadcastContext

public android.content.Context getBroadcastContext()
Accessor to the broadcast context used for action messages.

Returns:
A Context object.

startDiscovery

public void startDiscovery()
Starts discovery for bluetooth Orbotix devices. Don't leave discovery mode on when controlling a robot as this can cause performance issues.


findRobots

public void findRobots()

endDiscovery

public void endDiscovery()
Stops discovery for bluetooth Orbotix devices.


getControlledRobots

public java.util.ArrayList getControlledRobots()
Gets an array of Robot objects that are being controlled.

Returns:
Array of controlled robots.

getRobots

public java.util.ArrayList getRobots()
Accessor to available robots.

Returns:
An array of robots.

control

public void control(Robot robot)
Adds the robot to the controlled robot array.

Parameters:
robot - The robot to control. |

removeControl

public void removeControl(Robot robot)
Release the robot from control.

Parameters:
robot - The robot to release.

removeControl

public void removeControl(RobotControl control)
Removes a Robot control the controlled robot array.

Parameters:
control - The RobotControl object to remove.

removeAllControls

public void removeAllControls()
Removes all robots under control.


connectControlledRobots

public java.lang.Boolean connectControlledRobots()
Attempts to connect to any Robots who have been set up to be controlled.

Returns:
true if connects are attempted, otherwise false if nothing needed connected.
See Also:
RobotProvider.control(Robot)

disconnectControlledRobots

public void disconnectControlledRobots()
Disconnects all robots that are under control without removing them from control.


hasRobotControl

public boolean hasRobotControl()
Method for testing that there is at least one robot to control.

Returns:
true if at least one robot is available to control, otherwise, false.

getRobotControls

public java.util.ArrayList getRobotControls()
Accessor to the RobotControl objects.

Returns:
Array of RobotControl objects.

getRobotControl

public RobotControl getRobotControl(Robot robot)
Gets the RobotControl object for a Robot object.

Parameters:
robot - The robot.
Returns:
The RobotControl for the robot, otherwise null if the robot is not under control.

findRobot

public Robot findRobot(java.lang.String robotId)
Finds a robot in the robot list by it's bluetooth address.

Parameters:
robotId - String id that for the robot.
Returns:
A Robot object.

update

public void update(java.util.Observable observable,
                   java.lang.Object data)
DO NOT USE. Observes Robots state changes.

Specified by:
update in interface java.util.Observer