Move packages to org.vato
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package org.vato.carcontroller;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
public class SimpleController extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
SeekBar steeringSlider;
|
||||
SeekBar throttleSlider;
|
||||
private static PiLoader grpcController;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_simple_controller);
|
||||
|
||||
steeringSlider = findViewById(R.id.steeringBar);
|
||||
if (steeringSlider != null) {
|
||||
steeringSlider.setOnSeekBarChangeListener(this);
|
||||
}
|
||||
throttleSlider = findViewById(R.id.throttleBar);
|
||||
if (throttleSlider != null) {
|
||||
throttleSlider.setOnSeekBarChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
||||
if (grpcController == null) {
|
||||
grpcController = new PiLoader(prefs.getString("host", "10.0.0.53"), Integer.parseInt(prefs.getString("port", "50051")));
|
||||
}
|
||||
// Should call the equivalent of the load method either here or in the loader.
|
||||
grpcController.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
grpcController.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
grpcController.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
// Call the gRPC method to change the throttle.
|
||||
switch (seekBar.getId()) {
|
||||
case R.id.steeringBar:
|
||||
if (grpcController != null) {
|
||||
grpcController.updateSteering(i);
|
||||
}
|
||||
break;
|
||||
case R.id.throttleBar:
|
||||
if (grpcController != null) {
|
||||
grpcController.updateThrottle(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// Reset back to the middle, as this is how the controller will normally work.
|
||||
|
||||
// Check if this will actually still call the onProgressChanged listener method.
|
||||
// Otherwise update the steering/throttle here as well.
|
||||
steeringSlider.setProgress(50);
|
||||
throttleSlider.setProgress(50);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user