|
|
@@ -3,6 +3,7 @@ package com.example.bpa.view.from; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Handler; |
|
|
|
import android.view.View; |
|
|
|
import android.view.Window; |
|
|
|
import android.view.WindowManager; |
|
|
@@ -15,15 +16,19 @@ import android.widget.TextView; |
|
|
|
|
|
|
|
import com.example.bpa.Model.IWriteCallBack; |
|
|
|
import com.example.bpa.R; |
|
|
|
import com.example.bpa.config.ConfigName; |
|
|
|
import com.example.bpa.helper.ActiveMax; |
|
|
|
import com.example.bpa.helper.MessageLog; |
|
|
|
import com.example.bpa.service.DeviceData; |
|
|
|
import com.example.bpa.config.DataBus; |
|
|
|
import com.example.bpa.helper.T; |
|
|
|
import com.example.bpa.view.mode.UserLogEnum; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.locks.Lock; |
|
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
|
|
|
|
|
/** |
|
|
|
* 流速校验 |
|
|
@@ -39,12 +44,12 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList |
|
|
|
*/ |
|
|
|
TextView gongneng_title; |
|
|
|
//通道校准值 |
|
|
|
EditText passwayText_1, passwayText_2, passwayText_3, passwayText_4, passwayText_5, passwayText_6, passwayText_7, passwayText_8, passwayText_9, passwayText_10, passwayText_11, passwayText_12,passwayText_13; |
|
|
|
EditText passwayText_1, passwayText_2, passwayText_3, passwayText_4, passwayText_5, passwayText_6, passwayText_7, passwayText_8, passwayText_9, passwayText_10, passwayText_11, passwayText_12, passwayText_13; |
|
|
|
//校准基准时间 |
|
|
|
EditText timeText; |
|
|
|
List<EditText> editTextLists = new ArrayList<EditText>(); |
|
|
|
//通道校准开关 |
|
|
|
Switch Switch_1, Switch_2, Switch_3, Switch_4, Switch_5, Switch_6, Switch_7, Switch_8, Switch_9, Switch_10, Switch_11, Switch_12,Switch_13; |
|
|
|
Switch Switch_1, Switch_2, Switch_3, Switch_4, Switch_5, Switch_6, Switch_7, Switch_8, Switch_9, Switch_10, Switch_11, Switch_12, Switch_13; |
|
|
|
List<Switch> switchLists = new ArrayList<Switch>(); |
|
|
|
//开始校准 |
|
|
|
Button StartButton; |
|
|
@@ -153,11 +158,11 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList |
|
|
|
try { |
|
|
|
for (int i = 0; i < 13; i++) { |
|
|
|
String s = String.valueOf(DeviceData.Get().getCalibrationValue(i + 1)); |
|
|
|
editTextLists.get(i).setText(String.format ("%.1f", (Double.parseDouble(s)/10))); |
|
|
|
editTextLists.get(i).setText(String.format("%.1f", (Double.parseDouble(s) / 10))); |
|
|
|
} |
|
|
|
String time = String.valueOf(DeviceData.Get().getCalibrationReferenceTime()); |
|
|
|
//校准时间 |
|
|
|
timeText.setText(String.format ("%.1f", (Double.parseDouble(time)/10))); |
|
|
|
timeText.setText(String.format("%.1f", (Double.parseDouble(time) / 10))); |
|
|
|
|
|
|
|
//设置手动模式 |
|
|
|
DeviceData.Get().setHandOrAutoSwitch(false, null); |
|
|
@@ -168,6 +173,7 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList |
|
|
|
//endregion |
|
|
|
|
|
|
|
//region 点击事件 |
|
|
|
private boolean isClicked = false; |
|
|
|
|
|
|
|
/** |
|
|
|
* 本页面点击事件监听 |
|
|
@@ -181,92 +187,146 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList |
|
|
|
this.finish(); |
|
|
|
break; |
|
|
|
case R.id.savetime://校准基准时间保存 |
|
|
|
String stime = timeText.getText().toString(); |
|
|
|
if (stime.equals("")) { |
|
|
|
T.show(lsjy_activity.this, "校准基准时间不能为空!"); |
|
|
|
return; |
|
|
|
} |
|
|
|
int ftime = 0; |
|
|
|
try { |
|
|
|
ftime = (int)Math.round((Double.parseDouble(stime) * 10)); |
|
|
|
} catch (Exception e) { |
|
|
|
T.show(lsjy_activity.this, "校准基准时间异常!" + e.getMessage()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
DeviceData.Get().setCalibrationReferenceTime((short) ftime, new IWriteCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
T.show(lsjy_activity.this, "校准时间写入成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(String ErrorMsg) { |
|
|
|
T.show(lsjy_activity.this, "校准时间写入失败"); |
|
|
|
} |
|
|
|
}); |
|
|
|
// 执行操作 |
|
|
|
if (!isClicked) { |
|
|
|
isClicked = true; |
|
|
|
SaveButton.setEnabled(false); // 禁用按钮防止重复点击 |
|
|
|
|
|
|
|
for (int i = 0; i < 13; i++) { |
|
|
|
if (switchLists.get(i).isChecked() == true)//校准开关打开后,允许校准 |
|
|
|
{ |
|
|
|
String value = editTextLists.get(i).getText().toString(); |
|
|
|
Short val = 0; |
|
|
|
try { |
|
|
|
val =(short)Math.round((Double.parseDouble(value) * 10)); |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
if (val <= 0) { |
|
|
|
T.show(lsjy_activity.this, "请检查[通道" + (i + 1) + "]数值不能小于0"); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//写开关状态 数值 |
|
|
|
for (int i = 0; i < 13; i++) { |
|
|
|
String value = editTextLists.get(i).getText().toString(); |
|
|
|
Short val = 0; |
|
|
|
try { |
|
|
|
val =(short)Math.round((Double.parseDouble(value) * 10)); |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
DeviceData.Get().setCalibrationValue(val, i + 1, new IWriteCallBack() { |
|
|
|
// 在2秒后执行按钮操作 |
|
|
|
new Handler().postDelayed(new Runnable() { |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
} |
|
|
|
public void run() { |
|
|
|
// 执行按钮操作 |
|
|
|
// TODO: 在这里添加你的代码 |
|
|
|
try { |
|
|
|
String stime = timeText.getText().toString(); |
|
|
|
if (stime.equals("")) { |
|
|
|
T.show(lsjy_activity.this, "校准基准时间不能为空!"); |
|
|
|
return; |
|
|
|
} |
|
|
|
int ftime = 0; |
|
|
|
try { |
|
|
|
ftime = (int) Math.round((Double.parseDouble(stime) * 10)); |
|
|
|
} catch (Exception e) { |
|
|
|
T.show(lsjy_activity.this, "校准基准时间异常!" + e.getMessage()); |
|
|
|
return; |
|
|
|
} |
|
|
|
for (int i = 0; i < 13; i++) { |
|
|
|
if (switchLists.get(i).isChecked() == true)//校准开关打开后,允许校准 |
|
|
|
{ |
|
|
|
String value = editTextLists.get(i).getText().toString(); |
|
|
|
Short val = 0; |
|
|
|
try { |
|
|
|
val = (short) Math.round((Double.parseDouble(value) * 10)); |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
if (val <= 0) { |
|
|
|
T.show(lsjy_activity.this, "请检查[通道" + (i + 1) + "]数值不能小于0"); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(String ErrorMsg) { |
|
|
|
DeviceData.Get().setCalibrationReferenceTime((short) ftime, new IWriteCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(String ErrorMsg) { |
|
|
|
} |
|
|
|
}); |
|
|
|
//写开关状态 数值 |
|
|
|
for (int i = 0; i < 13; i++) { |
|
|
|
String value = editTextLists.get(i).getText().toString(); |
|
|
|
Short val = 0; |
|
|
|
try { |
|
|
|
val = (short) Math.round((Double.parseDouble(value) * 10)); |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
|
|
|
|
final boolean[] IsComplete = {false}; |
|
|
|
DeviceData.Get().setCalibrationValue(val, i + 1, new IWriteCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
IsComplete[0] = true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(String ErrorMsg) { |
|
|
|
IsComplete[0] = true; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
long a = System.currentTimeMillis(); |
|
|
|
while (!IsComplete[0]) { |
|
|
|
if ((System.currentTimeMillis() - a) > 1000 * 60) { |
|
|
|
break; |
|
|
|
} |
|
|
|
Thread.sleep(100);//10 *6 |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (WindowManager.BadTokenException ex) { |
|
|
|
MessageLog.ShowInfo("校准保存配置异常:" + ex.getMessage()); |
|
|
|
} catch (InterruptedException ex) { |
|
|
|
MessageLog.ShowInfo("校准保存配置异常:" + ex.getMessage()); |
|
|
|
} |
|
|
|
T.show(lsjy_activity.this, "参数写入成功"); |
|
|
|
|
|
|
|
SaveButton.setEnabled(true); // 恢复按钮状态 |
|
|
|
isClicked = false; // 重置点击状态 |
|
|
|
} |
|
|
|
}); |
|
|
|
}, 2000); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
case R.id.StartButton://开始校准 |
|
|
|
//写开关状态 数值 |
|
|
|
for (int i = 0; i < 13; i++) { |
|
|
|
//1.写入开关状态 |
|
|
|
DeviceData.Get().setChCalibrationSwitch(switchLists.get(i).isChecked(), i + 1, new IWriteCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
} |
|
|
|
if (!isClicked) { |
|
|
|
isClicked = true; |
|
|
|
StartButton.setEnabled(false); // 禁用按钮防止重复点击 |
|
|
|
|
|
|
|
// 在2秒后执行按钮操作 |
|
|
|
new Handler().postDelayed(new Runnable() { |
|
|
|
@Override |
|
|
|
public void onFailure(String ErrorMsg) { |
|
|
|
public void run() { |
|
|
|
// 执行按钮操作 |
|
|
|
// TODO: 在这里添加你的代码 |
|
|
|
try { |
|
|
|
//写开关状态 数值 |
|
|
|
for (int i = 0; i < 13; i++) { |
|
|
|
//1.写入开关状态 |
|
|
|
DeviceData.Get().setChCalibrationSwitch(switchLists.get(i).isChecked(), i + 1, new IWriteCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(String ErrorMsg) { |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
//写开始校准 |
|
|
|
DeviceData.Get().setChStartCalibration(new IWriteCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
T.show(lsjy_activity.this, "通道开始校准"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(String ErrorMsg) { |
|
|
|
T.show(lsjy_activity.this, "通道开始校准失败"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} catch (Exception ex) { |
|
|
|
MessageLog.ShowInfo("开始校准异常:" + ex.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StartButton.setEnabled(true); // 恢复按钮状态 |
|
|
|
isClicked = false; // 重置点击状态 |
|
|
|
} |
|
|
|
}); |
|
|
|
}, 2000); |
|
|
|
} |
|
|
|
//写开始校准 |
|
|
|
DeviceData.Get().setChStartCalibration(new IWriteCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
T.show(lsjy_activity.this, "通道开始校准"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(String ErrorMsg) { |
|
|
|
T.show(lsjy_activity.this, "通道开始校准失败"); |
|
|
|
} |
|
|
|
}); |
|
|
|
break; |
|
|
|
case R.id.ClearText://清空称重重量 |
|
|
|
DeviceData.Get().setWeightClear(new IWriteCallBack() { |
|
|
@@ -300,9 +360,9 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
try { |
|
|
|
zhongliang.setText(String.valueOf(DeviceData.Get().getCallCurrentWeight(1)/10.0)+" g"); |
|
|
|
zhongliang.setText(String.valueOf(DeviceData.Get().getCallCurrentWeight(1) / 10.0) + " g"); |
|
|
|
} catch (Exception e) { |
|
|
|
MessageLog.ShowInfo("重量解析显示异常!"+e.getMessage()); |
|
|
|
MessageLog.ShowInfo("重量解析显示异常!" + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|