Skip to content

Commit

Permalink
Pasarle la velocidad
Browse files Browse the repository at this point in the history
  • Loading branch information
vtcmer committed Sep 11, 2019
1 parent 097e5f2 commit 5caefc0
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 176 deletions.
3 changes: 2 additions & 1 deletion i-robot/IRobotApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"></activity>
<activity android:name=".MainActivity"
android:screenOrientation="portrait"></activity>
<activity android:name=".DeviceListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ScrollView;

import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;
Expand All @@ -23,8 +25,6 @@
import butterknife.ButterKnife;
import butterknife.OnClick;

import static java.lang.Thread.sleep;

public class MainActivity extends AppCompatActivity {

Handler bluetoothIn;
Expand All @@ -46,8 +46,15 @@ public class MainActivity extends AppCompatActivity {
ImageButton btnRight;
@BindView(R.id.btnBack)
ImageButton btnBack;
@BindView(R.id.scrollView)
ScrollView scrollView;

@BindView(R.id.txtSeekBarLeft)
TextView txtSeekBarLeft;
@BindView(R.id.seekBarLeft)
SeekBar seekBarLeft;
@BindView(R.id.txtSeekBarRigth)
TextView txtSeekBarRigth;
@BindView(R.id.seekBarRight)
SeekBar seekBarRight;

private BluetoothAdapter btAdapter = null;
private BluetoothSocket btSocket = null;
Expand All @@ -57,29 +64,34 @@ public class MainActivity extends AppCompatActivity {
// String for MAC address
private static String address = null;

final static Integer SPEED_LEFT_DEFAULT = 200;
final static Integer SPEED_RIGHT_DEFATUL = 200;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);

this.onSeekBarChange();


bluetoothIn = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == handlerState) {

String data = (String) msg.obj; // msg.arg1 = bytes from connect thread

if (data.equals("F")){
if (data.equals("F")) {
resetStatusActionsButtons();
selectAction(btnForward);
} else if (data.equals("B")){
} else if (data.equals("B")) {
resetStatusActionsButtons();
selectAction(btnBack);
} else if (data.equals("R")){
} else if (data.equals("R")) {
resetStatusActionsButtons();
selectAction(btnRight);
} else if (data.equals("L")){
} else if (data.equals("L")) {
resetStatusActionsButtons();
selectAction(btnLeft);
}
Expand Down Expand Up @@ -156,7 +168,7 @@ public void onChangeMode(View view) {
Toast.makeText(getBaseContext(), "Automático", Toast.LENGTH_SHORT).show();
break;
case R.id.btnModeStop:
mConnectedThread.write("3");
mConnectedThread.write("3");
Toast.makeText(getBaseContext(), "Stop", Toast.LENGTH_SHORT).show();
break;
}
Expand Down Expand Up @@ -184,7 +196,6 @@ private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOE
}



@OnClick({R.id.btnStop, R.id.btnForward, R.id.btnBack, R.id.btnRight, R.id.btnLeft})
public void onChangeDirection(View view) {

Expand Down Expand Up @@ -214,6 +225,7 @@ public void onChangeDirection(View view) {

/**
* Cambio entre modo manual y automático
*
* @param automatic
*/
void changeMode(boolean automatic) {
Expand All @@ -232,6 +244,7 @@ void changeMode(boolean automatic) {

/**
* Activa y desactiva los botones
*
* @param active
*/
private void changeStatusActionButtons(boolean active) {
Expand All @@ -246,24 +259,26 @@ private void changeStatusActionButtons(boolean active) {

/**
* Marca el botón como activo
*
* @param imageButton
*/
private void selectAction(ImageButton imageButton){
private void selectAction(ImageButton imageButton) {
imageButton.setBackgroundDrawable(getResources().getDrawable(R.color.active));
}

/**
* Resetea el botón de acción al color por defecto
*
* @param imageButton
*/
private void resetAction(ImageButton imageButton){
private void resetAction(ImageButton imageButton) {
imageButton.setBackgroundDrawable(getResources().getDrawable(R.color.enabled));
}

/**
* Establece el valor de colores por defecto de los botones de acción
*/
private void resetStatusActionsButtons(){
private void resetStatusActionsButtons() {

this.btnForward.setBackgroundDrawable(getResources().getDrawable(R.color.enabled));
this.btnBack.setBackgroundDrawable(getResources().getDrawable(R.color.enabled));
Expand Down Expand Up @@ -323,6 +338,70 @@ public void write(String input) {

}
}




}


void onSeekBarChange(){

this.seekBarLeft.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

Integer speed = 0;

@Override
public void onProgressChanged(SeekBar seekBar, int progressValue, boolean fromUser) {

speed = SPEED_LEFT_DEFAULT + progressValue;

txtSeekBarLeft.setText("IZ: " + speed);

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
txtSeekBarLeft.setText("IZ: " + speed );
mConnectedThread.write("L-"+speed);
// TODO ENVIAR DATO

}
});


this.seekBarRight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

Integer speed = 0;

@Override
public void onProgressChanged(SeekBar seekBar, int progressValue, boolean fromUser) {
speed = SPEED_LEFT_DEFAULT + progressValue;
txtSeekBarRigth.setText("DE: " + speed );

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

txtSeekBarRigth.setText("DE: ");
mConnectedThread.write("R-"+speed);
// TODO ENVIAR DATO


}
});

}


Expand Down
Loading

0 comments on commit 5caefc0

Please sign in to comment.