]> rtime.felk.cvut.cz Git - orte.git/commitdiff
ROBOT_DEMO: fix sync. problems in HokuyoView
authorMartin Vajnar <martin.vajnar@gmail.com>
Mon, 5 Aug 2013 19:26:29 +0000 (21:26 +0200)
committerMartin Vajnar <martin.vajnar@gmail.com>
Mon, 5 Aug 2013 19:26:29 +0000 (21:26 +0200)
Set new data only if the previous batch has been drawn and clone the newly
arrived data array. This prevents concurrent access problems when
the previous batch is being drawn on the UI thread and new data arrives
through ORTE's receive thread.

orte/Robot_Demo/src/org/ocera/orte/demo/HokuyoView.java
orte/Robot_Demo/src/org/ocera/orte/demo/MainActivity.java

index 6035076c5dfb26c0fa6a342a53ba1e5275868488..07452b61edf87359b1c4fff444e268e9ad0104d0 100644 (file)
@@ -21,6 +21,7 @@ public class HokuyoView extends View {
        private Paint paint = new Paint();
        private Path path = new Path();
        private boolean isRunning = false;
+       private boolean hasBeenDrawn = true;
 
        public HokuyoView(Context context, AttributeSet attrs) {
                super(context, attrs);
@@ -51,6 +52,9 @@ public class HokuyoView extends View {
                        
                        canvas.drawPath(path, paint);
                }
+               else
+                       canvas.drawARGB(0, 0, 0, 0);
+               hasBeenDrawn = true;
        }
        
        public void run(boolean run) {
@@ -58,8 +62,11 @@ public class HokuyoView extends View {
        }
        
        public void setData(int[] data) {
-               this.data = data;
-               postInvalidate();
+               if (hasBeenDrawn) {
+                       this.data = data.clone();
+                       hasBeenDrawn = false;
+                       postInvalidate();
+               }
        }
        
        public static double HOKUYO_INDEX_TO_DEG(int index) {
index f4d299ad60d018fa388df8830e285555d37e362a..d2b61d1210b737366823694752d521b9aec30c8d 100644 (file)
@@ -130,6 +130,7 @@ public class MainActivity extends Activity {
                else if (item.getTitle().equals("Stop hokuyo")) {
                        hokuyo_view.run(false);
                        hokuyo_scan.cancel();
+                       hokuyo_view.invalidate();
                        item.setTitle("Start hokuyo");
                }
                else if (item.getTitle().equals("Lift up")) {