ET_FAILED: .makeText (activity.getBaseContext (), Socket failed raquo ;, Toast.LENGTH_SHORT). show () ;;
} final MyHandler mHandler=new MyHandler (this); final static Runnable sRunnable=new Runnable () void run () {}
}; void onSensorChanged (SensorEvent e)
{directionL= raquo ;; directionR= raquo ;; cmdSendL, cmdSendR;=Math.round (e.values ??[0] * pwmMax/xR);=Math.round (e.values ??[1] * pwmMax/yMax); (xAxis gt; pwmMax) xAxis=pwmMax; if (xAxis lt; -pwmMax) xAxis=-pwmMax; (yAxis gt; pwmMax) yAxis=pwmMax; if (yAxis lt; -pwmMax) yAxis=-pwmMax; if (yAxis gt;=0 amp; amp; yAxis lt; yThreshold) yAxis=0; if (yAxis lt; 0 amp; amp; yAxis gt; -yThreshold) yAxis=0; (xAxis gt ; 0)
{= yAxis; (Math.abs (Math.round (e.values ??[0])) gt; xR)=Math.round ((e.values ??[0] -xR) * pwmMax/(xMax-xR));=Math.round (-motorLeft * yAxis/pwmMax);
} motorLeft=yAxis - yAxis * xAxis/pwmMax; if (xAxis lt; 0)
{= yAxis; (Math.abs (Math.round (e.values ??[0])) gt; xR)=Math.round ((Math.abs (e.values ??[0])-xR) * pwmMax/(xMax-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) bl.sendData (cmdSendL + cmdSendR); textX=(TextView) findViewById (R.id.textViewX); textY=(TextView) findViewById (R.id.textViewY); mLeft=(TextView) findViewById (R.id.mLeft); mRight= (TextView) findViewById (R.id.mRight); textCmdSend=(TextView) findViewById (R.id.textViewCmdSend); (show_Debug)
{. setText (String.valueOf ( X: + String.format (%. 1f , e.values ??[0]) + laquo ;; xPWM: + xAxis)) ;. setText (String.valueOf ( Y: + String.format (%. 1f , e.values ??[1]) + laquo ;; yPWM: + yAxis)). setText (String.valueOf ( MotorL: + directionL + . + motorLeft)). setText (String.valueOf ( MotorR: + directionR + . + motorRight)) ;. setText (String.valueOf ( Send: + cmdSendL.toUpperCase (Locale.getDefault ()) + cmdSendR.toUpperCase (Locale.getDefault ())));
}
{.setText(laquo;raquo;);.setText(laquo;raquo;);.setText(laquo;raquo;);.setText(laquo;raquo;);.setText(laquo;raquo;);
} void loadPref ()
{mySharedPreferences=PreferenceManager.getDefaultSharedPreferences (this);=mySharedPreferences.getString ( pref_MAC_address raquo ;, address);=Integer.parseInt (mySharedPreferences.getString ( pref_xMax raquo ;, String.valueOf (xMax )));=Integer.parseInt (mySharedPreferences.getString ( pref_xR raquo ;, String.valueOf (xR)));=Integer.parseInt (mySharedPreferences.getString ( pref_yMax raquo ;, String.valueOf (yMax))); =Integer.parseInt (mySharedPreferences.getString ( pref_yThreshold raquo ;, String.valueOf (yThreshold)));=Integer.parseInt (mySharedPreferences.getString ( pref_pwmMax raquo ;, String.valueOf (pwmMax))); _ Debug=mySharedPreferences. getBoolean ( pref_Debug raquo ;, false);=mySharedPreferences.getString ( pref_commandLeft raquo ;, commandLeft);=mySharedPreferences.getString ( pref_commandRight raquo ;, commandRight);=mySharedPreferences.getString ( pref_commandHorn raquo ;, commandHorn);
}
@ Overridevoid onResume ()
{. onResume (); _ is_connect=bl.BT_Connect (address, false) ;. registerListener (this, mAccel, SensorManager.SENSOR_DELAY_NORMAL);
}
@ Overridevoid onPause ()
{. onPause () ;. BT_onPause () ;. unregisterListener (this);
}
@ Overridevoid onActivityResult (int requestCode, int resultCode, Intent data)
{(); void onAccuracyChanged (Sensor arg0, int arg1) {}
}.javacom.dum_car;com.dum_car.cBluetooth;com.dum_car.R;java.lang.ref.WeakReference;android.app.Activity;android.bluetooth.BluetoothAdapter;android.content.Intent;android.content.SharedPreferences;android.os.Bundle;android.os.Handler;android.os.Message;android.preference.PreferenceManager;android.util.Log;android.view.View;android.view.View.OnClickListener;android.view.View.OnTouchListener;android.view.MotionEvent;android.widget.Button;android.widget.Toast;android.widget.ToggleButton;class ActivityButtons extends Activity
{cBluetooth bl=null; ToggleButton LightButton; Button btn_forward, btn_backward, btn_left, btn_right; int motorLeft=0; int motorRight=0; String address; int pwmBtnM...