Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. package net.yeputons.robotics.camp2014.week1.BluetoothBeep;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.Toast;
  8. import net.yeputons.robotics.libs.NxtBluetoothController;
  9. import net.yeputons.robotics.libs.NxtController;
  10. import net.yeputons.robotics.libs.NxtUsbController;
  11.  
  12. import java.io.IOException;
  13.  
  14. public class MyActivity extends Activity {
  15.     private NxtController nxt;
  16.  
  17.     /**
  18.      * Called when the activity is first created.
  19.      */
  20.     @Override
  21.     public void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.main);
  24.  
  25.         ((Button)findViewById(R.id.buttonConnect)).setOnClickListener(new View.OnClickListener() {
  26.             @Override
  27.             public void onClick(View v) {
  28.                 try {
  29.                     //nxt = new NxtBluetoothController(NxtBluetoothController.findDeviceByName("ffeferf"));
  30.                     nxt = new NxtUsbController(MyActivity.this, NxtUsbController.getAnyNxtDevice(MyActivity.this));
  31.                     nxt.connect();
  32.                 } catch (Exception e) {
  33.                     e.printStackTrace();
  34.                     Toast.makeText(MyActivity.this, e.toString(), Toast.LENGTH_LONG).show();
  35.                 }
  36.             }
  37.         });
  38.         ((Button)findViewById(R.id.buttonBeep)).setOnClickListener(new View.OnClickListener() {
  39.             @Override
  40.             public void onClick(View v) {
  41.                 byte[] msg = {
  42.                         (byte)0x80,
  43.                         0x03,
  44.                         (byte)184,
  45.                         1,
  46.                         (byte)224,
  47.                         1
  48.                 };
  49.                 try {
  50.                     nxt.sendDirectCommand(msg);
  51.                 } catch (IOException e) {
  52.                     e.printStackTrace();
  53.                 } catch (InterruptedException e) {
  54.                     e.printStackTrace();
  55.                 }
  56.             }
  57.         });
  58.         ((Button)findViewById(R.id.buttonDisconnect)).setOnClickListener(new View.OnClickListener() {
  59.             @Override
  60.             public void onClick(View v) {
  61.                 nxt.disconnect();
  62.             }
  63.         });
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement