/** センサーを停止する. */
  public void stopSensor() {

    if (!mIsSensorStarted) {
      return;
    }
    mIsSensorStarted = false;
    mDevice.getSensorControl().removeSensorListener(this);
    mDevice.getSensorControl().stopStreaming();
    mSensorListener = null;
  }
 public void setSphero(float heading, float speed, int milliSeconds) {
   final float direction = heading;
   final int time = milliSeconds;
   final float velocity = speed;
   mRobot.drive(direction, velocity);
   try {
     Thread.sleep(time);
   } catch (InterruptedException e) {
     e.printStackTrace();
     // handle the exception...
     // For example consider calling Thread.currentThread().interrupt(); here.
   }
 }
  /** 衝突イベントの検知を終了する. */
  public void stopCollision() {
    if (!mIsCollisionStarted) {
      return;
    }

    mIsCollisionStarted = false;
    mCollisionListener = null;
    mDevice.getCollisionControl().removeCollisionListener(this);
    mDevice.getCollisionControl().stopDetection();

    if (BuildConfig.DEBUG) {
      Log.d("", "stop collision");
    }
  }
  /**
   * 衝突の監視を開始する.
   *
   * @param listener リスナー
   */
  public void startCollistion(final DeviceCollisionListener listener) {

    if (mIsCollisionStarted) {
      return;
    }

    if (BuildConfig.DEBUG) {
      Log.d("", "start collision");
    }

    mIsCollisionStarted = true;
    mCollisionListener = listener;
    mDevice.getCollisionControl().addCollisionListener(this);
    mDevice.getCollisionControl().startDetection(90, 90, 130, 130, 100);
  }
  /**
   * センサーを開始する.
   *
   * @param listener リスナー
   */
  public void startSensor(final DeviceSensorListener listener) {

    if (mIsSensorStarted) {
      return;
    }

    mIsSensorStarted = true;
    mSensorListener = listener;
    SensorControl sc = mDevice.getSensorControl();
    sc.setRate(SENSOR_RATE);
    sc.enableStreaming(true);
    sc.addSensorListener(
        this,
        SensorFlag.ACCELEROMETER_NORMALIZED,
        SensorFlag.GYRO_NORMALIZED,
        SensorFlag.ATTITUDE,
        SensorFlag.QUATERNION,
        SensorFlag.LOCATOR);

    ConfigureLocatorCommand.sendCommand(
        mDevice, ConfigureLocatorCommand.ROTATE_WITH_CALIBRATE_FLAG_OFF, 0, 0, 0);
    mPreSensorTimestamp = System.currentTimeMillis();
  }
 /**
  * When the user clicks "STOP", stop the Robot.
  *
  * @param v The View that had been clicked
  */
 public void onStopClick(View v) {
   if (mRobot != null) {
     // Stop robot
     mRobot.stop();
   }
 }
 /**
  * 色を設定する.
  *
  * @param r 赤
  * @param g 緑
  * @param b 青
  */
 public void setColor(final int r, final int g, final int b) {
   mDevice.setColor(r, g, b);
   // SpheroのgetColorでは正しく現在の色がとれない(消灯しているのに0xff000000以外が返ってくる)ので
   // 自前で色を管理する。
   mColor = (0xff000000 | (r << 16) | (g << 8) | b);
 }