Android Open Source - nxt-remote-controller Bluetooth Constants






From Project

Back to project page nxt-remote-controller.

License

The source code is released under:

MIT License

If you think the Android project nxt-remote-controller listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package git.egatuts.nxtremotecontroller.bluetooth;
/*from   ww w  .  j a va 2  s.c o m*/
import git.egatuts.nxtremotecontroller.GlobalUtils;

public class BluetoothConstants {

  /* Bytes used to send telegrams to the robot */
  public static final byte[] LENGTH_OUTPUT_STATE = { 0x0C, 0x00 };

  public static final byte COMMAND_DIRECT_RESPONSE    = 0x00;
  public static final byte COMMAND_SYSTEM_RESPONSE    = 0x01;
  public static final byte COMMAND_DIRECT_NO_RESPONSE = (byte) 0x80;
  public static final byte COMMAND_SYSTEM_NO_RESPONSE = (byte) 0x81;

  public static final byte OUTPUT_STATE_MOTOR = 0x04;

  public static final byte MOTOR_A   = 0x00;
  public static final byte MOTOR_B   = 0x01;
  public static final byte MOTOR_C   = 0x02;
  public static final byte MOTOR_ALL = (byte) 0xff;

  public static final byte MOTOR_MAX_POWER = 0x64;

  public static final byte MOTOR_MODE_COAST                      = 0x00;
  public static final byte MOTOR_MODE_ON                         = 0x01;
  public static final byte MOTOR_MODE_BREAK                      = 0x02;
  public static final byte MOTOR_MODE_ON_AND_BREAK               = 0x03;
  public static final byte MOTOR_MODE_REGULATED                  = 0x04;
  public static final byte MOTOR_MODE_ON_AND_REGULATED           = 0x05;
  public static final byte MOTOR_MODE_ON_AND_BREAK_AND_REGULATED = 0x07;

  public static final byte REGULATION_MODE_NONE   = 0x00;
  public static final byte REGULATION_MODE_SPEED  = 0x01;
  public static final byte REGULATION_MODE_MOTORS = 0x02;

  public static final byte TURN_RATIO_NONE = 0x00;
  public static final byte TURN_RATIO_MAX = 0x64;

  public static final byte RUN_STATE_NONE      = 0x00;
  public static final byte RUN_STATE_RAMP_UP   = 0x10;
  public static final byte RUN_STATE_RUNNING   = 0x20;
  public static final byte RUN_STATE_RAMP_DOWN = 0x40;

  public static final byte[] TACHO_LIMIT_NONE = { 0x00, 0x00, 0x00, 0x00 };

  /* Bytes used to receive telegrams from the robot */
  public static final byte COMMAND_REPLY = 0x02;

  /*
   *  Returns the byte array to control the left motor. Can be personalized.
   */
  public static byte[] motorC (double power, boolean regulateSpeed, boolean syncMotors) {
    byte roundedPower = (byte) (power * BluetoothConstants.MOTOR_MAX_POWER);
    byte[] rawCommand = {
            BluetoothConstants.COMMAND_DIRECT_NO_RESPONSE,
            BluetoothConstants.OUTPUT_STATE_MOTOR,
            BluetoothConstants.MOTOR_C,
            roundedPower,
            BluetoothConstants.MOTOR_MODE_ON_AND_BREAK_AND_REGULATED,
            BluetoothConstants.REGULATION_MODE_NONE,
            BluetoothConstants.TURN_RATIO_NONE,
            BluetoothConstants.RUN_STATE_RUNNING
    };
    byte[] command = GlobalUtils.concatBytes(BluetoothConstants.LENGTH_OUTPUT_STATE, rawCommand);
    if (regulateSpeed) command[7] |= 0x01;
    if (syncMotors) command[7] |= 0x02;
    return GlobalUtils.concatBytes(command, BluetoothConstants.TACHO_LIMIT_NONE);
  }

  /*
   *  Returns the byte array to control the right motor. Can be personalized.
   */
  public static byte[] motorB (double power, boolean regulateSpeed, boolean syncMotors) {
    byte roundedPower = (byte) (power * BluetoothConstants.MOTOR_MAX_POWER);
    byte[] rawCommand = {
      BluetoothConstants.COMMAND_DIRECT_NO_RESPONSE,
      BluetoothConstants.OUTPUT_STATE_MOTOR,
      BluetoothConstants.MOTOR_B,
      roundedPower,
      BluetoothConstants.MOTOR_MODE_ON_AND_BREAK_AND_REGULATED,
      BluetoothConstants.REGULATION_MODE_NONE,
      BluetoothConstants.TURN_RATIO_NONE,
      BluetoothConstants.RUN_STATE_RUNNING
    };
    byte[] command = GlobalUtils.concatBytes(BluetoothConstants.LENGTH_OUTPUT_STATE, rawCommand);
    if (regulateSpeed) command[7] |= 0x01;
    if (syncMotors) command[7] |= 0x02;
    return GlobalUtils.concatBytes(command, BluetoothConstants.TACHO_LIMIT_NONE);
  }

  /*
   *  Returns the byte array to control the arm motor. Can be personalized.
   */
  public static byte[] motorA (double power, boolean regulateSpeed, boolean syncMotors) {
    byte roundedPower = (byte) (power * BluetoothConstants.MOTOR_MAX_POWER);
    byte[] rawCommand = {
      BluetoothConstants.COMMAND_DIRECT_NO_RESPONSE,
      BluetoothConstants.OUTPUT_STATE_MOTOR,
      BluetoothConstants.MOTOR_A,
      roundedPower,
      BluetoothConstants.MOTOR_MODE_ON_AND_BREAK_AND_REGULATED,
      BluetoothConstants.REGULATION_MODE_NONE,
      BluetoothConstants.TURN_RATIO_NONE,
      BluetoothConstants.RUN_STATE_RUNNING
    };
    byte[] command = GlobalUtils.concatBytes(BluetoothConstants.LENGTH_OUTPUT_STATE, rawCommand);
    if (regulateSpeed) command[7] |= 0x01;
    if (syncMotors) command[7] |= 0x02;
    return GlobalUtils.concatBytes(command, BluetoothConstants.TACHO_LIMIT_NONE);
  }

  /*
   *  Moves the two motors that let the robot move.
   */
  public static byte[] motorBC (double powerLeft, double powerRight, boolean regulateSpeed, boolean syncMotors) {
    byte[] motorLeft  = BluetoothConstants.motorC(powerLeft, regulateSpeed, syncMotors);
    byte[] motorRight = BluetoothConstants.motorB(powerRight, regulateSpeed, syncMotors);
    return GlobalUtils.concatBytes(motorLeft, motorRight);
  }

}




Java Source Code List

.OldPadControllerFragment.java
com.andexert.library.ApplicationTest.java
com.andexert.library.RippleView.java
com.andexert.rippleeffect.ApplicationTest.java
com.andexert.rippleeffect.CustomAdapter.java
com.andexert.rippleeffect.MainActivity.java
com.andexert.rippleeffect.OnTapListener.java
com.gc.materialdesign.utils.Utils.java
com.gc.materialdesign.views.ButtonFlat.java
com.gc.materialdesign.views.ButtonFloatSmall.java
com.gc.materialdesign.views.ButtonFloat.java
com.gc.materialdesign.views.ButtonIcon.java
com.gc.materialdesign.views.ButtonRectangle.java
com.gc.materialdesign.views.Button.java
com.gc.materialdesign.views.Card.java
com.gc.materialdesign.views.CheckBox.java
com.gc.materialdesign.views.CustomView.java
com.gc.materialdesign.views.LayoutRipple.java
com.gc.materialdesign.views.ProgressBarCircularIndeterminate.java
com.gc.materialdesign.views.ProgressBarDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminate.java
com.gc.materialdesign.views.RippleView.java
com.gc.materialdesign.views.ScrollView.java
com.gc.materialdesign.views.Slider.java
com.gc.materialdesign.views.Switch.java
com.gc.materialdesign.widgets.ColorSelector.java
com.gc.materialdesign.widgets.Dialog.java
com.gc.materialdesign.widgets.SnackBar.java
git.egatuts.nxtremotecontroller.ApplicationTest.java
git.egatuts.nxtremotecontroller.GlobalUtils.java
git.egatuts.nxtremotecontroller.activity.ActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.BaseActivity.java
git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
git.egatuts.nxtremotecontroller.activity.DefaultActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.MainActivity.java
git.egatuts.nxtremotecontroller.activity.SettingsActivity.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothConstants.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothUtils.java
git.egatuts.nxtremotecontroller.bluetooth.NXTConnector.java
git.egatuts.nxtremotecontroller.device.PairedDeviceAdapter.java
git.egatuts.nxtremotecontroller.device.PairedDeviceItemClickListener.java
git.egatuts.nxtremotecontroller.device.PairedDeviceViewHolder.java
git.egatuts.nxtremotecontroller.device.PairedDevice.java
git.egatuts.nxtremotecontroller.exception.SocketCreationException.java
git.egatuts.nxtremotecontroller.fragment.ActivityBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BluetoothFragment.java
git.egatuts.nxtremotecontroller.fragment.ControllerBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.DefaultFragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.FragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.HomeFragment.java
git.egatuts.nxtremotecontroller.fragment.LocalControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.OnlineControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.ScanFragment.java
git.egatuts.nxtremotecontroller.fragment.SettingsFragment.java
git.egatuts.nxtremotecontroller.listener.AnimationEndListener.java
git.egatuts.nxtremotecontroller.listener.AppKillerListener.java
git.egatuts.nxtremotecontroller.listener.BaseListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothDiscoveryListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothEnableListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothPairingListener.java
git.egatuts.nxtremotecontroller.navigation.DrawerItemViewHolder.java
git.egatuts.nxtremotecontroller.navigation.DrawerItem.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerAdapter.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerCallback.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerFragment.java
git.egatuts.nxtremotecontroller.preference.PreferencesUtils.java
git.egatuts.nxtremotecontroller.receiver.AppKillerReceiver.java
git.egatuts.nxtremotecontroller.receiver.BaseReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothDiscoveryReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothEnableReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothPairingReceiver.java
git.egatuts.nxtremotecontroller.thread.BaseThread.java
git.egatuts.nxtremotecontroller.thread.ConnectThread.java
git.egatuts.nxtremotecontroller.thread.ConnectedThread.java
git.egatuts.nxtremotecontroller.views.BaseIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.BaseProgressDialog.java
git.egatuts.nxtremotecontroller.views.JoystickView.java
git.egatuts.nxtremotecontroller.views.LongIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.ShortIndeterminateProgressDialog.java