Finish off SlamController
This commit is contained in:
@@ -13,9 +13,10 @@ import com.example.carcontroller.R;
|
||||
public class SlamController extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
|
||||
SeekBar steeringSlider;
|
||||
SeekBar throttleSlider;
|
||||
private SeekBar steeringSlider;
|
||||
private SeekBar throttleSlider;
|
||||
private static PiLoader grpcController;
|
||||
private SlamView slamView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -30,6 +31,7 @@ public class SlamController extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
if (throttleSlider != null) {
|
||||
throttleSlider.setOnSeekBarChangeListener(this);
|
||||
}
|
||||
slamView = findViewById(R.id.slamView);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,17 +76,20 @@ public class SlamController extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
}
|
||||
// Should call the equivalent of the load method either here or in the loader.
|
||||
grpcController.start();
|
||||
slamView.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
grpcController.stop();
|
||||
slamView.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
grpcController.stop();
|
||||
slamView.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.example.carcontroller.SLAM;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
@@ -13,12 +17,12 @@ import com.google.protobuf.ByteString;
|
||||
|
||||
public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListener {
|
||||
|
||||
SlamUpdater slam;
|
||||
Thread mapThread;
|
||||
Context context;
|
||||
private SlamUpdater slam;
|
||||
private Thread mapThread;
|
||||
private Context context;
|
||||
private int width;
|
||||
private int height;
|
||||
private SurfaceHolder surfaceHolder;
|
||||
private Paint paint;
|
||||
|
||||
public SlamView(Context context) {
|
||||
super(context);
|
||||
@@ -44,6 +48,9 @@ public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListe
|
||||
String port = prefs.getString("zmqPort", "5050");
|
||||
slam = new ZmqSlamUpdater(host, port);
|
||||
slam.addMapChangedListener(this);
|
||||
surfaceHolder = getHolder();
|
||||
paint = new Paint();
|
||||
paint.setColor(Color.BLUE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +73,27 @@ public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListe
|
||||
|
||||
@Override
|
||||
public void mapChanged(ByteString map, SlamLocation location) {
|
||||
if (surfaceHolder.getSurface().isValid()) {
|
||||
Canvas canvas = surfaceHolder.lockCanvas();
|
||||
canvas.save();
|
||||
canvas.drawColor(Color.WHITE);
|
||||
// Using width as we want square.
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ALPHA_8);
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
// 0-255 is appropriate for the config used.
|
||||
bitmap.setPixel(i, j, map.byteAt(i * width + j));
|
||||
}
|
||||
}
|
||||
canvas.drawBitmap(bitmap, 0, 0, paint);
|
||||
canvas.restore();
|
||||
surfaceHolder.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int b, int oldW, int oldB) {
|
||||
super.onSizeChanged(w, b, oldW, oldB);
|
||||
width = w;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class ZmqSlamUpdater extends SlamUpdater {
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
context = new ZContext();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user