示例#1
0
  /**
   * Disable controller data streaming for a Robot
   *
   * @param robot the Robot to stream data from
   */
  public void disableControllerStreaming(Robot robot) {
    // Turn on stabilization and turn off back LED
    StabilizationCommand.sendCommand(robot, true);
    BackLEDOutputCommand.sendCommand(robot, 0.0f);

    // Disable data streaming and delete profile
    SetDataStreamingCommand.sendCommand(robot, 0, 0, 0, 0);
    DeviceMessenger.getInstance().removeAsyncDataListener(robot, mDataListener);
  }
示例#2
0
  /**
   * Enable controller data streaming with infinite packets
   *
   * @param robot the Robot to stream data from
   * @param divisor Divisor of the maximum sensor sampling rate (400 Hz)
   * @param packetFrames Number of samples created on the device before it sends a packet to the
   *     phone with samples
   * @param sensorMask Bitwise selector of data sources to stream
   */
  public void enableControllerStreaming(
      Robot robot, int divisor, int packetFrames, long sensorMask) {
    // Turn off stabilization and turn on back LED
    StabilizationCommand.sendCommand(robot, false);
    BackLEDOutputCommand.sendCommand(robot, 1.0f);

    // Request data streaming
    this.setDataStreaming(robot, divisor, packetFrames, sensorMask, 0);
  }
  @Override
  protected void onStop() {
    super.onStop();

    if (screenWakeLock != null) {
      screenWakeLock.release();
      screenWakeLock = null;
    }

    // remove the flag that disables the screen dimming
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // remove use of the location listener
    locationManager.removeUpdates(locationListener);

    // turn stabilization back on
    StabilizationCommand.sendCommand(mRobot, true);

    // turn rear light off
    FrontLEDOutputCommand.sendCommand(mRobot, 0.0f);

    // unregister the async data listener to prevent a memory leak.
    DeviceMessenger.getInstance().removeAsyncDataListener(mRobot, mDataListener);

    // stop the streaming data when we leave
    SetDataStreamingCommand.sendCommand(
        mRobot, 0, 0, SetDataStreamingCommand.DATA_STREAMING_MASK_OFF, 0);

    // pause here for a tenth of a second to allow the previous commands to go through before we
    // shutdown
    // the connection to the ball
    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    // disconnect from the ball
    RobotProvider.getDefaultProvider().removeAllControls();

    // mRobot = null;
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == STARTUP_ACTIVITY && resultCode == RESULT_OK) {
      // get the connected robot
      final String robot_id = data.getStringExtra(StartupActivity.EXTRA_ROBOT_ID);
      Log.d(TAG, "Hi, there robot " + robot_id);
      if (robot_id != null && !robot_id.equals("")) {
        mRobot = RobotProvider.getDefaultProvider().findRobot(robot_id);

        StabilizationCommand.sendCommand(mRobot, false);
        FrontLEDOutputCommand.sendCommand(mRobot, 0.5f);
        startStreaming();
      }
    }

    // start blinking
    // blink(false);
    RGBLEDOutputCommand.sendCommand(mRobot, 0, 0, 0);
  }