@ Overridevoid handleMessage (Message msg) {activity=mActivity.get (); (activity!=null) {(msg.what) {
case cBluetooth.BL_NOT_AVAILABLE:
Log.d (cBluetooth.TAG, Bluetooth is not available. Exit );
Toast.makeText (activity.getBaseContext (), Bluetooth is not available raquo ;, Toast.LENGTH_SHORT) .show ();
activity.finish ();
break;
case cBluetooth.BL_INCORRECT_ADDRESS:
Log.d (cBluetooth.TAG, Incorrect MAC address );
Toast.makeText (activity.getBaseContext (), Incorrect Bluetooth address raquo ;, Toast.LENGTH_SHORT) .show ();
break;
case cBluetooth.BL_REQUEST_ENABLE:
Log.d (cBluetooth.TAG, Request Bluetooth Enable );
BluetoothAdapter.getDefaultAdapter ();
Intent enableBtIntent=new Intent (BluetoothAdapter.ACTION_REQUEST_ENABLE);
activity.startActivityForResult (enableBtIntent, 1);
break;
case cBluetooth.BL_SOCKET_FAILED:
Toast.makeText (activity.getBaseContext (), Socket failed raquo ;, Toast.LENGTH_SHORT) .show ();
break;
} final MyHandler mHandler=new MyHandler (this); final static Runnable sRunnable=new Runnable () {void run () {}
}; MyView extends View {fingerPaint, borderPaint, textPaint; dispWidth; dispHeight; x; y; xcirc; ycirc; directionL= raquo ;; directionR= raquo ;; drag=false; dragX=0; dragY=0; MyView (Context context) {(context);=new Paint () ;. setAntiAlias ??(true) ;. setColor (Color.RED);=new Paint () ;. setColor (Color.BLUE ) ;. setAntiAlias ??(true) ;. setStyle (Style.STROKE) ;. setStrokeWidth (3);=new Paint ();
textPaint.setColor (Color.WHITE);
textPaint.setStyle (Style.FILL);
textPaint.setColor (Color.BLACK);
textPaint.setTextSize (14);
} void onDraw (Canvas canvas) {= (int) Math.round ((this.getRight () - this.getLeft ())/3.5);=(int) Math.round (( this.getBottom () - this.getTop ())/1.7); (! drag) {= dispWidth;=dispHeight; .setColor (Color.RED);
}. drawCircle (x, y, FINGER_CIRCLE_SIZE, fingerPaint);.drawCircle (dispWidth, dispHeight, BIG_CIRCLE_SIZE, borderPaint); (show_Debug) {
canvas.drawText (String.valueOf ( X: + xcirc), 10, 75, textPaint);
canvas.drawText (String.valueOf ( Y: + (- ycirc)), 10, 95, textPaint);
canvas.drawText (String.valueOf ( Motor: + cmdSendL + cmdSendR), 10, 115, textPaint);
}
@ Overrideboolean onTouchEvent (MotionEvent event) {evX=event.getX (); evY=event.getY ();=event.getX () - dispWidth;=event.getY () - dispHeight; radius=(float) Math.sqrt (Math.pow (Math.abs (xcirc), 2) + Math.pow (Math.abs (ycirc), 2)); (event.getAction ()) {MotionEvent.ACTION_DOWN: (radius gt;=0 amp; amp; radius lt;=BIG_CIRCLE_SIZE) {= evX;=evY; .setColor (Color.GREEN); (xcirc, ycirc); ();=true;
}; MotionEvent.ACTION_MOVE: (drag amp; amp; radius gt;=0 amp; amp; radius lt;=BIG_CIRCLE_SIZE) {= evX;=evY; .setColor (Color.GREEN); (xcirc, ycirc); ();
}; MotionEvent.ACTION_UP:=0;=0; =False; (xcirc, ycirc); () ;;
} true;
} void CalcMotor (float calc_x, float calc_y) {directionL= raquo ;; directionR= raquo ;; _ x=-calc_x; xAxis=Math.round (calc_x * pwmMax/BIG_CIRCLE_SIZE) ; yAxis=Math.round (calc_y * pwmMax/BIG_CIRCLE_SIZE); xR=Math.round (BIG_CIRCLE_SIZE * xRperc/100); (xAxis gt; 0) {= yAxis; (Math.abs (Math.round (calc_x)) gt; xR) {= Math.round ((calc_x-xR) * pwmMax/(BIG_CIRCLE_SIZE-xR));=Math. round (-motorLeft * yAxis/pwmMax);
} motorLeft=yAxis - yAxis * xAxis/pwmMax;
} if (xAxis lt; 0) {= yAxis; (Math.abs (Math.round (calc_x)) gt; xR) {= Math.round ((Math.abs (calc_x) -xR) * pwmMax/(BIG_CIRCLE_SIZE-xR));=Math.round (-motorRight * yAxis/pwmMax);
} motorRight=yAxis - yAxis * Math.abs (xAxis)/pwmMax;
} if (xAxis == 0) {= yAxis;=yAxis;
} (motorLeft gt; 0) {= - raquo ;;
} (motorRight gt; 0) {= - raquo ;;
}=Math.abs (motorLeft);=Math.abs (motorRight); (motorLeft gt; pwmMax) motorLeft=pwmMax; (motorRight gt; pwmMax) motorRight=pwmMax;=String.valueOf ( commandLeft + directionL + motorLeft + r );=String.valueOf (commandRight + directionR + motorRight + r ); (BT_is_connect) ...