Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.yeputons.robotics.camp2014.week1.BluetoothBeep;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.Toast;
- import net.yeputons.robotics.libs.NxtBluetoothController;
- import net.yeputons.robotics.libs.NxtController;
- import net.yeputons.robotics.libs.NxtUsbController;
- import java.io.IOException;
- public class MyActivity extends Activity {
- private NxtController nxt;
- /**
- * Called when the activity is first created.
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- ((Button)findViewById(R.id.buttonConnect)).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- //nxt = new NxtBluetoothController(NxtBluetoothController.findDeviceByName("ffeferf"));
- nxt = new NxtUsbController(MyActivity.this, NxtUsbController.getAnyNxtDevice(MyActivity.this));
- nxt.connect();
- } catch (Exception e) {
- e.printStackTrace();
- Toast.makeText(MyActivity.this, e.toString(), Toast.LENGTH_LONG).show();
- }
- }
- });
- ((Button)findViewById(R.id.buttonBeep)).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- byte[] msg = {
- (byte)0x80,
- 0x03,
- (byte)184,
- 1,
- (byte)224,
- 1
- };
- try {
- nxt.sendDirectCommand(msg);
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- });
- ((Button)findViewById(R.id.buttonDisconnect)).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- nxt.disconnect();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement