|
|
@@ -7,21 +7,25 @@ import android.os.Bundle;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.text.method.ScrollingMovementMethod;
|
|
|
import android.util.Log;
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
+import android.widget.CompoundButton;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
-import com.slam.bboxblelib.Conversion;
|
|
|
import com.slam.bboxblelib.DataEvent;
|
|
|
import com.slam.bboxblelib.DeviceEvent;
|
|
|
import com.slam.bboxblelib.MainBluetooth;
|
|
|
import com.slam.bboxblelib.Responser;
|
|
|
-import com.slam.bboxblelib.WriteEvent;
|
|
|
-import com.slam.bboxblelib.WriteResponser;
|
|
|
import com.slam.bboxblelib.impl.MainBluetoothImpl;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import android.widget.CheckBox;
|
|
|
+import android.widget.ImageButton;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
|
|
|
public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
|
|
|
@@ -33,11 +37,95 @@ public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
private Button mButtonSend2;
|
|
|
private Button mButtonSend3;
|
|
|
private Button mButtonConnect;
|
|
|
+ private Button mButtonConnect2;
|
|
|
private Button mButtonDisconnect;
|
|
|
+ private Button mButtonDisconnect3;
|
|
|
+ private Button mButtonDisconnect2;
|
|
|
private Button mButtonUpdate;
|
|
|
|
|
|
private TextView textView;
|
|
|
|
|
|
+ private Button mButtonNext1;
|
|
|
+ private Button mButtonNext2;
|
|
|
+
|
|
|
+ /**
|
|
|
+ *检测按钮部分
|
|
|
+ */
|
|
|
+ private CheckBox mCheckBoxX;
|
|
|
+ private CheckBox mCheckBoxY;
|
|
|
+ private CheckBox mCheckBoxZ;
|
|
|
+
|
|
|
+ private Button mButtonX;
|
|
|
+ private Button mButtonX1;
|
|
|
+
|
|
|
+ private Button mButtonY;
|
|
|
+ private Button mButtonY1;
|
|
|
+ private Button mButtonZ;
|
|
|
+ private TextView mTextView2;
|
|
|
+
|
|
|
+
|
|
|
+ private double ax = 1;
|
|
|
+ private double ay = 1;
|
|
|
+ private double az = 1;
|
|
|
+ private double gx = 0;
|
|
|
+ private double gy = 0;
|
|
|
+ private double gz = 0;
|
|
|
+
|
|
|
+ //用于判断加速计的轴向
|
|
|
+ private double consult_ax = 1;
|
|
|
+ private double consult_ay = 1;
|
|
|
+ private double consult_az = -1;
|
|
|
+
|
|
|
+ private double ax_max = 0;
|
|
|
+ private double ay_max = 0;
|
|
|
+ private double az_max = 0;
|
|
|
+ private double allMax = 0;
|
|
|
+
|
|
|
+
|
|
|
+ private Button mButtonGY3;
|
|
|
+ private CheckBox mCheckBoxGY;
|
|
|
+ private boolean mFinishCheck = false;
|
|
|
+ private double gx_max = 0;
|
|
|
+ private double gy_max = 0;
|
|
|
+ private double gz_max = 0;
|
|
|
+ private TextView mTextViewTitle;
|
|
|
+
|
|
|
+ private ImageButton mImageButtonX;
|
|
|
+ private ImageButton mImageButtonY;
|
|
|
+ private ImageButton mImageButtonZ;
|
|
|
+ private ImageView mImageViewX;
|
|
|
+ private ImageView mImageViewY;
|
|
|
+ private ImageView mImageViewZ;
|
|
|
+
|
|
|
+ private RelativeLayout page_1;
|
|
|
+ private RelativeLayout page_2;
|
|
|
+ private RelativeLayout page_3;
|
|
|
+ private ImageView mImageViewPage_1;
|
|
|
+ private ImageView mImageViewPage_2;
|
|
|
+
|
|
|
+ private Toast toastCenter;
|
|
|
+
|
|
|
+ //类型变量
|
|
|
+ private static final int TestAccX = 11;
|
|
|
+ private static final int TestAccY = 12;
|
|
|
+ private static final int TestAccZ = 13;
|
|
|
+ private static final int TestGyroX = 21;
|
|
|
+ private static final int TestGyroY = 22;
|
|
|
+ private static final int TestGyroZ = 23;
|
|
|
+ //当前测试的场景
|
|
|
+ private int currentTest = 0;
|
|
|
+
|
|
|
+ //开始进入页面的时候,选择检测对应轴对应的按钮
|
|
|
+ private CheckBox mCheckBoxAccX;
|
|
|
+ private CheckBox mCheckBoxAccY;
|
|
|
+ private CheckBox mCheckBoxAccZ;
|
|
|
+ private CheckBox mCheckBoxGyroX;
|
|
|
+ private CheckBox mCheckBoxGyroY;
|
|
|
+ private CheckBox mCheckBoxGyroZ;
|
|
|
+ //进入第一个页面
|
|
|
+ private Button mButtonEnter;
|
|
|
+ private LinearLayout mSettingLayout;
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
@@ -63,6 +151,17 @@ public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
|
|
|
mButtonConnect = this.findViewById(R.id.button_connect);
|
|
|
mButtonSend1 = this.findViewById(R.id.button_send1);
|
|
|
+
|
|
|
+ mButtonConnect2 = this.findViewById(R.id.button_connect_1);
|
|
|
+ mButtonConnect2.setOnClickListener(this);
|
|
|
+
|
|
|
+
|
|
|
+ mButtonDisconnect2 = this.findViewById(R.id.button_dis_connect_2);
|
|
|
+ mButtonDisconnect2.setOnClickListener(this);
|
|
|
+ mButtonDisconnect3= this.findViewById(R.id.button_dis_connect_3);
|
|
|
+ mButtonDisconnect3.setOnClickListener(this);
|
|
|
+
|
|
|
+
|
|
|
mButtonConnect.setOnClickListener(this);
|
|
|
mButtonSend1.setOnClickListener(this);
|
|
|
|
|
|
@@ -88,9 +187,19 @@ public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
Log.i(TAG, deviceEvent.getDeviceName());
|
|
|
|
|
|
String _tip = textView.getText().toString();
|
|
|
- _tip += "设备,address:" + deviceEvent.getDeviceAddress() + ",deviceName:" + deviceEvent.getDeviceName() + "\n";
|
|
|
+ _tip += "设备mac-->:" + deviceEvent.getDeviceAddress() + "\n设备名称-->:" + deviceEvent.getDeviceName() + "\n";
|
|
|
textView.setText(_tip);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+ if(code == 20002){
|
|
|
+ onWriteValue("3");
|
|
|
+
|
|
|
+ mButtonX1.setVisibility(View.VISIBLE);
|
|
|
+ mButtonConnect2.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
//todo 返回成功对象信息
|
|
|
//约定处理信息 onSuccess
|
|
|
// {
|
|
|
@@ -121,20 +230,95 @@ public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
|
|
|
// Log.i(TAG, "type =" + dataEvent.getDataType());
|
|
|
String hand = dataEvent.getHand();
|
|
|
- double ax = dataEvent.getAcc().get("ax");
|
|
|
- double ay = dataEvent.getAcc().get("ay");
|
|
|
- double az = dataEvent.getAcc().get("az");
|
|
|
- double gx = dataEvent.getGyro().get("gx");
|
|
|
- double gy = dataEvent.getGyro().get("gy");
|
|
|
- double gz = dataEvent.getGyro().get("gz");
|
|
|
+ ax = dataEvent.getAcc().get("ax");
|
|
|
+ ay = dataEvent.getAcc().get("ay");
|
|
|
+ az = dataEvent.getAcc().get("az");
|
|
|
+ gx = dataEvent.getGyro().get("gx");
|
|
|
+ gy = dataEvent.getGyro().get("gy");
|
|
|
+ gz = dataEvent.getGyro().get("gz");
|
|
|
Integer min = dataEvent.getMin();
|
|
|
Integer s = dataEvent.getS();
|
|
|
Integer ms = dataEvent.getMs();
|
|
|
|
|
|
- textView.setText("hand =" + hand + "\n" +
|
|
|
- "acc = " + String.format("%.2f", ax) + " = " + String.format("%.2f", ay) + " = " + String.format("%.2f", az) +
|
|
|
- "\n gyro = " + String.format("%.2f", gx) + " = " + String.format("%.2f", gy) + " = " + String.format("%.2f", gz) +
|
|
|
- "\n min = " + min + " s= " + s + " ms= " + ms);
|
|
|
+ if(Math.abs(ax)>ax_max)
|
|
|
+ ax_max = Math.abs(ax);
|
|
|
+ if(Math.abs(ay)>ay_max)
|
|
|
+ ay_max = Math.abs(ay);
|
|
|
+ if(Math.abs(az)>az_max)
|
|
|
+ az_max = Math.abs(az);
|
|
|
+
|
|
|
+ allMax =Math.sqrt(ax_max*ax_max + ay_max*ay_max + az_max*az_max);
|
|
|
+
|
|
|
+ if(currentTest == TestGyroX && Math.abs(gx)>100){
|
|
|
+ //右旋转为负数,左旋转为正数
|
|
|
+ if(gx>0){
|
|
|
+ mCheckBoxX.setChecked(true);
|
|
|
+ }else{
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ }
|
|
|
+ gx_max += gx;
|
|
|
+ if(gx_max>200){
|
|
|
+ if(!mFinishCheck && gx_max >20000)
|
|
|
+ {
|
|
|
+ mTextViewTitle.setVisibility(View.GONE);
|
|
|
+ if(mCheckBoxGyroY.isChecked() || mCheckBoxGyroZ.isChecked()){
|
|
|
+ mButtonNext1.setVisibility(View.VISIBLE);
|
|
|
+ }else{
|
|
|
+ mButtonGY3.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ mFinishCheck = true;
|
|
|
+ }
|
|
|
+ mCheckBoxX.setText("逆时针旋转值会持续变大:"+ String.format("%.2f", gx_max));
|
|
|
+ }
|
|
|
+ }else if(currentTest == TestGyroY && Math.abs(gy)>100){
|
|
|
+ //右旋转为正数,左旋转为负数
|
|
|
+ if(gy>0){
|
|
|
+ mCheckBoxX.setChecked(true);
|
|
|
+ }else{
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ }
|
|
|
+ gy_max += gy;
|
|
|
+ if(gy_max>200){
|
|
|
+ if(!mFinishCheck && gy_max >20000)
|
|
|
+ {
|
|
|
+ mTextViewTitle.setVisibility(View.GONE);
|
|
|
+ if(mCheckBoxGyroZ.isChecked()){
|
|
|
+ mButtonNext1.setVisibility(View.VISIBLE);
|
|
|
+ }else{
|
|
|
+ mButtonGY3.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ mFinishCheck = true;
|
|
|
+ }
|
|
|
+ mCheckBoxX.setText("逆时针旋转值会持续变大:"+ String.format("%.2f", gy_max));
|
|
|
+ }
|
|
|
+ }else if(currentTest == TestGyroZ && Math.abs(gz)>100){
|
|
|
+ //右旋转为正数,左旋转为负数
|
|
|
+ if(gz>0){
|
|
|
+ mCheckBoxX.setChecked(true);
|
|
|
+ }else{
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ }
|
|
|
+ gz_max += gz;
|
|
|
+ if(gz_max>200){
|
|
|
+ if(!mFinishCheck && gz_max >20000)
|
|
|
+ {
|
|
|
+ mTextViewTitle.setVisibility(View.GONE);
|
|
|
+ mButtonGY3.setVisibility(View.VISIBLE);
|
|
|
+ mFinishCheck = true;
|
|
|
+ }
|
|
|
+ mCheckBoxX.setText("顺时针旋转值会持续变大:"+ String.format("%.2f", gz_max));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // "hand =" + hand + "\n" +
|
|
|
+ textView.setText("六轴实时数据值:\n"+
|
|
|
+ "加速计acc X= " + String.format("%.2f", ax) + " Y= " + String.format("%.2f", ay) + " Z= " + String.format("%.2f", az) +
|
|
|
+ "\n陀螺仪gyro X= " + String.format("%.2f", gx) + " Y= " + String.format("%.2f", gy) + " Z= " + String.format("%.2f", gz) +
|
|
|
+ "\n运行时间min = " + min + " s= " + s + " ms= " + ms + "\n"+
|
|
|
+ "\n最大的量程加速度:"+
|
|
|
+ "\nx最大值 = " + String.format("%.2f", ax_max) + " y最大值= " + String.format("%.2f", ay_max) + " z最大值= " + String.format("%.2f", az_max) +
|
|
|
+ "\n三个轴最大和加速度 = " + String.format("%.2f", allMax) );
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//todo 此处回调硬件解析的信息
|
|
|
//约定处理信息 onUpdateData
|
|
|
@@ -164,6 +348,125 @@ public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
};
|
|
|
//todo 1.注册一下事件
|
|
|
mainBluetooth.onRegisterEvent(this, responser);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检测按钮部分
|
|
|
+ */
|
|
|
+ //通过id找到按钮
|
|
|
+ mCheckBoxX = (CheckBox) findViewById(R.id.checkBoxX);
|
|
|
+ mCheckBoxY = (CheckBox) findViewById(R.id.checkBoxY);
|
|
|
+ mCheckBoxZ = (CheckBox) findViewById(R.id.checkBoxZ);
|
|
|
+ mButtonX = this.findViewById(R.id.buttonX);
|
|
|
+ mButtonX.setOnClickListener(this);
|
|
|
+ mButtonX1 = this.findViewById(R.id.buttonX_1);
|
|
|
+ mButtonX1.setOnClickListener(this);
|
|
|
+
|
|
|
+ mButtonY = this.findViewById(R.id.buttonY);
|
|
|
+ mButtonY.setOnClickListener(this);
|
|
|
+ mButtonY1 = this.findViewById(R.id.buttonY_1);
|
|
|
+ mButtonY1.setOnClickListener(this);
|
|
|
+ mTextView2 = this.findViewById(R.id.textView_2);
|
|
|
+
|
|
|
+ mButtonZ = this.findViewById(R.id.buttonZ);
|
|
|
+ mButtonZ.setOnClickListener(this);
|
|
|
+ //旋转部分
|
|
|
+ mCheckBoxGY = (CheckBox) findViewById(R.id.checkBoxGY);
|
|
|
+ mCheckBoxGY.setText("逆时针旋转值会持续变大:"+ 0);
|
|
|
+
|
|
|
+ mButtonGY3 = this.findViewById(R.id.buttonX_3);
|
|
|
+ mButtonGY3.setOnClickListener(this);
|
|
|
+
|
|
|
+ mImageButtonX = this.findViewById(R.id.imageButtonX);
|
|
|
+ mImageButtonX.setOnClickListener(this);
|
|
|
+ mImageButtonY = this.findViewById(R.id.imageButtonY);
|
|
|
+ mImageButtonY.setOnClickListener(this);
|
|
|
+ mImageButtonZ = this.findViewById(R.id.imageButtonZ);
|
|
|
+ mImageButtonZ.setOnClickListener(this);
|
|
|
+ mImageViewX = this.findViewById(R.id.imageViewX);
|
|
|
+ mImageViewX.setOnClickListener(this);
|
|
|
+ mImageViewY = this.findViewById(R.id.imageViewY);
|
|
|
+ mImageViewY.setOnClickListener(this);
|
|
|
+ mImageViewZ = this.findViewById(R.id.imageViewZ);
|
|
|
+ mImageViewZ.setOnClickListener(this);
|
|
|
+
|
|
|
+ page_1 = this.findViewById(R.id.page_1);
|
|
|
+ page_2 = this.findViewById(R.id.page_2);
|
|
|
+ page_3 = this.findViewById(R.id.page_3);
|
|
|
+
|
|
|
+ mImageViewPage_1 = this.findViewById(R.id.imageViewX_1);
|
|
|
+ mImageViewPage_2 = this.findViewById(R.id.imageViewX_2);
|
|
|
+
|
|
|
+ toastCenter = Toast.makeText(getApplicationContext(),"正在连接中",Toast.LENGTH_LONG);
|
|
|
+ //setGravity决定Toast显示位置
|
|
|
+ toastCenter.setGravity(Gravity.CENTER,0,0);
|
|
|
+
|
|
|
+
|
|
|
+ mButtonNext1 = this.findViewById(R.id.button_next_1);
|
|
|
+ mButtonNext1.setOnClickListener(this);
|
|
|
+ mButtonNext2 = this.findViewById(R.id.button_next_2);
|
|
|
+ mButtonNext2.setOnClickListener(this);
|
|
|
+
|
|
|
+ //首页选择
|
|
|
+ mCheckBoxAccX = this.findViewById(R.id.checkBoxAccX);
|
|
|
+ mCheckBoxAccY = this.findViewById(R.id.checkBoxAccY);
|
|
|
+ mCheckBoxAccZ = this.findViewById(R.id.checkBoxAccZ);
|
|
|
+ mCheckBoxGyroX = this.findViewById(R.id.checkBoxGyroX);
|
|
|
+ mCheckBoxGyroY = this.findViewById(R.id.checkBoxGyroY);
|
|
|
+ mCheckBoxGyroZ = this.findViewById(R.id.checkBoxGyroZ);
|
|
|
+
|
|
|
+ //lambda 表达式
|
|
|
+ mCheckBoxAccX.setOnCheckedChangeListener((buttonView,isChecked)->{
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ if(isChecked){
|
|
|
+ Log.i(TAG, "mCheckBoxAccX"+isChecked);
|
|
|
+ }else{
|
|
|
+ Log.i(TAG, "mCheckBoxAccX"+isChecked);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mCheckBoxAccY.setOnCheckedChangeListener((buttonView,isChecked)->{
|
|
|
+ if(isChecked){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mCheckBoxAccZ.setOnCheckedChangeListener((buttonView,isChecked)->{
|
|
|
+ if(isChecked){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mCheckBoxGyroX.setOnCheckedChangeListener((buttonView,isChecked)->{
|
|
|
+ if(isChecked){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mCheckBoxGyroY.setOnCheckedChangeListener((buttonView,isChecked)->{
|
|
|
+ if(isChecked){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mCheckBoxGyroZ.setOnCheckedChangeListener((buttonView,isChecked)->{
|
|
|
+ if(isChecked){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 默认设置的3个轴,x,y 。和陀螺仪y
|
|
|
+ */
|
|
|
+ mCheckBoxAccX.setChecked(true);
|
|
|
+ mCheckBoxAccZ.setChecked(true);
|
|
|
+ mCheckBoxGyroX.setChecked(true);
|
|
|
+
|
|
|
+ mButtonEnter = this.findViewById(R.id.button_enter);
|
|
|
+ mButtonEnter.setOnClickListener(this);
|
|
|
+ mSettingLayout = this.findViewById(R.id.SettingLayout);
|
|
|
+
|
|
|
+ mTextViewTitle = this.findViewById(R.id.textView_title);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -176,8 +479,25 @@ public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
switch (view.getId()) {
|
|
|
+ case R.id.button_enter:
|
|
|
+ //判断有什么检测就进什么页面,如果没有给出提示
|
|
|
+ if( mCheckBoxAccX.isChecked() || mCheckBoxAccY.isChecked() || mCheckBoxAccZ.isChecked() ||
|
|
|
+ mCheckBoxGyroX.isChecked() || mCheckBoxGyroY.isChecked() || mCheckBoxGyroZ.isChecked()){
|
|
|
+ //设置page_1页面现在检测什么轴 文案
|
|
|
+ resetTestState();
|
|
|
+ //隐藏选择页面,现在Acc检测页面类型
|
|
|
+ mSettingLayout.setVisibility(View.GONE);
|
|
|
+ page_1.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ toastCenter.setText("请选择一个测试轴");
|
|
|
+ toastCenter.show();
|
|
|
+ }
|
|
|
+ break;
|
|
|
case R.id.button_connect:
|
|
|
+ case R.id.button_connect_1:
|
|
|
onConnect("BGBox");
|
|
|
+ toastCenter.setText("正在连接中");
|
|
|
+ toastCenter.show();
|
|
|
break;
|
|
|
case R.id.button_send1:
|
|
|
onWriteValue("V");
|
|
|
@@ -195,9 +515,161 @@ public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
break;
|
|
|
|
|
|
case R.id.button_dis_connect:
|
|
|
+ case R.id.button_dis_connect_2:
|
|
|
+ case R.id.button_dis_connect_3:
|
|
|
+ case R.id.buttonX_3:
|
|
|
onDisconnect();
|
|
|
break;
|
|
|
+ case R.id.buttonX:
|
|
|
+ case R.id.buttonX_1:
|
|
|
+ //检测的时候,按照类型来
|
|
|
+ double _temp = 1d;
|
|
|
+ String _strSuccess = "" , _strFail = "";
|
|
|
+ if(currentTest == TestAccX){
|
|
|
+ _temp = Math.abs(ax - consult_ax);
|
|
|
+ _strSuccess = "检测X正确,值为:"+String.format("%.2f", ax);
|
|
|
+ _strFail = "检测X不正确,值为:"+String.format("%.2f", ax);
|
|
|
+ }else if(currentTest == TestAccY){
|
|
|
+ _temp = Math.abs(ay - consult_ay);
|
|
|
+ _strSuccess = "检测Y正确,值为:"+String.format("%.2f", ay);
|
|
|
+ _strFail = "检测Y不正确,值为:"+String.format("%.2f", ay);
|
|
|
+ }else if(currentTest == TestAccZ){
|
|
|
+ _temp = Math.abs(az - consult_az);
|
|
|
+ _strSuccess = "检测Z正确,值为:"+String.format("%.2f", az);
|
|
|
+ _strFail = "检测Z不正确,值为:"+String.format("%.2f", az);
|
|
|
+ }
|
|
|
+ if(_temp <0.2f){
|
|
|
+ mCheckBoxX.setChecked(true);
|
|
|
+ mCheckBoxX.setText(_strSuccess);
|
|
|
+ toastCenter.setText("检测成功");
|
|
|
+ toastCenter.show();
|
|
|
+
|
|
|
+ mButtonNext1.setVisibility(View.VISIBLE);
|
|
|
+ mButtonX1.setVisibility(View.GONE);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText(_strFail);
|
|
|
+ }
|
|
|
|
|
|
+ break;
|
|
|
+ case R.id.button_next_1:
|
|
|
+ //点击下一步时候,切换检测坐标
|
|
|
+ if(mCheckBoxAccX.isChecked() && currentTest < TestAccX){
|
|
|
+ mButtonNext1.setVisibility(View.GONE);
|
|
|
+ mButtonX1.setVisibility(View.VISIBLE);
|
|
|
+ currentTest = TestAccX;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测X方向,方向键向上垂直桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.x);
|
|
|
+
|
|
|
+ }else if(mCheckBoxAccY.isChecked() && currentTest < TestAccY){
|
|
|
+ mButtonNext1.setVisibility(View.GONE);
|
|
|
+ mButtonX1.setVisibility(View.VISIBLE);
|
|
|
+ currentTest = TestAccY;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测Y方向,L,R向上垂直桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.y);
|
|
|
+
|
|
|
+ }else if(mCheckBoxAccZ.isChecked() && currentTest < TestAccZ){
|
|
|
+ mButtonNext1.setVisibility(View.GONE);
|
|
|
+ mButtonX1.setVisibility(View.VISIBLE);
|
|
|
+ currentTest = TestAccZ;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测Z方向,AB键向上放置桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.z);
|
|
|
+ }
|
|
|
+ //选择时候,不用显示检测按钮,直接根据旋转判断是否进行下一步
|
|
|
+ else if(mCheckBoxGyroX.isChecked() && currentTest < TestGyroX){
|
|
|
+ currentTest = TestGyroX;
|
|
|
+ mButtonNext1.setVisibility(View.GONE);
|
|
|
+ mTextViewTitle.setVisibility(View.VISIBLE);
|
|
|
+ mTextViewTitle.setText("检测陀螺仪X轴,直到超过20000");
|
|
|
+ mFinishCheck = false;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("方向键向上垂直桌面,逆时针旋转增大!");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.x);
|
|
|
+ }else if(mCheckBoxGyroY.isChecked() && currentTest < TestGyroY){
|
|
|
+ currentTest = TestGyroY;
|
|
|
+ mButtonNext1.setVisibility(View.GONE);
|
|
|
+ mTextViewTitle.setVisibility(View.VISIBLE);
|
|
|
+ mTextViewTitle.setText("检测陀螺仪Y轴,直到超过20000");
|
|
|
+ mFinishCheck = false;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("L,R向上垂直桌面,逆时针旋转增大!");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.y);
|
|
|
+ }else if(mCheckBoxGyroZ.isChecked() && currentTest < TestGyroZ){
|
|
|
+ currentTest = TestGyroZ;
|
|
|
+ mButtonNext1.setVisibility(View.GONE);
|
|
|
+ mTextViewTitle.setVisibility(View.VISIBLE);
|
|
|
+ mTextViewTitle.setText("检测陀螺仪Z轴,直到超过20000");
|
|
|
+ mFinishCheck = false;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("AB键向上放置桌面,顺时针旋转增大!");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.z);
|
|
|
+ }
|
|
|
+
|
|
|
+ //进行下一步
|
|
|
+ //隐藏当前页面
|
|
|
+// page_1.setVisibility(View.INVISIBLE);
|
|
|
+// page_2.setVisibility(View.VISIBLE);
|
|
|
+ break;
|
|
|
+ case R.id.button_next_2:
|
|
|
+ //进行下一步
|
|
|
+ //隐藏当前页面
|
|
|
+ page_2.setVisibility(View.INVISIBLE);
|
|
|
+ page_3.setVisibility(View.VISIBLE);
|
|
|
+ break;
|
|
|
+ case R.id.buttonY:
|
|
|
+ case R.id.buttonY_1:
|
|
|
+ if(Math.abs(ay - consult_ay) <0.2f){
|
|
|
+ mCheckBoxY.setChecked(true);
|
|
|
+ mCheckBoxY.setText("检测Y正确,值为:"+String.format("%.2f", ay));
|
|
|
+ mTextView2.setText("检测Y正确,值为:"+String.format("%.2f", ay));
|
|
|
+
|
|
|
+ toastCenter.setText("检测Y成功");
|
|
|
+ toastCenter.show();
|
|
|
+
|
|
|
+ mButtonDisconnect2.setVisibility(View.GONE);
|
|
|
+ mButtonY1.setVisibility(View.GONE);
|
|
|
+ mButtonNext2.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ mCheckBoxY.setChecked(false);
|
|
|
+ mCheckBoxY.setText("检测Y不正确,值为:"+String.format("%.2f", ay));
|
|
|
+ mTextView2.setText("检测Y不正确,值为:"+String.format("%.2f", ay));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case R.id.buttonZ:
|
|
|
+ if(az - consult_az <0.2f){
|
|
|
+ mCheckBoxZ.setChecked(true);
|
|
|
+ mCheckBoxZ.setText("检测Z正确,值为:"+String.format("%.2f", az));
|
|
|
+ }else{
|
|
|
+ mCheckBoxZ.setChecked(false);
|
|
|
+ mCheckBoxZ.setText("检测Z不正确,值为:"+String.format("%.2f", az));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case R.id.imageButtonX:
|
|
|
+ mImageViewX.setVisibility(mImageViewX.getVisibility() == View.INVISIBLE? View.VISIBLE:View.INVISIBLE);
|
|
|
+ break;
|
|
|
+ case R.id.imageButtonY:
|
|
|
+ mImageViewY.setVisibility(mImageViewY.getVisibility() == View.INVISIBLE? View.VISIBLE:View.INVISIBLE);
|
|
|
+ break;
|
|
|
+ case R.id.imageButtonZ:
|
|
|
+ mImageViewZ.setVisibility(mImageViewZ.getVisibility() == View.INVISIBLE? View.VISIBLE:View.INVISIBLE);
|
|
|
+ break;
|
|
|
+ case R.id.imageViewX:
|
|
|
+ mImageViewX.setVisibility(mImageViewX.getVisibility() == View.INVISIBLE? View.VISIBLE:View.INVISIBLE);
|
|
|
+ break;
|
|
|
+ case R.id.imageViewY:
|
|
|
+ mImageViewY.setVisibility(mImageViewY.getVisibility() == View.INVISIBLE? View.VISIBLE:View.INVISIBLE);
|
|
|
+ break;
|
|
|
+ case R.id.imageViewZ:
|
|
|
+ mImageViewZ.setVisibility(mImageViewZ.getVisibility() == View.INVISIBLE? View.VISIBLE:View.INVISIBLE);
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -227,7 +699,98 @@ public class TestActivity extends Activity implements View.OnClickListener {
|
|
|
* 断开连接
|
|
|
*/
|
|
|
public void onDisconnect() {
|
|
|
+ //重置对应的数据
|
|
|
+ ax = 1;
|
|
|
+ ay = 1;
|
|
|
+ az = 1;
|
|
|
+ gx = 0;
|
|
|
+ gy = 0;
|
|
|
+ gz = 0;
|
|
|
+
|
|
|
+ ax_max = 0;
|
|
|
+ ay_max = 0;
|
|
|
+ az_max = 0;
|
|
|
+ allMax = 0;
|
|
|
+
|
|
|
+
|
|
|
+ gx_max = 0;
|
|
|
+ gy_max = 0;
|
|
|
+ gz_max = 0;
|
|
|
+
|
|
|
+ //返回第一页
|
|
|
+ page_1.setVisibility(View.VISIBLE);
|
|
|
+ page_2.setVisibility(View.INVISIBLE);
|
|
|
+ page_3.setVisibility(View.INVISIBLE);
|
|
|
+
|
|
|
+ //首页按钮
|
|
|
+ mButtonX1.setVisibility(View.GONE);
|
|
|
+ mButtonConnect2.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测x方向,方向键向上");
|
|
|
+ mCheckBoxY.setChecked(false);
|
|
|
+ mCheckBoxY.setText("检测Y方向,L,R键向上");
|
|
|
+ mCheckBoxGY.setChecked(false);
|
|
|
+
|
|
|
+ mFinishCheck = false;
|
|
|
+
|
|
|
+ textView.setText("");
|
|
|
mainBluetooth.disConnectLeDevice();
|
|
|
+
|
|
|
+
|
|
|
+ mButtonConnect.setVisibility(View.VISIBLE);
|
|
|
+ mButtonNext1.setVisibility(View.GONE);
|
|
|
+
|
|
|
+ mButtonDisconnect2.setVisibility(View.VISIBLE);
|
|
|
+ mButtonY1.setVisibility(View.VISIBLE);
|
|
|
+ mButtonNext2.setVisibility(View.GONE);
|
|
|
+
|
|
|
+ mButtonDisconnect3.setVisibility(View.VISIBLE);
|
|
|
+ mButtonGY3.setVisibility(View.GONE);
|
|
|
+ mCheckBoxGY.setText("逆时针旋转值会持续变大:"+ 0);
|
|
|
+
|
|
|
+
|
|
|
+ resetTestState();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void resetTestState(){
|
|
|
+ if(mCheckBoxAccX.isChecked()){
|
|
|
+ currentTest = TestAccX;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测X方向,方向键向上垂直桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.x);
|
|
|
+
|
|
|
+ }else if(mCheckBoxAccY.isChecked()){
|
|
|
+ currentTest = TestAccY;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测Y方向,L,R向上垂直桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.y);
|
|
|
+
|
|
|
+ }else if(mCheckBoxAccZ.isChecked()){
|
|
|
+ currentTest = TestAccZ;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测Z方向,AB键向上放置桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.z);
|
|
|
+
|
|
|
+ }else if(mCheckBoxGyroX.isChecked()){
|
|
|
+ currentTest = TestGyroX;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测X方向,方向键向上垂直桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.x);
|
|
|
+ }else if(mCheckBoxGyroY.isChecked()){
|
|
|
+ currentTest = TestGyroY;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测Y方向,L,R向上垂直桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.y);
|
|
|
+ }else if(mCheckBoxGyroZ.isChecked()){
|
|
|
+ currentTest = TestGyroZ;
|
|
|
+ mCheckBoxX.setChecked(false);
|
|
|
+ mCheckBoxX.setText("检测Z方向,AB键向上放置桌面");
|
|
|
+ mImageViewPage_1.setImageResource(R.drawable.z);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|