コード例 #1
0
        @Override
        public void handleMessage(Message myMessage) {

          int message;

          switch (message = myMessage.getData().getInt("message")) {
            case MOTOR_A:
            case MOTOR_B:
            case MOTOR_C:
              changeMotorSpeed(message, myMessage.getData().getInt("value1"));
              break;
            case MOTOR_B_ACTION:
              rotateTo(MOTOR_B, myMessage.getData().getInt("value1"));
              break;
            case MOTOR_RESET:
              reset(myMessage.getData().getInt("value1"));
              break;
            case START_PROGRAM:
              startProgram(myMessage.getData().getString("name"));
              break;
            case STOP_PROGRAM:
              stopProgram();
              break;
            case GET_PROGRAM_NAME:
              getProgramName();
              break;
            case DO_BEEP:
              doBeep(myMessage.getData().getInt("value1"), myMessage.getData().getInt("value2"));
              break;
            case DO_ACTION:
              doAction(myMessage.getData().getInt("value1"));
              break;
            case READ_MOTOR_STATE:
              readMotorState(myMessage.getData().getInt("value1"));
              break;
            case GET_FIRMWARE_VERSION:
              getFirmwareVersion();
              break;
            case FIND_FILES:
              findFiles(
                  myMessage.getData().getInt("value1") == 0, myMessage.getData().getInt("value2"));
              break;
            case DISCONNECT:
              // send stop messages before closing
              changeMotorSpeed(MOTOR_A, 0);
              changeMotorSpeed(MOTOR_B, 0);
              changeMotorSpeed(MOTOR_C, 0);
              waitSomeTime(500);
              try {
                destroyNXTconnection();
              } catch (IOException e) {
              }
              break;
          }
        }
コード例 #2
0
  /**
   * Creates and starts the a thread for communication via bluetooth to the NXT robot.
   *
   * @param mac_address The MAC address of the NXT robot.
   */
  private void startBTCommunicator(String mac_address) {
    connected = false;
    connectingProgressDialog =
        ProgressDialog.show(
            this, "", getResources().getString(R.string.connecting_please_wait), true);

    if (myBTCommunicator != null) {
      try {
        myBTCommunicator.destroyNXTconnection();
      } catch (IOException e) {
      }
    }
    createBTCommunicator();
    myBTCommunicator.setMACAddress(mac_address);
    myBTCommunicator.start();
    updateButtonsAndMenu();
  }