public class LegoRobot extends java.lang.Object implements SharedConstants
Modifier and Type | Class and Description |
---|---|
static class |
LegoRobot.ClosingMode
Modes to determine what happens when the title bar close button is hit.
|
Modifier and Type | Field and Description |
---|---|
static boolean |
isConnecting |
ABOUT, ANGLE, ANGLESTEPSMODE, BOOLEANMODE, BOOT, BRAKE, CELSIUSMODE, CLOSE, CUSTOM, DEBUG_LEVEL_HIGH, DEBUG_LEVEL_LOW, DEBUG_LEVEL_MEDIUM, DEBUG_LEVEL_OFF, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, HIGH_SPEED_BUFFER, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, NO_OF_SENSOR_TYPES, NO_SENSOR, NXJ_FIND_FIRST, NXJ_FIND_NEXT, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TITLE, TITLEMP, TRANSITIONCNTMODE, VERSION, WRITE
Constructor and Description |
---|
LegoRobot()
Asks for the Bluetooth name and creates a LegoRobot instance.
|
LegoRobot(long btAddress)
Creates a LegoRobot instance with given Bluetooth address.
|
LegoRobot(long btAddress,
boolean connect)
Creates a LegoRobot instance with given Bluetooth address.
|
LegoRobot(java.lang.String btName)
Creates a LegoRobot instance with given Bluetooth name.
|
LegoRobot(java.lang.String btName,
boolean connect)
Creates a LegoRobot instance with given Bluetooth name.
|
Modifier and Type | Method and Description |
---|---|
void |
addPart(Part part)
Assembles the given part into the robot.
|
void |
clearDisplay()
Clears the display.
|
boolean |
connect()
Connects the host to the robot via Bluetooth.
|
boolean |
connect(boolean isConnectPane)
Connects the host to the robot via Bluetooth.
|
boolean |
connect(boolean isConnectPane,
boolean isAnnounce)
Connects the host to the robot via Bluetooth.
|
boolean |
disconnect()
Closes the Bluetooth communication.
|
void |
drawString(java.lang.String text,
int x,
int y)
Draws the given text line starting at given position.
|
void |
drawStringAt(java.lang.String text,
int count)
Draws the given text line starting at given screen cell count.
|
void |
exit()
Closes the connection dialog and any open QuitPane, disconnects
the Bluetooth communication and terminates the program.
|
boolean |
fileExists(java.lang.String filename)
Searches for given file in the brick's file system.
|
FileInfo |
findFirst()
Start file enumeration in the brick's file system.
|
FileInfo |
findNext(byte handle)
Searches the next file in a file enumeration.
|
static java.lang.String |
getAbout()
Returns copywrite information.
|
double |
getBatteryLevel()
Returns the battery level.
|
java.lang.String |
getBtAddress()
Returns the Bluetooth address (hex).
|
long |
getBtAddressLong()
Returns the Bluetooth address (long).
|
java.lang.String |
getBtName()
Returns the Bluetooth name
|
static int |
getDebugLevel()
Returns the current debug level.
|
java.lang.String |
getFriendlyName()
Sends a request to the brick to get the Bluetooth friendly name.
|
int |
getHitButtonID()
Returns the button ID of the button previously hit.
|
java.io.InputStream |
getInputStream()
Returns the InputStream reference of the Bluetooth connection.
|
java.io.OutputStream |
getOutputStream()
Returns the OutputStream reference of the Bluetooth connection.
|
static ch.aplu.nxt.platform.NxtProperties |
getProperties()
Returns the properties from the NxtJLib property file.
|
javax.microedition.io.StreamConnection |
getStreamConnection()
Returns the StreamConnection reference of the Bluetooth connection.
|
static java.lang.String |
getVersion()
Returns library version information.
|
boolean |
isButtonHit()
Returns true, if any of the buttons was hit.
|
boolean |
isButtonListenerRunning()
Returns the current state of the button listener thread.
|
boolean |
isConnected()
Returns the connection state.
|
boolean |
isDownHit()
Returns true, if the DOWN button was the last button hit since
the last call of this method.
|
boolean |
isEnterHit()
Returns true, if the ENTER button was the last button hit since
the last call of this method.
|
boolean |
isEscapeHit()
Returns true, if the ESCAPE button was the last button hit since
the last call of this method.
|
boolean |
isLeftHit()
Returns true, if the LEFT button was the last button hit since
the last call of this method.
|
boolean |
isRightHit()
Returns true, if the RIGHT button was the last button hit since
the last call of this method.
|
boolean |
isRunning()
Returns true as long as exit() is not called and the close button of the Connection Pane is
not hit.
|
boolean |
isUpHit()
Returns true, if the UP button was the last button hit since
the last call of this method.
|
void |
keepAlive()
Sends a keep alive command to prevent the automatic shutdown of
the brick.
|
void |
playConnectMelody()
Plays a standard connect melody.
|
void |
playDisconnectMelody()
Plays a standard disconnect melody.
|
void |
playTone(int frequency,
int duration)
Plays a tone with given frequency (in Hertz) and duration (in seconds).
|
byte[] |
readData()
Reads the data returned as a reply from the brick.
|
byte[] |
requestData(byte[] request)
Combines sendData() and readData() in synchronized block.
|
void |
reset()
Resets Nxt to start location/direction.
|
void |
sendData(byte[] command)
Sends a direct command to the brick.
|
void |
setChannel(int channel)
Sets the Bluetooth channel (default: 1).
|
void |
startButtonListener()
Starts a button listener to get button hit events.
|
boolean |
startProgram(java.lang.String filename) |
void |
stopButtonListener()
Stops the button listener and disables button hit events.
|
public LegoRobot(java.lang.String btName, boolean connect)
btName
- the Bluetooth friendly name of the brick, e.g. "NXT"connect
- if true, a connection trial is engagedpublic LegoRobot(java.lang.String btName)
btName
- the Bluetooth friendly name of the brick, e.g. "NXT"public LegoRobot(long btAddress, boolean connect)
btAddress
- the Bluetooth address of the brick, e.g. 0x0000A762B001connect
- if true, a connection trial is engagedpublic LegoRobot(long btAddress)
btAddress
- the Bluetooth address of the brick, e.g. 0x0000A762B001public LegoRobot()
public void setChannel(int channel)
channel
- the channel numberpublic static ch.aplu.nxt.platform.NxtProperties getProperties()
public static int getDebugLevel()
public void addPart(Part part)
part
- the part to assemblepublic boolean connect()
public boolean connect(boolean isConnectPane)
isConnectPane
- if true an information pane is shownpublic boolean connect(boolean isConnectPane, boolean isAnnounce)
isConnectPane
- if true, an information pane is shownisAnnounce
- if true, a connect/disconnect melody is playedpublic boolean disconnect()
public void exit()
public boolean isRunning()
public void playConnectMelody()
public void playDisconnectMelody()
public javax.microedition.io.StreamConnection getStreamConnection()
public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public java.lang.String getFriendlyName()
public byte[] requestData(byte[] request)
request
- the data to sendpublic void sendData(byte[] command)
command
- the data to sendpublic byte[] readData()
public boolean isConnected()
public void playTone(int frequency, int duration)
public double getBatteryLevel()
public java.lang.String getBtAddress()
public java.lang.String getBtName()
public long getBtAddressLong()
public static java.lang.String getVersion()
public static java.lang.String getAbout()
public void keepAlive()
LegoRobot
public boolean startProgram(java.lang.String filename)
public FileInfo findFirst()
public FileInfo findNext(byte handle)
handle
- the handle of the previous found filepublic boolean fileExists(java.lang.String filename)
public void reset()
public void startButtonListener()
public void stopButtonListener()
public boolean isButtonHit()
public int getHitButtonID()
public boolean isUpHit()
public boolean isDownHit()
public boolean isLeftHit()
public boolean isRightHit()
public boolean isEnterHit()
public boolean isEscapeHit()
public boolean isButtonListenerRunning()
public void drawString(java.lang.String text, int x, int y)
text
- the text to displayx
- unusedy
- unusedpublic void drawStringAt(java.lang.String text, int count)
text
- the text to displaycount
- unusedpublic void clearDisplay()