Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBrodin committed Jan 23, 2022
1 parent db1f3af commit 28a1432
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions app/src/main/java/fr/esiea/esieabot/bluetooth/BtClientActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.nio.charset.Charset;

import fr.esiea.esieabot.R;

//TODO Reecire la class en fragment
public class BtClientActivity extends AppCompatActivity {

private String mMessageFromServer = "";

private TextView mMessageTextView;
private SeekBar mSpeedSeekBar;

private String mDeviceAddress;
protected CommunicationsTask mBluetoothConnection;
Expand All @@ -41,28 +40,49 @@ protected void onCreate(Bundle savedInstanceState) {
mMessageTextView = (TextView)findViewById(R.id.serverReplyText);

ImageButton btnUp = (ImageButton) findViewById(R.id.arrow_up);
ImageButton btnDown = (ImageButton) findViewById(R.id.arrow_down);
ImageButton btnLeft = (ImageButton) findViewById(R.id.arrow_left);
ImageButton btnRight = (ImageButton) findViewById(R.id.arrow_right);
ImageButton btnStop = (ImageButton) findViewById(R.id.control_btn);

String up = "up";
String down = "down";
String left = "left";
String right = "right";
String stop = "stop";

btnUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
byte up = 00;
mBluetoothConnection.write(up);
mBluetoothConnection.write(up.getBytes());
}
});

mSpeedSeekBar = (SeekBar) findViewById(R.id.seekBar);

mSpeedSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
btnDown.setOnClickListener(new View.OnClickListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

if (fromUser==true) {

for (byte b : String.valueOf(progress).getBytes()) {
mBluetoothConnection.write(b);
}
mBluetoothConnection.write((byte)'.');

while (mBluetoothConnection.available() > 0) {
public void onClick(View v) {
mBluetoothConnection.write(down.getBytes());
}
});
btnLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBluetoothConnection.write(left.getBytes());
}
});
btnRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBluetoothConnection.write(right.getBytes());
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBluetoothConnection.write(stop.getBytes());
}
});
/*
while (mBluetoothConnection.available() > 0) {
char c = (char)mBluetoothConnection.read();
Expand All @@ -76,20 +96,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
else {
mMessageFromServer += c;
}
}
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});
*/
}

@Override
Expand All @@ -99,3 +106,4 @@ public void onDestroy() {
}
}


0 comments on commit 28a1432

Please sign in to comment.