From 09c54e2bfa51aa9800f224fda7ad3754b353bfed Mon Sep 17 00:00:00 2001
From: zhuguifei <zhuguifei@zhuguifeideiMac.local>
Date: 星期三, 14 一月 2026 08:43:21 +0800
Subject: [PATCH] 功能调整
---
app/src/main/java/com/shlb/comb/activity/ParameterSettingActivity.java | 429 +++++++++++----
app/src/main/res/mipmap-xhdpi/ic_launcher.png | 0
app/src/main/res/mipmap-xxhdpi/ic_launcher.png | 0
app/src/main/res/mipmap-xhdpi/icon_3.png | 0
app/src/main/res/values-land/dimens.xml | 2
app/src/main/java/com/shlb/comb/activity/HomeActivity.java | 50 +
app/src/main/res/layout/activity_system_settings.xml | 22
app/src/main/res/layout/activity_parameter_setting.xml | 97 +-
app/src/main/res/mipmap-xhdpi/icon_4.png | 0
app/src/main/java/com/shlb/comb/fragment/SettingsFragment.java | 475 +++++++++++++++---
app/src/main/res/values-w1240dp/dimens.xml | 2
app/src/main/res/layout/fragment_settings.xml | 274 +++++-----
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png | 0
app/src/main/res/mipmap-xhdpi/icon_5.png | 0
app/src/main/java/com/shlb/comb/fragment/DeviceListFragment.java | 2
app/src/main/res/mipmap-mdpi/ic_launcher.png | 0
app/src/main/AndroidManifest.xml | 2
app/src/main/res/mipmap-xhdpi/icon_1.png | 0
app/src/main/res/mipmap-hdpi/ic_launcher.png | 0
app/src/main/java/com/shlb/comb/activity/SystemSettingsActivity.java | 86 +++
app/src/main/res/mipmap-xhdpi/icon_2.png | 0
app/src/main/java/com/shlb/comb/activity/AdvancedSettingActivity.java | 30 +
app/src/main/res/mipmap-xhdpi/icon_6.png | 0
app/src/main/res/layout/activity_home.xml | 67 +-
app/src/main/res/values-w600dp/dimens.xml | 2
app/src/main/res/drawable/ic_arrow_drop_down.xml | 10
26 files changed, 1,132 insertions(+), 418 deletions(-)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 855e47c..db0467a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -55,6 +55,8 @@
/>
<activity android:name=".activity.TestActivity"
android:screenOrientation="portrait" />
+ <activity android:name=".activity.SystemSettingsActivity"
+ android:screenOrientation="portrait" />
</application>
diff --git a/app/src/main/java/com/shlb/comb/activity/AdvancedSettingActivity.java b/app/src/main/java/com/shlb/comb/activity/AdvancedSettingActivity.java
index b61f980..2abfc59 100644
--- a/app/src/main/java/com/shlb/comb/activity/AdvancedSettingActivity.java
+++ b/app/src/main/java/com/shlb/comb/activity/AdvancedSettingActivity.java
@@ -37,6 +37,8 @@
private TextView tv_sensor_status;
private StringBuilder logBuilder = new StringBuilder();
private String currentExecutingCmd = "";
+ private View currentOperatingButton;
+
@Override
protected void contentView() {
@@ -96,18 +98,26 @@
int id = v.getId();
String action = "";
if (id == R.id.btn_mainboard_read) {
+ currentOperatingButton = btn_mainboard_read;
+ updateButtonState(currentOperatingButton, false);
action = "璇诲彇涓绘澘鐗堟湰";
currentExecutingCmd = CMD.READ_BOARD_VERSION;
sendCmdWithCrc(CMD.READ_BOARD_VERSION);
} else if (id == R.id.btn_display_read) {
+ currentOperatingButton = btn_display_read;
+ updateButtonState(currentOperatingButton, false);
action = "璇诲彇浼犳劅鍣ㄧ増鏈�";
currentExecutingCmd = CMD.READ_SENSOR_VERSION;
sendCmdWithCrc(CMD.READ_SENSOR_VERSION);
} else if (id == R.id.btn_start_addressing) {
+ currentOperatingButton = btn_start_addressing;
+ updateButtonState(currentOperatingButton, false);
action = "寮�濮嬬紪鍧�";
currentExecutingCmd = CMD.WRITE_START_ADDRESS;
sendCmdWithCrc(CMD.WRITE_START_ADDRESS);
} else if (id == R.id.btn_end_addressing) {
+ currentOperatingButton = btn_end_addressing;
+ updateButtonState(currentOperatingButton, false);
action = "缁撴潫缂栧潃";
currentExecutingCmd = CMD.WRITE_END_ADDRESS;
sendCmdWithCrc(CMD.WRITE_END_ADDRESS);
@@ -265,6 +275,24 @@
}
}
+ private void updateButtonState(View btn, boolean enable) {
+ if (btn == null) return;
+ btn.setEnabled(enable);
+ if (enable) {
+ btn.getBackground().clearColorFilter();
+ } else {
+ btn.getBackground().setColorFilter(android.graphics.Color.GRAY, android.graphics.PorterDuff.Mode.MULTIPLY);
+ }
+ }
+
+ private void restoreCurrentButton() {
+ if (currentOperatingButton != null) {
+ updateButtonState(currentOperatingButton, true);
+ currentOperatingButton = null;
+ }
+ }
+
+
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(UpdateEvent event) {
if (event.getType() == UpdateEvent.Type.CONN_STATU) {
@@ -284,12 +312,14 @@
// 鍐欏叆鎸囦护鐨勮繑鍥� (A55A06寮�澶�)
if (hex.startsWith("A55A06") && hex.length() >= 12) {
+ restoreCurrentButton();
parseWriteResponse(hex);
return;
}
// 璇诲彇鎸囦护鐨勮繑鍥� (A55A03寮�澶�)
if (hex.startsWith("A55A03") && hex.length() >= 8) {
+ restoreCurrentButton();
parseReadResponse(hex);
}
}
diff --git a/app/src/main/java/com/shlb/comb/activity/HomeActivity.java b/app/src/main/java/com/shlb/comb/activity/HomeActivity.java
index 6be9c20..02048a4 100644
--- a/app/src/main/java/com/shlb/comb/activity/HomeActivity.java
+++ b/app/src/main/java/com/shlb/comb/activity/HomeActivity.java
@@ -121,7 +121,7 @@
}
});
}
- if (iv_right != null) iv_right.setVisibility(View.VISIBLE);
+ if (iv_right != null) iv_right.setVisibility(View.GONE);
}
});
@@ -176,14 +176,37 @@
});
// 楂樼骇璁剧疆
- findViewById(R.id.menu_advanced_settings).setOnClickListener(v -> {
+ View menuAdvancedSettings = findViewById(R.id.menu_advanced_settings);
+ menuAdvancedSettings.setVisibility(View.GONE);
+ menuAdvancedSettings.setOnClickListener(v -> {
drawerLayout.closeDrawer(GravityCompat.START);
startActivity(new Intent(this, AdvancedSettingActivity.class));
+ });
+
+ // 绯荤粺璁剧疆
+ View menuSystemSettings = findViewById(R.id.menu_system_settings);
+ menuSystemSettings.setVisibility(View.GONE);
+ menuSystemSettings.setOnClickListener(v -> {
+ drawerLayout.closeDrawer(GravityCompat.START);
+ startActivity(new Intent(this, SystemSettingsActivity.class));
+ });
+
+ // 椤堕儴comb鐐瑰嚮浜嬩欢
+ findViewById(R.id.tv_menu_title).setOnClickListener(new View.OnClickListener() {
+ long lastClickTime = 0;
+ @Override
+ public void onClick(View v) {
+ long currentTime = System.currentTimeMillis();
+ if (currentTime - lastClickTime < 500) {
+ showPasswordDialog();
+ }
+ lastClickTime = currentTime;
+ }
});
}
private void updateDrawerSelection(int selectedId) {
- int[] menuIds = {R.id.menu_monitor, R.id.menu_devices, R.id.menu_current_device, R.id.menu_settings, R.id.menu_advanced_settings};
+ int[] menuIds = {R.id.menu_monitor, R.id.menu_devices, R.id.menu_current_device, R.id.menu_settings, R.id.menu_advanced_settings, R.id.menu_system_settings};
for (int id : menuIds) {
View view = findViewById(id);
if (view != null) {
@@ -237,7 +260,7 @@
}
});
}
- if (iv_right != null) iv_right.setVisibility(View.VISIBLE);
+ if (iv_right != null) iv_right.setVisibility(View.GONE);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (deviceListFragment == null) {
@@ -352,4 +375,23 @@
finish();
}
}
+ private void showPasswordDialog() {
+ final QMUIDialog.EditTextDialogBuilder builder = new QMUIDialog.EditTextDialogBuilder(this);
+ builder.setTitle("璇疯緭鍏ュ瘑鐮�")
+ .setPlaceholder("璇疯緭鍏ュ瘑鐮�")
+ .setInputType(android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD)
+ .addAction("鍙栨秷", (dialog, index) -> dialog.dismiss())
+ .addAction("纭畾", (dialog, index) -> {
+ String text = builder.getEditText().getText().toString();
+ if ("0880".equals(text)) {
+ findViewById(R.id.menu_advanced_settings).setVisibility(View.VISIBLE);
+ findViewById(R.id.menu_system_settings).setVisibility(View.VISIBLE);
+ Toast("宸叉樉绀洪殣钘忚缃�");
+ dialog.dismiss();
+ } else {
+ Toast("瀵嗙爜閿欒");
+ }
+ })
+ .create(com.qmuiteam.qmui.R.style.QMUI_Dialog).show();
+ }
}
diff --git a/app/src/main/java/com/shlb/comb/activity/ParameterSettingActivity.java b/app/src/main/java/com/shlb/comb/activity/ParameterSettingActivity.java
index 1d68133..eab9635 100644
--- a/app/src/main/java/com/shlb/comb/activity/ParameterSettingActivity.java
+++ b/app/src/main/java/com/shlb/comb/activity/ParameterSettingActivity.java
@@ -36,35 +36,43 @@
public class ParameterSettingActivity extends BaseActivity {
+ // 闃堝�艰瀹氱浉鍏虫帶浠�
private Spinner sp_threshold_mode;
private EditText et_threshold_value;
- private Button btn_threshold_read;
+
private Button btn_threshold_write;
+ // 鐏垫晱搴﹁瀹氱浉鍏虫帶浠�
private Spinner sp_sensitivity_mode;
private EditText et_sensitivity_value;
- private Button btn_sensitivity_read;
+
private Button btn_sensitivity_write;
+ // 鑷鍜屽浣嶆寜閽�
private Button btn_start_check;
private Button btn_end_check;
private Button btn_reset_mainboard;
private Button btn_reset_sensor;
+ // 鏃ュ織鍜岀姸鎬佹樉绀�
private TextView tv_log;
private TextView tv_right_text;
+ private androidx.cardview.widget.CardView cvLog;
- // New components
+ // 鑷鐩戞祴缃戞牸鍜屾棩蹇楁帶浠�
private RecyclerView rvGrid;
private QMUIRoundButton btnReadData;
private QMUIRoundButton btnClearLog;
private ScrollView svLog;
+ // 鏁版嵁鐩稿叧
private GridAdapter mAdapter;
private List<BoxStatus> boxStatusList = new ArrayList<>();
private StringBuilder logBuilder = new StringBuilder();
- private boolean isSelfCheckMode = false;
- private String pendingSettingCmd = "";
+ private boolean isSelfCheckMode = false; // 鏍囪褰撳墠鏄惁澶勪簬鑷妯″紡
+ private String pendingSettingCmd = ""; // 璁板綍寰呭鐞嗙殑璁惧畾鎸囦护
+ private Button currentOperatingButton; // 褰撳墠姝e湪鎿嶄綔鐨勬寜閽�
+ private String pendingToastMessage = null; // 寰呮樉绀虹殑Toast娑堟伅
private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
@@ -85,12 +93,12 @@
sp_threshold_mode = findViewById(R.id.sp_threshold_mode);
et_threshold_value = findViewById(R.id.et_threshold_value);
- btn_threshold_read = findViewById(R.id.btn_threshold_read);
+
btn_threshold_write = findViewById(R.id.btn_threshold_write);
sp_sensitivity_mode = findViewById(R.id.sp_sensitivity_mode);
et_sensitivity_value = findViewById(R.id.et_sensitivity_value);
- btn_sensitivity_read = findViewById(R.id.btn_sensitivity_read);
+
btn_sensitivity_write = findViewById(R.id.btn_sensitivity_write);
btn_start_check = findViewById(R.id.btn_start_check);
@@ -99,15 +107,15 @@
btn_reset_sensor = findViewById(R.id.btn_reset_sensor);
tv_log = findViewById(R.id.tv_log);
+ cvLog = findViewById(R.id.cv_log);
tv_right_text = findViewById(R.id.tv_right_text);
- // Init new components
+ // 鍒濆鍖栬嚜妫�鐩戞祴鐩稿叧鎺т欢
rvGrid = findViewById(R.id.rv_grid);
- // btnReadData was removed from layout
btnClearLog = findViewById(R.id.btn_clear_log);
svLog = findViewById(R.id.sv_log);
- // Log setup
+ // 璁剧疆鏃ュ織婊氬姩瑙嗗浘鐨勮Е鎽哥洃鍚紝闃叉婊戝姩鍐茬獊
if (svLog != null) {
svLog.setOnTouchListener((v, event) -> {
v.getParent().requestDisallowInterceptTouchEvent(true);
@@ -118,6 +126,7 @@
});
}
+ // 鍒濆鍖栨棩蹇楀唴瀹�
if (logBuilder.length() > 0) {
tv_log.setText(Html.fromHtml(logBuilder.toString()));
} else {
@@ -130,25 +139,36 @@
protected void initData() {
updateBluetoothStatus();
- // Initialize box status list
+ // 鍒濆鍖�30涓牸瀛愮殑鐘舵�佸垪琛�
boxStatusList.clear();
for (int i = 1; i <= 30; i++) {
boxStatusList.add(new BoxStatus(i));
}
- // Grid Setup
+ // 璁剧疆缃戞牸甯冨眬锛�3琛�10鍒�
rvGrid.setLayoutManager(new GridLayoutManager(this, 10));
mAdapter = new GridAdapter();
rvGrid.setAdapter(mAdapter);
+ // 濡傛灉钃濈墮宸茶繛鎺ワ紝杩涘叆璁惧畾妯″紡
if (BleGlobalManager.getInstance().isConnected()) {
sendCmdWithCrc(CMD.ENTER_SETTING);
- // sendCmdWithCrc(CMD.READ_DATA);
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ // 鏍规嵁绯荤粺璁剧疆鎺у埗鏃ュ織鏄剧ず
+ boolean isCmdLogEnabled = com.blankj.utilcode.util.SPUtils.getInstance().getBoolean("cmd_log_enabled", false);
+ if (cvLog != null) {
+ cvLog.setVisibility(isCmdLogEnabled ? View.VISIBLE : View.GONE);
}
}
@Override
protected void onDestroy() {
+ // 椤甸潰閿�姣佹椂閫�鍑鸿瀹氭ā寮�
if (BleGlobalManager.getInstance().isConnected()) {
sendCmdWithCrc(CMD.EXIT_SETTING);
}
@@ -162,27 +182,37 @@
public void onClick(View v) {
int id = v.getId();
String action = "";
- if (id == R.id.btn_threshold_read) {
- action = "璇诲彇闃堝��";
- Toast.makeText(ParameterSettingActivity.this, "璇ュ姛鑳芥殏鏈紑鏀�", Toast.LENGTH_SHORT).show();
- } else if (id == R.id.btn_threshold_write) {
+ if (id == R.id.btn_threshold_write) {
handleThresholdWrite();
- } else if (id == R.id.btn_sensitivity_read) {
- action = "璇诲彇鐏垫晱搴�";
- Toast.makeText(ParameterSettingActivity.this, "璇ュ姛鑳芥殏鏈紑鏀�", Toast.LENGTH_SHORT).show();
} else if (id == R.id.btn_sensitivity_write) {
handleSensitivityWrite();
} else if (id == R.id.btn_start_check) {
- action = "寮�濮嬭嚜妫�";
- sendCmdWithCrc(CMD.WRITE_START_CHECK);
- isSelfCheckMode = true;
+ if (BleGlobalManager.getInstance().isConnected()) {
+ currentOperatingButton = btn_start_check;
+ updateButtonState(currentOperatingButton, false);
+ action = "寮�濮嬭嚜妫�";
+ setAllGridGray();
+ sendCmdWithCrc(CMD.WRITE_START_CHECK);
+ isSelfCheckMode = true;
+ } else {
+ Toast.makeText(ParameterSettingActivity.this, "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
+ }
} else if (id == R.id.btn_end_check) {
- action = "缁撴潫鑷";
- sendCmdWithCrc(CMD.WRITE_END_CHECK);
- isSelfCheckMode = false;
+ if (BleGlobalManager.getInstance().isConnected()) {
+ currentOperatingButton = btn_end_check;
+ updateButtonState(currentOperatingButton, false);
+ action = "缁撴潫鑷";
+ setAllGridGray();
+ sendCmdWithCrc(CMD.WRITE_END_CHECK);
+ isSelfCheckMode = false;
+ } else {
+ Toast.makeText(ParameterSettingActivity.this, "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
+ }
} else if (id == R.id.btn_reset_mainboard) {
+ currentOperatingButton = btn_reset_mainboard;
showResetConfirmDialog("纭畾瑕佹墽琛屼富鏉垮浣嶅悧锛�", CMD.WRITE_BOARD_RESET);
} else if (id == R.id.btn_reset_sensor) {
+ currentOperatingButton = btn_reset_sensor;
showResetConfirmDialog("纭畾瑕佹墽琛屼紶鎰熷櫒澶嶄綅鍚楋紵", CMD.WRITE_SENSOR_RESET);
}
@@ -193,14 +223,59 @@
}
};
- btn_threshold_read.setOnClickListener(listener);
+
btn_threshold_write.setOnClickListener(listener);
- btn_sensitivity_read.setOnClickListener(listener);
+
btn_sensitivity_write.setOnClickListener(listener);
btn_start_check.setOnClickListener(listener);
btn_end_check.setOnClickListener(listener);
btn_reset_mainboard.setOnClickListener(listener);
btn_reset_sensor.setOnClickListener(listener);
+
+ // 闃堝�兼ā寮忛�夋嫨鐩戝惉锛屾帶鍒惰緭鍏ユ鏄惁鍙敤
+ sp_threshold_mode.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
+ if (position == 0) {
+ // 涓�閿瀹氾紝闅愯棌杈撳叆妗� (浣跨敤INVISIBLE淇濈暀鍗犱綅锛岄槻姝㈡寜閽Щ浣�)
+ et_threshold_value.setVisibility(View.INVISIBLE);
+ et_threshold_value.setText("");
+ } else {
+ // 鍗曞眰璁惧畾锛屾樉绀鸿緭鍏ユ
+ et_threshold_value.setVisibility(View.VISIBLE);
+ int maxLayer = com.blankj.utilcode.util.SPUtils.getInstance().getInt("layer_count", 30);
+ et_threshold_value.setHint("1-" + maxLayer);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(android.widget.AdapterView<?> parent) {
+ }
+ });
+
+
+
+ // 鐏垫晱搴︽ā寮忛�夋嫨鐩戝惉锛屾帶鍒惰緭鍏ユ鏄惁鍙敤
+ sp_sensitivity_mode.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
+ // 0: 鎵归噺澧炲姞, 1: 鎵归噺鍑忓皯, 2: 鍗曞眰澧炲姞, 3: 鍗曞眰鍑忓皯
+ if (position == 0 || position == 1) {
+ // 鎵归噺鎿嶄綔锛岄殣钘忚緭鍏ユ
+ et_sensitivity_value.setVisibility(View.INVISIBLE);
+ et_sensitivity_value.setText("");
+ } else {
+ // 鍗曞眰鎿嶄綔锛屾樉绀鸿緭鍏ユ
+ et_sensitivity_value.setVisibility(View.VISIBLE);
+ int maxLayer = com.blankj.utilcode.util.SPUtils.getInstance().getInt("layer_count", 30);
+ et_sensitivity_value.setHint("1-" + maxLayer);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(android.widget.AdapterView<?> parent) {
+ }
+ });
btnClearLog.setOnClickListener(v -> {
logBuilder.setLength(0);
@@ -212,7 +287,7 @@
private String getCmdDescription(String hex, Boolean isSent) {
if (hex == null) return "";
- // Special handling for 3B (Enter/Exit Setting)
+ // 杩涘叆/閫�鍑鸿瀹氭ā寮忔寚浠ょ壒娈婂鐞�
if (hex.startsWith(CMD.ENTER_SETTING.substring(0, 8))) {
if (hex.startsWith(CMD.ENTER_SETTING)) return "-杩涘叆璁惧畾";
if (hex.startsWith(CMD.EXIT_SETTING)) return "-閫�鍑鸿瀹�";
@@ -249,7 +324,7 @@
String displayMsg = msg;
String cmdDesc = "";
- // 濡傛灉鏄� hex 鎸囦护 (绾� 0-9 A-F a-f)锛屽姞绌烘牸鏍煎紡鍖�
+ // 濡傛灉鏄崄鍏繘鍒舵寚浠わ紝姣忎袱浣嶅姞涓�涓┖鏍兼牸寮忓寲鏄剧ず
if (msg.matches("^[0-9A-Fa-f]+$")) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < msg.length(); i += 2) {
@@ -267,8 +342,8 @@
String logLine;
if (isSent != null) {
- String color = isSent ? "#1890ff" : "#05aa87"; // Blue for sent, Green for received
- // 鎷兼帴鍒板墠缂�鍚庨潰: "鍙戦��-璇荤珯鍙�: " 鎴� "鏀跺埌-璇荤珯鍙�: "
+ // 鍙戦�佹寚浠ょ敤钃濊壊锛屾帴鏀舵暟鎹敤缁胯壊
+ String color = isSent ? "#1890ff" : "#05aa87";
String prefix = (isSent ? "鍙戦��" : "鏀跺埌") + cmdDesc + ": ";
logLine = time + " <font color='" + color + "'>" + prefix + displayMsg + "</font><br>";
} else {
@@ -278,7 +353,7 @@
logBuilder.append(logLine);
- // Update UI
+ // 鏇存柊鏃ュ織鏄剧ず骞惰嚜鍔ㄦ粴鍔ㄥ埌搴曢儴
if (tv_log != null) {
tv_log.setText(Html.fromHtml(logBuilder.toString()));
if (svLog != null) {
@@ -287,7 +362,7 @@
}
}
- // Kept for backward compatibility if needed, but redirected to appendLog
+ // 鍏煎鏃т唬鐮佺殑鏃ュ織鏂规硶
private void addLog(String message) {
appendLog(message);
}
@@ -298,7 +373,7 @@
updateBluetoothStatus();
} else if (event.getType() == UpdateEvent.Type.DEVICE_INFO) {
String hex = event.getMsg();
- appendLog(hex, false); // false for received (Green)
+ appendLog(hex, false); // false琛ㄧず鎺ユ敹鐨勬暟鎹紝鏄剧ず涓虹豢鑹�
parseAndRefresh(hex);
}
}
@@ -306,11 +381,13 @@
private void parseAndRefresh(String hex) {
if (hex == null) return;
- // 鍐欏叆鎸囦护鐨勮繑鍥� (A55A06寮�澶�)
- if (hex.startsWith("A55A06") && hex.length() >= 12) {
+ // 澶勭悊鍐欏叆鎸囦护鐨勮繑鍥烇紙A55A06寮�澶达級
+ if (hex.startsWith(CMD.WRITE_SUFFIX) && hex.length() >= 12) {
+ // 鎻愬彇鐘舵�佸瓧鑺傦紝01琛ㄧず鎴愬姛
String statusHex = hex.substring(10, 12);
boolean isSuccess = "01".equals(statusHex);
+ // 澶勭悊杩涘叆璁惧畾妯″紡鐨勮繑鍥�
if (hex.startsWith(CMD.ENTER_SETTING.substring(0, 8))) {
if (isSuccess) {
appendLog("杩涘叆璁惧畾妯″紡鎴愬姛");
@@ -320,57 +397,108 @@
return;
}
+ // 澶勭悊閫�鍑鸿瀹氭ā寮忕殑杩斿洖
if (hex.startsWith(CMD.EXIT_SETTING.substring(0, 8))) {
appendLog("閫�鍑鸿瀹氭ā寮忔垚鍔�");
return;
}
+ // 澶勭悊闃堝�艰瀹氱殑杩斿洖
if (hex.startsWith(CMD.WRITE_THRESHOLD_SETTING.substring(0, 8))) {
if (isSuccess) {
appendLog("闃堝�煎啓鍏ユ垚鍔�");
- Toast.makeText(this, "闃堝�煎啓鍏ユ垚鍔�", Toast.LENGTH_SHORT).show();
+ pendingToastMessage = "闃堝�煎啓鍏ユ垚鍔�";
+ // 闃堝�煎啓鍏ユ垚鍔熷悗锛岀瓑寰�500姣鍐嶈鍙栨暟鎹�
+ appendLog("500姣鍚庤鍙栭槇鍊艰瀹氱粨鏋�...");
+ new android.os.Handler().postDelayed(() -> {
+ sendCmdWithCrc(CMD.READ_DATA);
+ }, 500);
} else {
+ restoreCurrentButton();
appendLog("闃堝�煎啓鍏ュけ璐�");
Toast.makeText(this, "闃堝�煎啓鍏ュけ璐�", Toast.LENGTH_SHORT).show();
}
} else if (hex.startsWith(CMD.WRITE_SENSITIVITY_SETTING.substring(0, 8))) {
+ // 澶勭悊鐏垫晱搴﹁瀹氱殑杩斿洖
if (isSuccess) {
appendLog("鐏垫晱搴﹀啓鍏ユ垚鍔�");
- Toast.makeText(this, "鐏垫晱搴﹀啓鍏ユ垚鍔�", Toast.LENGTH_SHORT).show();
+ pendingToastMessage = "鐏垫晱搴﹀啓鍏ユ垚鍔�";
+ // 鐏垫晱搴﹀啓鍏ユ垚鍔熷悗锛岀瓑寰�500姣鍐嶈鍙栨暟鎹�
+ appendLog("500姣鍚庤鍙栫伒鏁忓害璁惧畾缁撴灉...");
+ new android.os.Handler().postDelayed(() -> {
+ sendCmdWithCrc(CMD.READ_DATA);
+ }, 500);
} else {
+ restoreCurrentButton();
appendLog("鐏垫晱搴﹀啓鍏ュけ璐�");
Toast.makeText(this, "鐏垫晱搴﹀啓鍏ュけ璐�", Toast.LENGTH_SHORT).show();
}
- } else if (hex.startsWith(CMD.WRITE_BOARD_RESET.substring(0, 8))) {
+ } else if (hex.startsWith(CMD.WRITE_BOARD_RESET.substring(0, 8))) {
+ // 澶勭悊涓绘澘/浼犳劅鍣ㄥ浣嶇殑杩斿洖
+ // 鍒ゆ柇鏄富鏉垮浣嶈繕鏄紶鎰熷櫒澶嶄綅
boolean isBoardReset = pendingSettingCmd.equals(CMD.WRITE_BOARD_RESET);
String name = isBoardReset ? "涓绘澘澶嶄綅" : "浼犳劅鍣ㄥ浣�";
if (isSuccess) {
appendLog(name + "鎴愬姛");
- Toast.makeText(this, name + "鎴愬姛", Toast.LENGTH_SHORT).show();
+
+ // 濡傛灉鏄富鏉垮浣嶆垚鍔燂紝鎻愮ず鍗冲皢杩斿洖骞惰烦杞埌瀹炴椂鐩戞帶椤甸潰
+ if (isBoardReset) {
+ Toast.makeText(this, "澶嶄綅鎴愬姛鍗冲皢杩斿洖", Toast.LENGTH_SHORT).show();
+ appendLog("澶嶄綅鎴愬姛锛�2绉掑悗杩斿洖瀹炴椂鐩戞帶椤甸潰...");
+
+ // 2绉掑悗杩斿洖鍒板疄鏃剁洃鎺ч〉闈�
+ new android.os.Handler().postDelayed(() -> {
+ finish(); // 鍏抽棴褰撳墠椤甸潰锛岃繑鍥炲埌瀹炴椂鐩戞帶椤甸潰
+ }, 2000);
+ } else {
+ // 浼犳劅鍣ㄥ浣嶆垚鍔燂紝鎻愮ず骞跺湪500姣鍚庤鍙栨暟鎹�
+ Toast.makeText(this, name + "鎴愬姛", Toast.LENGTH_SHORT).show();
+
+ // 500姣鍚庤鍙栨暟鎹紝閫氳繃鐜版湁鐨刾arseSelfCheckData瑙f瀽
+ new android.os.Handler().postDelayed(() -> {
+ sendCmdWithCrc(CMD.READ_DATA);
+ }, 500);
+ }
} else {
+ restoreCurrentButton();
appendLog(name + "澶辫触");
Toast.makeText(this, name + "澶辫触", Toast.LENGTH_SHORT).show();
}
}
}
- // Check for Self Check command response
+ // 澶勭悊鑷鎸囦护鐨勮繑鍥炵粨鏋�
+ // 寮�濮嬭嚜妫�鍜岀粨鏉熻嚜妫�鐨勬寚浠ゅ墠缂�鐩稿悓锛岄兘鏄� CMD.WRITE_START_CHECK 鐨勫墠8浣�
if (hex.startsWith(CMD.WRITE_START_CHECK.substring(0, 8)) && hex.length() >= 12) {
+ // 鎻愬彇鐘舵�佸瓧鑺傦紙绗�11-12浣嶏級锛�01琛ㄧず鎴愬姛锛屽叾浠栬〃绀哄け璐�
String statusHex = hex.substring(10, 12);
boolean isSuccess = "01".equals(statusHex);
+ // 鏍规嵁褰撳墠妯″紡鍒ゆ柇鎿嶄綔鍚嶇О
String opName = isSelfCheckMode ? "寮�濮嬭嚜妫�" : "缁撴潫鑷";
if (isSuccess) {
appendLog(opName + "鎴愬姛");
- Toast.makeText(this, opName + "鎴愬姛", Toast.LENGTH_SHORT).show();
+ pendingToastMessage = opName + "鎴愬姛";
- // If success and isSelfCheckMode, wait 5s then read data
+ // 鏍规嵁涓嶅悓鐨勮嚜妫�闃舵锛屽欢杩熶笉鍚屾椂闂村悗璇诲彇鏁版嵁
if (isSelfCheckMode) {
- appendLog("5绉掑悗璇诲彇鑷缁撴灉...");
+ // 寮�濮嬭嚜妫�鎴愬姛鍚庯紝绛夊緟 灞傛暟 * 1000 姣鍐嶈鍙栨暟鎹�
+ int layerCount = com.blankj.utilcode.util.SPUtils.getInstance().getInt("layer_count", 3);
+ long delay = layerCount * 1000L;
+ Toast.makeText(this, "寮�濮嬭嚜妫�锛岃绛夊緟" + layerCount + "绉�", Toast.LENGTH_SHORT).show();
+ // 杩欎釜鏃堕棿鏄负浜嗚浼犳劅鍣ㄥ畬鎴愯嚜妫�鍔ㄤ綔
+ appendLog(delay + "姣鍚庤鍙栬嚜妫�缁撴灉...");
new android.os.Handler().postDelayed(() -> {
sendCmdWithCrc(CMD.READ_DATA);
- }, 5000);
+ }, delay);
+ } else {
+ // 缁撴潫鑷鎴愬姛鍚庯紝绛夊緟500姣鍐嶈鍙栨暟鎹�
+ // 杩欎釜鏃堕棿鏄负浜嗚璁惧鐘舵�佺ǔ瀹氬悗鍐嶈鍙栨渶缁堢粨鏋�
+ appendLog("500姣鍚庤鍙栬嚜妫�缁撴灉...");
+ new android.os.Handler().postDelayed(() -> {
+ sendCmdWithCrc(CMD.READ_DATA);
+ }, 500);
}
} else {
appendLog(opName + "澶辫触");
@@ -378,69 +506,54 @@
}
}
- // Handle READ_DATA response for Self Check results
- // A55A0301...
+ // 澶勭悊璇诲彇鏁版嵁鎸囦护鐨勮繑鍥炵粨鏋滐紝鐢ㄤ簬鏄剧ず鑷缁撴灉
+ // 鏁版嵁鏍煎紡锛欰55A0301... 鑷冲皯闇�瑕�26浣嶅崄鍏繘鍒跺瓧绗�
if (hex.startsWith(CMD.READ_DATA.substring(0, 8)) && hex.length() >= 26) {
+ restoreCurrentButton();
parseSelfCheckData(hex);
+ if (pendingToastMessage != null) {
+ Toast.makeText(this, pendingToastMessage, Toast.LENGTH_SHORT).show();
+ pendingToastMessage = null;
+ }
}
}
+ /**
+ * 瑙f瀽鑷鏁版嵁骞舵洿鏂版牸瀛愮姸鎬�
+ * @param hex 鎺ユ敹鍒扮殑鍗佸叚杩涘埗鏁版嵁
+ */
private void parseSelfCheckData(String hex) {
try {
- // 11th hex -> index 10-18 (8 chars)
+ // 鎻愬彇绗�11-18浣嶏紙8涓瓧绗︼級浣滀负绗竴閮ㄥ垎鏁版嵁
String part1Hex = hex.substring(10, 18);
long part1Bits = Long.parseLong(part1Hex, 16);
- // 18th hex -> index 18-26 (8 chars)
+ // 鎻愬彇绗�19-26浣嶏紙8涓瓧绗︼級浣滀负绗簩閮ㄥ垎鏁版嵁
String part2Hex = hex.substring(18, 26);
long part2Bits = Long.parseLong(part2Hex, 16);
appendLog("鑷鏁版嵁瑙f瀽: " + part1Hex + ", " + part2Hex);
boolean hasChange = false;
+ // 閬嶅巻鎵�鏈夋牸瀛愶紝鏍规嵁浣嶆暟鎹垽鏂嚜妫�缁撴灉
for (BoxStatus box : boxStatusList) {
- int bitIndex = box.id - 1;
+ int bitIndex = box.id - 1; // 鏍煎瓙ID浠�1寮�濮嬶紝浣嶇储寮曚粠0寮�濮�
if (bitIndex >= 0 && bitIndex < 32) {
- // Determine success based on both bits
- // Assuming both need to be 1, or following specific logic.
- // Based on user request "11th and 18th hex", we check both.
- // Usually part1 is Glass (Detection), part2 is Online.
- // We'll assume success means bit is set in both (Online and Detected?)
- // OR maybe just Online?
- // Let's stick to combining them to be safe as user mentioned both.
- // But if Self Check is just checking if it's working, maybe Online is enough?
- // Let's use: Success = (part1 & 1) && (part2 & 1) ?
- // Let's use bitwise AND of the two parts for the result.
-
+ // 鎻愬彇瀵瑰簲浣嶇殑鍊�
boolean bit1 = ((part1Bits >> bitIndex) & 1) == 1;
boolean bit2 = ((part2Bits >> bitIndex) & 1) == 1;
- // If user meant "11th OR 18th", or "11th is this, 18th is that".
- // Given "Success/Fail", I'll assume both must be valid.
- // However, in normal operation:
- // Glass=0, Online=1 -> Empty box, but sensor working.
- // Glass=1, Online=1 -> Full box, sensor working.
- // Online=0 -> Sensor broken/offline.
-
- // If "Self Check" puts the sensor in a state where it should report "1" for Glass?
- // If so, then we expect Glass=1 AND Online=1.
- // If "Self Check" just checks health, then Glass might be 0.
-
- // "纭畾鍝簺鏍煎瓙鑷鎴愬姛" (Determine which grids passed self-check).
- // If I use bit1 && bit2:
- // If a sensor is working but empty (Glass=0), it fails self-check?
- // This implies Self Check expects a "1" signal.
- // This is common in self-checks (force a signal).
-
+ // 涓や釜浣嶉兘涓�1琛ㄧず鑷鎴愬姛锛屽惁鍒欏け璐�
if (bit1 && bit2) {
- box.checkResult = 1; // Green
+ box.checkResult = 1; // 鎴愬姛锛屾樉绀虹豢鑹�
} else {
- box.checkResult = 0; // Red
+ box.checkResult = 0; // 澶辫触锛屾樉绀虹孩鑹�
}
hasChange = true;
}
}
+ // 濡傛灉鏈夋暟鎹彉鍖栵紝鍒锋柊鐣岄潰
if (hasChange && mAdapter != null) {
mAdapter.notifyDataSetChanged();
appendLog("鑷缁撴灉宸叉洿鏂�");
@@ -452,7 +565,10 @@
}
}
-
+ /**
+ * 鍙戦�佸甫CRC鏍¢獙鐨勬寚浠�
+ * @param cmd 瑕佸彂閫佺殑鎸囦护锛堜笉鍚獵RC锛�
+ */
private void sendCmdWithCrc(String cmd) {
if (!BleGlobalManager.getInstance().isConnected()) {
Toast.makeText(this, "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
@@ -462,42 +578,50 @@
byte[] cmdBytes = BleGlobalManager.hexStringToBytes(cmd);
if (cmdBytes != null) {
+ // 璁$畻CRC鏍¢獙鐮�
String crc = CRCutil.getCRC(cmdBytes);
- // Pad CRC to 4 chars if needed
+ // CRC琛ラ綈鍒�4浣�
while (crc.length() < 4) {
crc = "0" + crc;
}
String fullCmd = cmd + crc.toUpperCase();
- appendLog(fullCmd, true); // true for sent (Blue)
+ appendLog(fullCmd, true); // true琛ㄧず鍙戦�佺殑鎸囦护锛屾樉绀轰负钃濊壊
BleGlobalManager.getInstance().sendCmd(fullCmd);
} else {
appendLog("閿欒: 鎸囦护杞崲澶辫触");
}
}
+ /**
+ * 澶勭悊闃堝�艰瀹氬啓鍏�
+ */
private void handleThresholdWrite() {
int position = sp_threshold_mode.getSelectedItemPosition();
String inputValue = et_threshold_value.getText().toString().trim();
String modeHex = "";
String valueHex = "";
- if (position == 0) { // 涓�閿瀹�
+ if (position == 0) {
+ // 涓�閿瀹�
modeHex = "00";
valueHex = "00";
- } else if (position == 1) { // 鍗曞眰璁惧畾
+ } else if (position == 1) {
+ // 鍗曞眰璁惧畾
modeHex = "01";
+ int maxLayer = com.blankj.utilcode.util.SPUtils.getInstance().getInt("layer_count", 30);
if (inputValue.isEmpty()) {
- Toast.makeText(this, "璇疯緭鍏ラ槇鍊�(1-30)", Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, "璇疯緭鍏ラ槇鍊�(1-" + maxLayer + ")", Toast.LENGTH_SHORT).show();
return;
}
try {
int val = Integer.parseInt(inputValue);
- if (val < 1 || val > 30) {
- Toast.makeText(this, "闃堝�艰寖鍥�1-30", Toast.LENGTH_SHORT).show();
+ if (val < 1 || val > maxLayer) {
+ Toast.makeText(this, "闃堝�艰寖鍥�1-" + maxLayer, Toast.LENGTH_SHORT).show();
return;
}
- valueHex = String.format("%02X", val);
+ // 鍗曞眰璁惧畾鏃讹紝杈撳叆鍙傛暟闇�瑕佸噺1
+ valueHex = String.format("%02X", val - 1);
} catch (NumberFormatException e) {
Toast.makeText(this, "杈撳叆鏍煎紡閿欒", Toast.LENGTH_SHORT).show();
return;
@@ -506,19 +630,40 @@
return;
}
- // Construct pending command: CMD (32) + Len (02) + Mode + Value
- // CMD.WRITE_THRESHOLD_SETTING is "A55A063202"
+ // 鏋勯�犳寚浠わ細CMD.WRITE_THRESHOLD_SETTING + 妯″紡 + 鍊�
pendingSettingCmd = CMD.WRITE_THRESHOLD_SETTING + modeHex + valueHex;
- sendCmdWithCrc(pendingSettingCmd);
+ if (BleGlobalManager.getInstance().isConnected()) {
+ currentOperatingButton = btn_threshold_write;
+ updateButtonState(currentOperatingButton, false);
+ setAllGridGray();
+ sendCmdWithCrc(pendingSettingCmd);
+ } else {
+ Toast.makeText(this, "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
+ }
}
+ /**
+ * 灏嗘墍鏈夋牸瀛愯缃负鐏拌壊锛堢瓑寰呯姸鎬侊級
+ */
+ private void setAllGridGray() {
+ for (BoxStatus box : boxStatusList) {
+ box.checkResult = 2; // 2琛ㄧず绛夊緟鐘舵�侊紝鏄剧ず鐏拌壊
+ }
+ if (mAdapter != null) {
+ mAdapter.notifyDataSetChanged();
+ }
+ }
+
+ /**
+ * 澶勭悊鐏垫晱搴﹁瀹氬啓鍏�
+ */
private void handleSensitivityWrite() {
int position = sp_sensitivity_mode.getSelectedItemPosition();
String inputValue = et_sensitivity_value.getText().toString().trim();
String modeHex = "";
String valueHex = "";
- // 0: 鎵归噺澧炲姞(00), 1: 鎵归噺鍑忓皯(01), 2: 鍗曞眰澧炲姞(02), 3: 鍗曞眰鍑忓皯(03)
+ // 妯″紡锛�0=鎵归噺澧炲姞(00), 1=鎵归噺鍑忓皯(01), 2=鍗曞眰澧炲姞(02), 3=鍗曞眰鍑忓皯(03)
if (position == 0) {
modeHex = "00";
valueHex = "00";
@@ -533,28 +678,37 @@
return;
}
+ // 鍗曞眰鎿嶄綔闇�瑕佽緭鍏ュ叿浣撴暟鍊�
if (position == 2 || position == 3) {
+ int maxLayer = com.blankj.utilcode.util.SPUtils.getInstance().getInt("layer_count", 30);
if (inputValue.isEmpty()) {
- Toast.makeText(this, "璇疯緭鍏ユ暟鍊�(1-30)", Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, "璇疯緭鍏ユ暟鍊�(1-" + maxLayer + ")", Toast.LENGTH_SHORT).show();
return;
}
try {
int val = Integer.parseInt(inputValue);
- if (val < 1 || val > 30) {
- Toast.makeText(this, "鏁板�艰寖鍥�1-30", Toast.LENGTH_SHORT).show();
+ if (val < 1 || val > maxLayer) {
+ Toast.makeText(this, "鏁板�艰寖鍥�1-" + maxLayer, Toast.LENGTH_SHORT).show();
return;
}
- valueHex = String.format("%02X", val);
+ // 鍗曞眰璁惧畾鏃讹紝杈撳叆鍙傛暟闇�瑕佸噺1
+ valueHex = String.format("%02X", val - 1);
} catch (NumberFormatException e) {
Toast.makeText(this, "杈撳叆鏍煎紡閿欒", Toast.LENGTH_SHORT).show();
return;
}
}
- // Construct pending command: CMD (33) + Len (02) + Mode + Value
- // CMD.WRITE_SENSITIVITY_SETTING is "A55A063302"
+ // 鏋勯�犳寚浠わ細CMD.WRITE_SENSITIVITY_SETTING + 妯″紡 + 鍊�
pendingSettingCmd = CMD.WRITE_SENSITIVITY_SETTING + modeHex + valueHex;
- sendCmdWithCrc(pendingSettingCmd);
+ if (BleGlobalManager.getInstance().isConnected()) {
+ currentOperatingButton = btn_sensitivity_write;
+ updateButtonState(currentOperatingButton, false);
+ setAllGridGray();
+ sendCmdWithCrc(pendingSettingCmd);
+ } else {
+ Toast.makeText(this, "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
+ }
}
private void updateBluetoothStatus() {
@@ -580,20 +734,25 @@
.setPositiveButton("纭畾", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- pendingSettingCmd = cmd;
- sendCmdWithCrc(cmd);
+ if (BleGlobalManager.getInstance().isConnected()) {
+ updateButtonState(currentOperatingButton, false);
+ pendingSettingCmd = cmd;
+ sendCmdWithCrc(cmd);
+ } else {
+ Toast.makeText(ParameterSettingActivity.this, "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
+ }
}
})
.setNegativeButton("鍙栨秷", null)
.show();
}
- // Inner classes
-
+ /**
+ * 鏍煎瓙鐘舵�佹暟鎹被
+ */
private static class BoxStatus {
- int id;
- // -1: Unknown/Initial (White), 0: Fail (Red), 1: Success (Green)
- int checkResult = -1;
+ int id; // 鏍煎瓙ID锛�1-30锛�
+ int checkResult = -1; // 鑷缁撴灉锛�-1=鏈煡锛堢櫧鑹诧級锛�0=澶辫触锛堢孩鑹诧級锛�1=鎴愬姛锛堢豢鑹诧級锛�2=绛夊緟锛堢伆鑹诧級
public BoxStatus(int id) {
this.id = id;
@@ -612,18 +771,17 @@
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
- // Calculate Box ID based on 3 rows of 10, Right to Left logic as seen in image
- // Row 1 (pos 0-9): 10 ... 1
- // Row 2 (pos 10-19): 20 ... 11
- // Row 3 (pos 20-29): 30 ... 21
-
+ // 璁$畻鏍煎瓙ID锛�3琛�10鍒楋紝浠庡乏鍒板彸鎺掑垪
+ // 绗�1琛岋紙浣嶇疆0-9锛夛細1-10
+ // 绗�2琛岋紙浣嶇疆10-19锛夛細11-20
+ // 绗�3琛岋紙浣嶇疆20-29锛夛細21-30
int row = position / 10;
int col = position % 10;
- int boxId = (row + 1) * 10 - col;
+ int boxId = row * 10 + col + 1;
holder.tvBoxNumber.setText(String.valueOf(boxId));
- // Find status for this box
+ // 鏌ユ壘瀵瑰簲鏍煎瓙鐨勭姸鎬�
BoxStatus status = null;
for (BoxStatus s : boxStatusList) {
if (s.id == boxId) {
@@ -632,16 +790,24 @@
}
}
+ // 鏍规嵁鑷缁撴灉璁剧疆鑳屾櫙棰滆壊
if (status != null) {
if (status.checkResult == 1) {
- // Success
- holder.viewBox.setBackgroundResource(R.drawable.bg_box_full); // Green
+ // 鑷鎴愬姛锛屾樉绀虹豢鑹�
+ holder.viewBox.setBackgroundResource(R.drawable.bg_box_full);
+ holder.viewBox.getBackground().clearColorFilter();
} else if (status.checkResult == 0) {
- // Fail
- holder.viewBox.setBackgroundResource(R.drawable.bg_box_error); // Red
+ // 鑷澶辫触锛屾樉绀虹孩鑹�
+ holder.viewBox.setBackgroundResource(R.drawable.bg_box_error);
+ holder.viewBox.getBackground().clearColorFilter();
+ } else if (status.checkResult == 2) {
+ // 绛夊緟鐘舵�侊紝鏄剧ず鐏拌壊
+ holder.viewBox.setBackgroundResource(R.drawable.bg_box_empty);
+ holder.viewBox.getBackground().setColorFilter(android.graphics.Color.GRAY, android.graphics.PorterDuff.Mode.MULTIPLY);
} else {
- // Unknown / Initial
- holder.viewBox.setBackgroundResource(R.drawable.bg_box_empty); // White
+ // 鏈煡鐘舵�侊紝鏄剧ず鐧借壊
+ holder.viewBox.setBackgroundResource(R.drawable.bg_box_empty);
+ holder.viewBox.getBackground().clearColorFilter();
}
}
}
@@ -662,4 +828,25 @@
}
}
}
+
+ private void restoreCurrentButton() {
+ if (currentOperatingButton != null) {
+ updateButtonState(currentOperatingButton, true);
+ currentOperatingButton = null;
+ }
+ }
+
+ private void updateButtonState(Button btn, boolean enable) {
+ if (btn == null) return;
+ btn.setEnabled(enable);
+ if (enable) {
+ if (btn.getBackground() != null) {
+ btn.getBackground().clearColorFilter();
+ }
+ } else {
+ if (btn.getBackground() != null) {
+ btn.getBackground().setColorFilter(android.graphics.Color.GRAY, android.graphics.PorterDuff.Mode.MULTIPLY);
+ }
+ }
+ }
}
diff --git a/app/src/main/java/com/shlb/comb/activity/SystemSettingsActivity.java b/app/src/main/java/com/shlb/comb/activity/SystemSettingsActivity.java
new file mode 100644
index 0000000..864763f
--- /dev/null
+++ b/app/src/main/java/com/shlb/comb/activity/SystemSettingsActivity.java
@@ -0,0 +1,86 @@
+package com.shlb.comb.activity;
+
+import android.widget.CompoundButton;
+import android.widget.Toast;
+
+import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView;
+import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView;
+import com.shlb.comb.R;
+import com.shlb.comb.base.BaseActivity;
+import com.shlb.comb.event.UpdateEvent;
+
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
+
+public class SystemSettingsActivity extends BaseActivity {
+
+ private QMUIGroupListView mGroupListView;
+
+ @Override
+ protected void contentView() {
+ setContentView(R.layout.activity_system_settings);
+ }
+
+ @Override
+ protected void initView() {
+ super.initHead();
+ setTitle("绯荤粺璁剧疆");
+
+ // Set left button to back icon
+ if (iv_left != null) {
+ iv_left.setImageResource(R.mipmap.icon_back);
+ iv_left.setOnClickListener(v -> finish());
+ }
+
+ // Hide right text (connection status)
+ android.view.View tvRightText = findViewById(R.id.tv_right_text);
+ if (tvRightText != null) {
+ tvRightText.setVisibility(android.view.View.GONE);
+ }
+
+ mGroupListView = findViewById(R.id.groupListView);
+ initGroupListView();
+ // Hide right button if not needed
+ if (iv_right != null) {
+ iv_right.setVisibility(android.view.View.GONE);
+ }
+ }
+
+ @Override
+ protected void initData() {
+
+ }
+
+ @Override
+ protected void initEvent() {
+
+ }
+
+ private void initGroupListView() {
+ QMUICommonListItemView itemCmdLog = mGroupListView.createItemView("CMD鏃ュ織");
+ itemCmdLog.setAccessoryType(QMUICommonListItemView.ACCESSORY_TYPE_SWITCH);
+ boolean isCmdLogEnabled = com.blankj.utilcode.util.SPUtils.getInstance().getBoolean("cmd_log_enabled", false);
+ itemCmdLog.getSwitch().setChecked(isCmdLogEnabled);
+ itemCmdLog.getSwitch().setOnCheckedChangeListener((buttonView, isChecked) -> {
+ com.blankj.utilcode.util.SPUtils.getInstance().put("cmd_log_enabled", isChecked);
+ Toast("CMD鏃ュ織: " + (isChecked ? "寮�鍚�" : "鍏抽棴"));
+ });
+
+// QMUICommonListItemView itemTestPage = mGroupListView.createItemView("娴嬭瘯椤甸潰");
+// itemTestPage.setAccessoryType(QMUICommonListItemView.ACCESSORY_TYPE_SWITCH);
+// itemTestPage.getSwitch().setOnCheckedChangeListener((buttonView, isChecked) -> {
+// Toast("娴嬭瘯椤甸潰: " + (isChecked ? "寮�鍚�" : "鍏抽棴"));
+// });
+
+ QMUIGroupListView.newSection(this)
+ .setTitle("璁剧疆")
+ .addItemView(itemCmdLog, null)
+// .addItemView(itemTestPage, null)
+ .addTo(mGroupListView);
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onEvent(UpdateEvent event) {
+ // Placeholder to satisfy EventBus requirements in BaseActivity
+ }
+}
diff --git a/app/src/main/java/com/shlb/comb/fragment/DeviceListFragment.java b/app/src/main/java/com/shlb/comb/fragment/DeviceListFragment.java
index 942c9be..d8df7be 100644
--- a/app/src/main/java/com/shlb/comb/fragment/DeviceListFragment.java
+++ b/app/src/main/java/com/shlb/comb/fragment/DeviceListFragment.java
@@ -356,8 +356,6 @@
if (scanManager != null) {
scanManager.setScanCallbackCompat(null);
scanManager.setScanOverListener(null);
- // 閲婃斁璧勬簮
- scanManager.release();
}
}
}
diff --git a/app/src/main/java/com/shlb/comb/fragment/SettingsFragment.java b/app/src/main/java/com/shlb/comb/fragment/SettingsFragment.java
index 2702ac4..4ff3346 100644
--- a/app/src/main/java/com/shlb/comb/fragment/SettingsFragment.java
+++ b/app/src/main/java/com/shlb/comb/fragment/SettingsFragment.java
@@ -1,5 +1,6 @@
package com.shlb.comb.fragment;
+import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -34,32 +35,50 @@
import android.text.Html;
import android.content.DialogInterface;
+/**
+ * 璁剧疆鐣岄潰 Fragment
+ * <p>
+ * 璇ョ被璐熻矗璁惧鍙傛暟鐨勯厤缃�佽澶囩姸鎬佺殑鐩戞帶浠ュ強钃濈墮閫氫俊鐨勫鐞嗭細
+ * 1. 鏀寔绔欏彿銆佸眰鏁般�佹尝鐗圭巼绛夊弬鏁扮殑璇诲彇鍜屽啓鍏�
+ * 2. 瀹炴椂鐩戞帶璁惧鍦ㄧ嚎鐘舵�佸拰鐜荤拑鏈夋棤鎯呭喌
+ * 3. 鎻愪緵钃濈墮杩炴帴鐘舵�佺殑鏄剧ず鍜屽鐞�
+ * 4. 瀹炵幇鏃ュ織璁板綍鍜屾樉绀哄姛鑳�
+ * 5. 鏀寔鍛ㄦ湡鎬ф暟鎹鍙栵紙姣�1绉掞級锛岄伩鍏嶉绻佹棩蹇楀鑷撮〉闈㈠崱椤�
+ * </p>
+ */
public class SettingsFragment extends Fragment {
- private RecyclerView rvGrid;
- private EditText etLayer;
- private EditText etStation;
- private Spinner spinnerBaud;
- private QMUIRoundButton btnWriteAll;
- private QMUIRoundButton btnReadData;
- private QMUIRoundButton btnReadParam;
- private QMUIRoundButton btnClearLog;
- private TextView tvStatus;
- private TextView tvLog;
- private TextView tvLayerStatus;
- private TextView tvStationStatus;
- private TextView tvBaudStatus;
- private android.widget.ScrollView svLog;
-
- private QMUITipDialog mLoadingDialog;
-
- private GridAdapter mAdapter;
- private List<BoxStatus> boxStatusList = new ArrayList<>();
- private StringBuilder logBuilder = new StringBuilder();
+ // 鐢ㄦ埛鐣岄潰缁勪欢
+ private RecyclerView rvGrid; // 璁惧鐘舵�佺綉鏍艰鍥�
+ private TextView etLayer; // 灞傛暟鏄剧ず鏂囨湰妗�
+ private EditText etStation; // 绔欏彿杈撳叆妗�
+ private Spinner spinnerBaud; // 娉㈢壒鐜囬�夋嫨鍣�
+ private QMUIRoundButton btnWriteAll; // 鍐欏叆鎵�鏈夊弬鏁版寜閽�
+ private QMUIRoundButton btnReadParam; // 璇诲彇鍙傛暟鎸夐挳
+ private QMUIRoundButton btnClearLog; // 娓呴櫎鏃ュ織鎸夐挳
+ private TextView tvMonitorTitle; // 鐩戞帶璇︽儏鏍囬
+ private TextView tvMonitorUpdateTime; // 鐩戞帶鏁版嵁鏇存柊鏃堕棿
+ private TextView tvStatus; // 鐘舵�佹樉绀烘枃鏈�
+ private TextView tvLog; // 鏃ュ織鏄剧ず鏂囨湰
+ private TextView tvLayerStatus; // 灞傛暟鐘舵�佹爣绛�
+ private TextView tvStationStatus; // 绔欏彿鐘舵�佹爣绛�
+ private TextView tvBaudStatus; // 娉㈢壒鐜囩姸鎬佹爣绛�
- private java.util.Queue<String> cmdQueue = new java.util.LinkedList<>();
+ private android.widget.ScrollView svLog; // 鏃ュ織婊氬姩瑙嗗浘
+ private androidx.cardview.widget.CardView cvLog; // 鏃ュ織瀹瑰櫒
+
+ private QMUITipDialog mLoadingDialog; // 鍔犺浇瀵硅瘽妗�
+
+ private GridAdapter mAdapter; // 缃戞牸閫傞厤鍣�
+ private List<BoxStatus> boxStatusList = new ArrayList<>(); // 璁惧鐘舵�佸垪琛�
+ private StringBuilder logBuilder = new StringBuilder(); // 鏃ュ織鍐呭鏋勫缓鍣�
+
+ private java.util.Queue<String> cmdQueue = new java.util.LinkedList<>(); // 鎸囦护闃熷垪锛岀敤浜庢寜椤哄簭鎵ц鎸囦护
private String currentExecutingCmd = ""; // 褰撳墠姝e湪鎵ц鐨勬寚浠わ紝鐢ㄤ簬鏍¢獙鍝嶅簲
-
+ private boolean isPeriodicRead = false; // 鏍囪鏄惁涓哄懆鏈熸�ц鍙栵紝鐢ㄤ簬鎺у埗鏃ュ織璁板綍
+ private boolean isFirstLoad = true; // 鏍囪鏄惁涓洪娆″姞杞斤紝閬垮厤閲嶅瑙﹀彂璇诲彇鍙傛暟
+ private View currentOperatingButton; // 褰撳墠姝e湪鎿嶄綔鐨勬寜閽�
+
private static class BoxStatus {
int id;
boolean isOnline;
@@ -72,30 +91,61 @@
}
}
- private Runnable autoReadRunnable = new Runnable() {
+ // 鍛ㄦ湡鎬ц鍙栨暟鎹浉鍏冲彉閲�
+ private android.os.Handler periodicReadHandler = new android.os.Handler(); // 鐢ㄤ簬澶勭悊鍛ㄦ湡鎬ц鍙栦换鍔$殑Handler
+ private static final long PERIODIC_READ_INTERVAL = 500; // 鍛ㄦ湡鎬ц鍙栭棿闅旓紙姣锛夛細1绉�
+
+ private Runnable periodicReadRunnable = new Runnable() {
+ @Override
+ public void run() {
+ // 姣�1绉掕鍙栦竴娆℃暟鎹紝涓嶈褰曟棩蹇�
+ if (BleGlobalManager.getInstance().isConnected()) {
+ periodicReadData();
+
+ // 缁х画瀹夋帓涓嬩竴娆¤鍙�
+ periodicReadHandler.postDelayed(this, PERIODIC_READ_INTERVAL);
+ }
+ }
+ };
+
+ // 鑷姩璇诲彇鍙傛暟鐩稿叧鍙橀噺
+ private Runnable autoReadRunnable = new Runnable() { // 钃濈墮杩炴帴鎴愬姛鍚庤嚜鍔ㄨ鍙栧弬鏁扮殑浠诲姟
@Override
public void run() {
// 钃濈墮杩炴帴鎴愬姛鍚� 鑷姩瑙﹀彂鐩戞帶璇︽儏鐨� 璇诲彇鏁版嵁 鍜� 鍙傛暟璁惧畾杩欓噷鐨� 璇诲彇鍙傛暟
if (BleGlobalManager.getInstance().isConnected()) {
showLoading("姝e湪鍚屾鏁版嵁...");
- if (btnReadData != null) btnReadData.performClick();
-
+ // 鍏堣Е鍙戣鍙栨暟鎹�
+ tvStatus.setText("鐘舵�侊細姝e湪璇诲彇鏁版嵁...");
+ if (tvMonitorTitle != null) tvMonitorTitle.performClick();
+
+
new android.os.Handler().postDelayed(() -> {
+ // 鍐嶈Е鍙戣鍙栧弬鏁�
if (btnReadParam != null) btnReadParam.performClick();
// 鍋囪鍙傛暟璇诲彇瑙﹀彂鍚� 1.5绉� 鍏抽棴 loading锛屾垨鑰呭湪瑙f瀽瀹屾墍鏈夊弬鏁板悗鍏抽棴
// 杩欓噷绠�鍗曞鐞嗭紝寤舵椂鍏抽棴
new android.os.Handler().postDelayed(() -> {
dismissLoading();
+ // 鍒濆璁剧疆瀹屾垚鍚庡惎鍔ㄥ懆鏈熸�ц鍙�
+ startPeriodicRead(PERIODIC_READ_INTERVAL);
+ isFirstLoad = false; // 棣栨鍔犺浇瀹屾垚
}, 1500);
}, 1000); // 闂撮殧1绉掞紝閬垮厤鎸囦护鍐茬獊
}
}
};
- private android.os.Handler debounceHandler = new android.os.Handler();
- private static final long DEBOUNCE_DELAY_MS = 1500; // 1.5 seconds debounce
+ private android.os.Handler debounceHandler = new android.os.Handler(); // 鐢ㄤ簬闃叉姈澶勭悊鐨凥andler
+ private static final long DEBOUNCE_DELAY_MS = 1500; // 闃叉姈寤惰繜鏃堕棿锛堟绉掞級锛�1.5绉�
+/**
+ * Fragment 鍙鏃惰皟鐢�
+ * <p>
+ * 娉ㄥ唽 EventBus 骞舵洿鏂拌摑鐗欒繛鎺ョ姸鎬�
+ * </p>
+ */
@Override
public void onStart() {
super.onStart();
@@ -105,11 +155,70 @@
updateConnectionStatus();
}
+/**
+ * Fragment 涓嶅彲瑙佹椂璋冪敤
+ * <p>
+ * 鍙栨秷娉ㄥ唽 EventBus锛岄伩鍏嶅唴瀛樻硠婕�
+ * </p>
+ */
@Override
public void onStop() {
super.onStop();
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
+ }
+ }
+
+/**
+ * Fragment 鎭㈠鍙鏃惰皟鐢�
+ * \u003cp\u003e
+ * 濡傛灉钃濈墮宸茶繛鎺ワ紝鎭㈠鍛ㄦ湡鎬ц鍙栨暟鎹�
+ * \u003c/p\u003e
+ */
+ @Override
+ public void onResume() {
+ super.onResume();
+ // 鏍规嵁绯荤粺璁剧疆鎺у埗鏃ュ織鏄剧ず
+ boolean isCmdLogEnabled = com.blankj.utilcode.util.SPUtils.getInstance().getBoolean("cmd_log_enabled", false);
+ if (cvLog != null) {
+ cvLog.setVisibility(isCmdLogEnabled ? View.VISIBLE : View.GONE);
+ }
+
+ // 濡傛灉钃濈墮宸茶繛鎺ワ紝鎭㈠鍛ㄦ湡鎬ц鍙�
+ if (BleGlobalManager.getInstance().isConnected()) {
+ // 鍙湁褰撲笉鏄娆″姞杞斤紙鍗充粠鍏朵粬椤甸潰杩斿洖锛夋椂鎵嶆墜鍔ㄨЕ鍙戣鍙栧弬鏁�
+ // 棣栨鍔犺浇浼氳蛋 autoReadRunnable
+ if (!isFirstLoad && btnReadParam != null) {
+ btnReadParam.performClick();
+ }
+ startPeriodicRead(3000);
+ }
+ }
+
+/**
+ * Fragment 鏆傚仠鏃惰皟鐢�
+ * \u003cp\u003e
+ * 鍋滄鍛ㄦ湡鎬ц鍙栨暟鎹紝鑺傜渷璧勬簮
+ * \u003c/p\u003e
+ */
+ @Override
+ public void onPause() {
+ super.onPause();
+ // 绂诲紑椤甸潰鏃跺仠姝㈠懆鏈熸�ц鍙�
+ stopPeriodicRead();
+ }
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ // 娓呯悊鎵�鏈� Handler 鍥炶皟锛岄伩鍏嶅唴瀛樻硠婕�
+ stopPeriodicRead();
+ debounceHandler.removeCallbacks(autoReadRunnable);
+
+ // 娓呯悊鍔犺浇瀵硅瘽妗�
+ if (mLoadingDialog != null) {
+ mLoadingDialog.dismiss();
+ mLoadingDialog = null;
}
}
@@ -121,40 +230,66 @@
}
}
+/**
+ * 浜嬩欢鎬荤嚎鐩戝惉鍣�
+ * <p>
+ * 澶勭悊钃濈墮杩炴帴鐘舵�佸彉鍖栧拰璁惧鏁版嵁鎺ユ敹浜嬩欢
+ * </p>
+ * @param event 浜嬩欢瀵硅薄
+ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventRefresh(UpdateEvent event) {
if (event.getType() == UpdateEvent.Type.CONN_STATU) {
- // Check if obj is integer
+ // 妫�鏌bj鏄惁涓烘暣鏁�
if (event.getObj() instanceof Integer) {
int status = (int) event.getObj();
if (status == BluetoothProfile.STATE_CONNECTED) {
tvStatus.setText("鐘舵�侊細宸茶繛鎺�");
Toast.makeText(getContext(), "钃濈墮宸茶繛鎺�", Toast.LENGTH_SHORT).show();
-
+
// 钃濈墮杩炴帴鎴愬姛鍚� 鑷姩瑙﹀彂
triggerAutoRead();
} else {
tvStatus.setText("鐘舵�侊細宸叉柇寮�");
+ // 钃濈墮鏂紑鏃跺仠姝㈠懆鏈熸�ц鍙�
+ stopPeriodicRead();
}
}
} else if (event.getType() == UpdateEvent.Type.DEVICE_INFO) {
- // Received data
+ // 鏀跺埌鏁版嵁
String hex = event.getMsg();
- tvStatus.setText("鏀跺埌鏁版嵁: " + hex);
- appendLog(hex, false); // false for received (Green)
+ if (tvStatus != null && !isPeriodicRead) {
+ tvStatus.setText("鏀跺埌鏁版嵁: " + hex);
+ }
+
+ // 妫�鏌ユ槸鍚︿负鍛ㄦ湡鎬ц鍙�
+ if (!isPeriodicRead) {
+ appendLog(hex, false); // false琛ㄧず鎺ユ敹鐨勬暟鎹紙缁胯壊锛�
+ }
+
parseAndRefresh(hex);
+
+ // 鏃犺鏄惁涓哄懆鏈熸�ц鍙栵紝澶勭悊瀹屾垚鍚庨兘閲嶇疆鏍囪
+ isPeriodicRead = false;
}
}
+/**
+ * 瑙f瀽骞跺埛鏂版暟鎹�
+ * <p>
+ * 鏍规嵁鎸囦护绫诲瀷鍒嗗彂鍒颁笉鍚岀殑瑙f瀽鏂规硶
+ * </p>
+ * @param hex 鍗佸叚杩涘埗鏍煎紡鐨勫師濮嬫暟鎹�
+ */
private void parseAndRefresh(String hex) {
if (hex == null) return;
- // 鏍规嵁CMD鍓�8浣嶅垽鏂寚浠ょ被鍨�
+ // 鏍规嵁鎸囦护鍓�8浣嶅垽鏂寚浠ょ被鍨�
if (hex.length() >= 8) {
// 鍙傛暟璇诲彇杩斿洖 (闀垮害鑷冲皯12浣�)
- // 璇诲眰鏁�: A55A0308...
- // 璇荤珯鍙�: A55A0304...
- // 璇绘尝鐗圭巼: A55A0305...
+ // 璇诲眰鏁版寚浠�: A55A0308...
+ // 璇荤珯鍙锋寚浠�: A55A0304...
+ // 璇绘尝鐗圭巼鎸囦护: A55A0305...
if (hex.length() >= 12 && (
hex.startsWith(CMD.READ_FLOORS.substring(0, 8)) ||
hex.startsWith(CMD.READ_STATION_NUM.substring(0, 8)) ||
@@ -164,14 +299,14 @@
}
// 鏁版嵁璇诲彇杩斿洖 (闀垮害鑷冲皯32浣�)
- // 璇绘暟鎹�: A55A0301...
+ // 璇绘暟鎹寚浠�: A55A0301...
if (hex.length() >= 32 && hex.startsWith(CMD.READ_DATA.substring(0, 8))) {
parseDataResponse(hex);
return;
}
}
- // 鍐欏叆鎸囦护鐨勮繑鍥� (A55A06寮�澶�)
+ // 鍐欏叆鎸囦护鐨勮繑鍥� (浠55A06寮�澶�)
if (hex.startsWith("A55A06") && hex.length() >= 12) {
parseWriteResponse(hex);
return;
@@ -208,11 +343,18 @@
}
setLabelStatus(tvBaudStatus, "(璇诲彇鍊�)", R.color.base_color);
appendLog("璇诲彇娉㈢壒鐜�: " + value);
+
+ // 璇诲彇缁撴潫锛屾仮澶嶆寜閽姸鎬�
+ restoreCurrentButton();
} else if ("08".equals(cmdType)) {
// 灞傛暟
- if (etLayer != null) etLayer.setText(String.valueOf(value));
+ if (etLayer != null) {
+ etLayer.setText(String.valueOf(value));
+ etLayer.setTextColor(0xFF333333);
+ }
setLabelStatus(tvLayerStatus, "(璇诲彇鍊�)", R.color.base_color);
appendLog("璇诲彇灞傛暟: " + value);
+ com.blankj.utilcode.util.SPUtils.getInstance().put("layer_count", value);
}
} catch (Exception e) {
e.printStackTrace();
@@ -259,6 +401,7 @@
cmdQueue.clear();
currentExecutingCmd = "";
tvStatus.setText("鍐欏叆澶辫触");
+ restoreCurrentButton(); // 鎭㈠鎸夐挳
if (currentExecutingCmd.startsWith(CMD.WRITE_STATION_NUM)) {
setLabelStatus(tvStationStatus, "(鍐欏叆澶辫触)", R.color.orange);
@@ -278,6 +421,7 @@
// 寮傚父涔熻涓哄け璐�
setLabelStatus(tvStationStatus, "(鍐欏叆澶辫触)", R.color.orange);
setLabelStatus(tvBaudStatus, "(鍐欏叆澶辫触)", R.color.orange);
+ restoreCurrentButton(); // 寮傚父鎭㈠鎸夐挳
}
}
@@ -303,25 +447,38 @@
currentExecutingCmd = "";
tvStatus.setText("鍙傛暟鍐欏叆瀹屾垚");
Toast.makeText(getContext(), "鍙傛暟鍐欏叆鎴愬姛", Toast.LENGTH_SHORT).show();
+ restoreCurrentButton(); // 鍏ㄩ儴瀹屾垚锛屾仮澶嶆寜閽�
}
}
/**
* 瑙f瀽鐩戞帶鏁版嵁杩斿洖 (鏄惁鏈夌幓鐠冦�佸湪绾跨姸鎬�)
*/
+/**
+ * 瑙f瀽鐩戞帶鏁版嵁杩斿洖
+ * <p>
+ * 瑙f瀽璁惧鍦ㄧ嚎鐘舵�佸拰鐜荤拑鏈夋棤鎯呭喌
+ * </p>
+ * @param hex 鍗佸叚杩涘埗鏍煎紡鐨勫師濮嬫暟鎹�
+ */
private void parseDataResponse(String hex) {
try {
// 瑙f瀽鏄惁鏈夌幓鐠�: 绗�11-18浣� (8涓瓧绗� = 32浣�)
// 绱㈠紩 10-17
String glassHex = hex.substring(10, 18);
- appendLog("瑙f瀽鐜荤拑鏁版嵁: " + glassHex);
+ if(!isPeriodicRead){
+ appendLog("瑙f瀽鐜荤拑鏁版嵁: " + glassHex);
+ }
+
- // 鐩存帴瑙f瀽 hex 涓� long (Big Endian)
- // "00000004" -> 4 -> ...00100 -> Bit 2 -> Box 3
+ // 鐩存帴灏嗗崄鍏繘鍒惰В鏋愪负闀挎暣鍨� (澶х搴�)
+ // "00000004" -> 4 -> ...00100 -> 绗�2浣� -> 绗�3涓牸瀛�
long glassBits = Long.parseLong(glassHex, 16);
String onlineHex = hex.substring(18, 26);
+ if(!isPeriodicRead){
appendLog("瑙f瀽鍦ㄧ嚎鏁版嵁: " + onlineHex);
+ }
long onlineBits = Long.parseLong(onlineHex, 16);
// 鏇存柊30涓牸瀛愮殑鐘舵��
@@ -337,6 +494,12 @@
// 鍒锋柊鍒楄〃鏄剧ず
if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
+ }
+
+ // 鏇存柊鐩戞帶鏁版嵁鎺ユ敹鏃堕棿
+ if (tvMonitorUpdateTime != null) {
+ String currentTime = com.blankj.utilcode.util.TimeUtils.getNowString(new java.text.SimpleDateFormat("HH:mm:ss"));
+ tvMonitorUpdateTime.setText(currentTime);
}
} catch (Exception e) {
@@ -358,7 +521,7 @@
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- // Initialize box status list
+ // 鍒濆鍖栬澶囩姸鎬佸垪琛�
boxStatusList.clear();
for (int i = 1; i <= 30; i++) {
boxStatusList.add(new BoxStatus(i));
@@ -378,6 +541,82 @@
debounceHandler.postDelayed(autoReadRunnable, DEBOUNCE_DELAY_MS);
}
+ private void startPeriodicRead(long delay) {
+ // 鍏堝仠姝㈠彲鑳藉瓨鍦ㄧ殑浠诲姟锛岄伩鍏嶉噸澶嶅惎鍔�
+ stopPeriodicRead();
+
+ // 鍚姩鍛ㄦ湡鎬ц鍙�
+ periodicReadHandler.postDelayed(periodicReadRunnable, delay);
+ }
+
+ private void stopPeriodicRead() {
+ periodicReadHandler.removeCallbacks(periodicReadRunnable);
+ }
+
+ /**
+ * 涓撻棬鐢ㄤ簬鍛ㄦ湡鎬ц鍙栨暟鎹殑鏂规硶锛屼笉璁板綍鏃ュ織
+ */
+/**
+ * 鍛ㄦ湡鎬ц鍙栨暟鎹紙姣�1绉掞級
+ * <p>
+ * 涓撻棬鐢ㄤ簬鍛ㄦ湡鎬ц鍙栨暟鎹紝涓嶈褰曟棩蹇椾互閬垮厤椤甸潰鍗¢】
+ * </p>
+ */
+ private void periodicReadData() {
+ try {
+ if (BleGlobalManager.getInstance() != null && BleGlobalManager.getInstance().isConnected()) {
+ if (tvStatus != null && isPeriodicRead) {
+ tvStatus.setText("鐘舵�侊細姝e湪璇诲彇鏁版嵁...");
+ }
+ // 璁剧疆鍛ㄦ湡鎬ц鍙栨爣璁�
+ isPeriodicRead = true;
+ // 鐩存帴鍙戦�佸懡浠わ紝涓嶈褰曟棩蹇�
+ sendCmdWithCrcNoLog(CMD.READ_DATA);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ // 寮傚父涔熶笉璁板綍鏃ュ織锛岄伩鍏嶅崱椤�
+ // 纭繚鏍囪琚噸缃�
+ isPeriodicRead = false;
+ }
+ }
+
+ /**
+ * 鍙戦�佸懡浠や絾涓嶈褰曟棩蹇楋紙鐢ㄤ簬鍛ㄦ湡鎬ц鍙栵級
+ */
+/**
+ * 鍙戦�佸甫 CRC 鏍¢獙鐨勬寚浠わ紙涓嶈褰曟棩蹇楋級
+ * <p>
+ * 涓撻棬鐢ㄤ簬鍛ㄦ湡鎬ц鍙栨暟鎹紝閬垮厤棰戠箒璁板綍鏃ュ織瀵艰嚧椤甸潰鍗¢】
+ * </p>
+ * @param cmd 鍗佸叚杩涘埗鏍煎紡鐨勬寚浠ゅ唴瀹�
+ */
+ private void sendCmdWithCrcNoLog(String cmd) {
+ if (!BleGlobalManager.getInstance().isConnected()) {
+ return; // 闈欓粯杩斿洖锛屼笉鏄剧ず Toast 鎴栨棩蹇�
+ }
+
+ byte[] cmdBytes = BleGlobalManager.hexStringToBytes(cmd);
+ if (cmdBytes != null) {
+ String crc = CRCutil.getCRC(cmdBytes);
+ // 纭繚CRC涓�4涓瓧绗︼紝涓嶈冻鍒欒ˉ闆�
+ while (crc.length() < 4) {
+ crc = "0" + crc;
+ }
+ String fullCmd = cmd + crc.toUpperCase();
+
+ // 涓嶈褰曟棩蹇楋紝鐩存帴鍙戦�佸懡浠�
+ BleGlobalManager.getInstance().sendCmd(fullCmd);
+ }
+ }
+
+/**
+ * 鏄剧ず鍔犺浇瀵硅瘽妗�
+ * <p>
+ * 鐢ㄤ簬鎿嶄綔杩囩▼涓殑绛夊緟鎻愮ず
+ * </p>
+ * @param msg 鍔犺浇鎻愮ず淇℃伅
+ */
private void showLoading(String msg) {
if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
mLoadingDialog.dismiss();
@@ -386,25 +625,36 @@
.setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
.setTipWord(msg)
.create();
- // 鍏佽鐐瑰嚮澶栭儴鎴栬繑鍥為敭鍙栨秷 loading锛堝彧鏄叧闂� dialog锛�
+ // 鍏佽鐐瑰嚮澶栭儴鎴栬繑鍥為敭鍙栨秷鍔犺浇锛堜粎鍏抽棴瀵硅瘽妗嗭級
mLoadingDialog.setCancelable(true);
mLoadingDialog.setCanceledOnTouchOutside(true);
mLoadingDialog.show();
}
+/**
+ * 鍏抽棴鍔犺浇瀵硅瘽妗�
+ */
private void dismissLoading() {
if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
mLoadingDialog.dismiss();
}
}
+/**
+ * 鍒濆鍖栫晫闈㈢粍浠�
+ * <p>
+ * 璁剧疆鍚勪釜UI缁勪欢鐨勫紩鐢ㄥ拰鐩戝惉鍣�
+ * </p>
+ * @param view Fragment 鐨勬牴瑙嗗浘
+ */
private void initView(View view) {
rvGrid = view.findViewById(R.id.rv_grid);
etLayer = view.findViewById(R.id.et_layer);
etStation = view.findViewById(R.id.et_station);
spinnerBaud = view.findViewById(R.id.spinner_baud);
btnWriteAll = view.findViewById(R.id.btn_write_all);
- btnReadData = view.findViewById(R.id.btn_read_data);
+ tvMonitorTitle = view.findViewById(R.id.tv_monitor_title);
+ tvMonitorUpdateTime = view.findViewById(R.id.tv_monitor_update_time);
btnReadParam = view.findViewById(R.id.btn_read_param);
btnClearLog = view.findViewById(R.id.btn_clear_log);
tvStatus = view.findViewById(R.id.tv_status);
@@ -412,7 +662,9 @@
svLog = view.findViewById(R.id.sv_log);
tvLayerStatus = view.findViewById(R.id.tv_layer_status);
tvStationStatus = view.findViewById(R.id.tv_station_status);
+
tvBaudStatus = view.findViewById(R.id.tv_baud_status);
+ cvLog = view.findViewById(R.id.cv_log);
// 瑙e喅鏃ュ織鍖哄煙婊戝姩鍐茬獊
svLog.setOnTouchListener((v, event) -> {
@@ -423,7 +675,7 @@
return false;
});
- // Restore logs if any
+ // 鎭㈠鏃ュ織锛堝鏋滄湁锛�
if (logBuilder.length() > 0) {
tvLog.setText(Html.fromHtml(logBuilder.toString()));
} else {
@@ -431,21 +683,25 @@
tvLog.setText(Html.fromHtml(logBuilder.toString()));
}
- // Grid Setup
- // 10 columns to match the image (10 boxes per row)
- // Since we are in a horizontal scroll view, this will layout correctly
+ // 缃戞牸甯冨眬璁剧疆
+ // 姣忚10涓牸瀛�
+ // 鐢变簬鍦ㄦ按骞虫粴鍔ㄨ鍥句腑锛屽竷灞�浼氳嚜鍔ㄨ皟鏁�
rvGrid.setLayoutManager(new GridLayoutManager(getContext(), 10));
mAdapter = new GridAdapter();
rvGrid.setAdapter(mAdapter);
- // Spinner Setup
+ // 娉㈢壒鐜囬�夋嫨鍣ㄨ缃�
String[] baudRates = new String[]{"156Kbps", "625Kbps", "2.5Mbps", "5Mbps", "10Mbps"};
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, baudRates);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerBaud.setAdapter(spinnerAdapter);
- spinnerBaud.setSelection(0); // Select 156Kbps by default
+ spinnerBaud.setSelection(0); // 榛樿閫夋嫨156Kbps
- // Button Listeners
+ tvMonitorTitle.setOnClickListener(v -> {
+ onMonitorTitleClick();
+ });
+
+ // 鎸夐挳鐩戝惉鍣ㄨ缃�
btnWriteAll.setOnClickListener(v -> {
if (!BleGlobalManager.getInstance().isConnected()) {
Toast.makeText(getContext(), "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
@@ -470,6 +726,9 @@
return;
}
+ currentOperatingButton = btnWriteAll;
+ updateButtonState(currentOperatingButton, false); // Disable buttons, gray out write button
+
// 鏋勯�犳寚浠ら槦鍒�
cmdQueue.clear();
@@ -493,26 +752,19 @@
processNextCmd();
});
- btnReadData.setOnClickListener(v -> {
- if (BleGlobalManager.getInstance().isConnected()) {
- tvStatus.setText("鐘舵�侊細姝e湪璇诲彇鏁版嵁...");
- sendCmdWithCrc(CMD.READ_DATA);
- } else {
- Toast.makeText(getContext(), "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
- appendLog("閿欒: 钃濈墮鏈繛鎺�");
- }
- });
btnReadParam.setOnClickListener(v -> {
if (BleGlobalManager.getInstance().isConnected()) {
+ currentOperatingButton = btnReadParam;
+ updateButtonState(currentOperatingButton, false); // Disable buttons, gray out read button
tvStatus.setText("鐘舵�侊細姝e湪璇诲彇鍙傛暟...");
sendCmdWithCrc(CMD.READ_FLOORS);
new android.os.Handler().postDelayed(() -> {
sendCmdWithCrc(CMD.READ_STATION_NUM);
- }, 200);
+ }, 500);
new android.os.Handler().postDelayed(() -> {
sendCmdWithCrc(CMD.READ_BAUD_RATE);
- }, 400);
+ }, 1000);
} else {
Toast.makeText(getContext(), "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
appendLog("閿欒: 钃濈墮鏈繛鎺�");
@@ -526,6 +778,41 @@
});
}
+/**
+ * 鐩戞帶璇︽儏鏍囬鐐瑰嚮浜嬩欢
+ * <p>
+ * 鎵嬪姩瑙﹀彂鏁版嵁璇诲彇锛屼細璁板綍瀹屾暣鏃ュ織
+ * </p>
+ */
+ public void onMonitorTitleClick() {
+ try {
+ if (BleGlobalManager.getInstance() != null && BleGlobalManager.getInstance().isConnected()) {
+ if (tvStatus != null) {
+ tvStatus.setText("鐘舵�侊細姝e湪璇诲彇鏁版嵁...");
+ }
+ // 纭繚涓嶆槸鍛ㄦ湡鎬ц鍙栵紝浠ヤ究璁板綍鏃ュ織
+ isPeriodicRead = false;
+ sendCmdWithCrc(CMD.READ_DATA);
+ } else {
+ Context context = getContext();
+ if (context != null) {
+ Toast.makeText(context, "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
+ }
+ appendLog("閿欒: 钃濈墮鏈繛鎺�");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ appendLog("鐐瑰嚮鐩戞帶璇︽儏鏃跺彂鐢熼敊璇�: " + e.getMessage());
+ }
+ }
+
+/**
+ * 璁板綍鏅�氭棩蹇�
+ * <p>
+ * 灏嗘棩蹇椾俊鎭坊鍔犲埌鏃ュ織鏋勫缓鍣ㄥ苟鏄剧ず
+ * </p>
+ * @param msg 鏃ュ織鍐呭
+ */
private void appendLog(String msg) {
appendLog(msg, null);
}
@@ -579,13 +866,38 @@
return "";
}
+ private void updateButtonState(View btn, boolean enable) {
+ if (btn == null) return;
+ btn.setEnabled(enable);
+ if (enable) {
+ btn.getBackground().clearColorFilter();
+ } else {
+ btn.getBackground().setColorFilter(android.graphics.Color.GRAY, android.graphics.PorterDuff.Mode.MULTIPLY);
+ }
+ }
+
+ private void restoreCurrentButton() {
+ if (currentOperatingButton != null) {
+ updateButtonState(currentOperatingButton, true);
+ currentOperatingButton = null;
+ }
+ }
+
+/**
+ * 璁板綍鏃ュ織
+ * <p>
+ * 灏嗘棩蹇椾俊鎭坊鍔犲埌鏃ュ織鏋勫缓鍣ㄥ苟鏄剧ず锛屾敮鎸佸彂閫�/鎺ユ敹绫诲瀷鐨勫尯鍒�
+ * </p>
+ * @param msg 鏃ュ織鍐呭
+ * @param isSent true琛ㄧず鍙戦�佺殑鎸囦护锛宖alse琛ㄧず鎺ユ敹鐨勬暟鎹�
+ */
private void appendLog(String msg, Boolean isSent) {
String time = com.blankj.utilcode.util.TimeUtils.getNowString(new java.text.SimpleDateFormat("HH:mm:ss.SSS"));
String displayMsg = msg;
String cmdDesc = "";
- // 濡傛灉鏄� hex 鎸囦护 (绾� 0-9 A-F a-f)锛屽姞绌烘牸鏍煎紡鍖�
+ // 濡傛灉鏄崄鍏繘鍒舵寚浠� (绾� 0-9 A-F a-f)锛屽姞绌烘牸鏍煎紡鍖�
if (msg.matches("^[0-9A-Fa-f]+$")) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < msg.length(); i += 2) {
@@ -603,7 +915,7 @@
String logLine;
if (isSent != null) {
- String color = isSent ? "#1890ff" : "#05aa87"; // Blue for sent, Green for received
+ String color = isSent ? "#1890ff" : "#05aa87"; // 鍙戦�佷负钃濊壊锛屾帴鏀朵负缁胯壊
// 鎷兼帴鍒板墠缂�鍚庨潰: "鍙戦��-璇荤珯鍙�: " 鎴� "鏀跺埌-璇荤珯鍙�: "
String prefix = (isSent ? "鍙戦��" : "鏀跺埌") + cmdDesc + ": ";
logLine = time + " <font color='" + color + "'>" + prefix + displayMsg + "</font><br>";
@@ -621,6 +933,13 @@
}
}
+/**
+ * 鍙戦�佸甫 CRC 鏍¢獙鐨勬寚浠�
+ * <p>
+ * 璁$畻鎸囦护鐨� CRC 鏍¢獙鍊煎苟鍙戦�侊紝鍚屾椂璁板綍鏃ュ織
+ * </p>
+ * @param cmd 鍗佸叚杩涘埗鏍煎紡鐨勬寚浠ゅ唴瀹�
+ */
private void sendCmdWithCrc(String cmd) {
if (!BleGlobalManager.getInstance().isConnected()) {
Toast.makeText(getContext(), "璇峰厛杩炴帴钃濈墮", Toast.LENGTH_SHORT).show();
@@ -637,7 +956,7 @@
}
String fullCmd = cmd + crc.toUpperCase();
- appendLog(fullCmd, true); // true for sent (Blue)
+ appendLog(fullCmd, true); // true琛ㄧず鍙戦�佺殑鎸囦护锛堣摑鑹诧級
BleGlobalManager.getInstance().sendCmd(fullCmd);
} else {
appendLog("閿欒: 鎸囦护杞崲澶辫触");
@@ -655,14 +974,14 @@
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
- // Calculate Box ID based on 3 rows of 10, Right to Left logic as seen in image
- // Row 1 (pos 0-9): 10 ... 1
- // Row 2 (pos 10-19): 20 ... 11
- // Row 3 (pos 20-29): 30 ... 21
+ // 鏍规嵁3琛�10鍒楃殑缃戞牸锛屼粠宸﹀埌鍙宠绠楁牸瀛怚D
+ // 绗�1琛� (浣嶇疆0-9): 1 ... 10
+ // 绗�2琛� (浣嶇疆10-19): 11 ... 20
+ // 绗�3琛� (浣嶇疆20-29): 21 ... 30
int row = position / 10;
int col = position % 10;
- int boxId = (row + 1) * 10 - col;
+ int boxId = row * 10 + (col + 1);
holder.tvBoxNumber.setText(String.valueOf(boxId));
@@ -676,18 +995,18 @@
}
if (status != null) {
- // Priority: Online > Glass
- // User requirement: "浼樺厛鏄剧ず鏄惁鍦ㄧ嚎" (Prioritize displaying online status)
- // "19-26涓轰篃鏄�16杩涘埗锛岃В鏋愭垚浜岃繘鍒�32浠g爜鎴戣繖30涓牸瀛愭槸鍚﹀湪绾�"
- // Usually this means if offline, show offline color. If online, show state (glass/no glass).
+ // 浼樺厛绾�: 鍦ㄧ嚎鐘舵�� > 鐜荤拑鐘舵��
+ // 鐢ㄦ埛闇�姹�: "浼樺厛鏄剧ず鏄惁鍦ㄧ嚎"
+ // "19-26浣嶄篃鏄�16杩涘埗锛岃В鏋愭垚浜岃繘鍒�32浣嶈〃绀�30涓牸瀛愮殑鍦ㄧ嚎鐘舵��"
+ // 閫氬父鎰忓懗鐫�濡傛灉绂荤嚎锛屾樉绀虹绾块鑹诧紱濡傛灉鍦ㄧ嚎锛屾樉绀虹幓鐠冪姸鎬侊紙鏈�/鏃狅級
if (!status.isOnline) {
- holder.viewBox.setBackgroundResource(R.drawable.bg_box_offline); // Offline (Grey)
+ holder.viewBox.setBackgroundResource(R.drawable.bg_box_offline); // 绂荤嚎锛堢伆鑹诧級
} else {
if (status.hasGlass) {
- holder.viewBox.setBackgroundResource(R.drawable.bg_box_full); // Green
+ holder.viewBox.setBackgroundResource(R.drawable.bg_box_full); // 缁胯壊
} else {
- holder.viewBox.setBackgroundResource(R.drawable.bg_box_empty); // Online but empty (White)
+ holder.viewBox.setBackgroundResource(R.drawable.bg_box_empty); // 鍦ㄧ嚎浣嗘棤鐜荤拑锛堢櫧鑹诧級
}
}
}
diff --git a/app/src/main/res/drawable/ic_arrow_drop_down.xml b/app/src/main/res/drawable/ic_arrow_drop_down.xml
new file mode 100644
index 0000000..d3c5d77
--- /dev/null
+++ b/app/src/main/res/drawable/ic_arrow_drop_down.xml
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="#999999">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M7,10l5,5 5,-5H7z"/>
+</vector>
diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml
index eb9fcf1..189ffcf 100644
--- a/app/src/main/res/layout/activity_home.xml
+++ b/app/src/main/res/layout/activity_home.xml
@@ -70,6 +70,7 @@
android:orientation="vertical">
<TextView
+ android:id="@+id/tv_menu_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COMB"
@@ -112,8 +113,8 @@
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
- android:src="@mipmap/icon_record"
- app:tint="@color/drawer_item_text_gray" />
+ android:src="@mipmap/icon_1"
+ />
<TextView
android:layout_width="wrap_content"
@@ -131,14 +132,14 @@
android:layout_height="48dp"
android:gravity="center_vertical"
android:orientation="horizontal"
- android:paddingLeft="20dp"
+ android:paddingLeft="21dp"
android:paddingRight="20dp">
<ImageView
- android:layout_width="22dp"
- android:layout_height="22dp"
- android:src="@mipmap/ic_bluetooth"
- app:tint="@color/drawer_item_text_gray" />
+ android:layout_width="20dp"
+ android:layout_height="20dp"
+ android:src="@mipmap/icon_2"
+ />
<TextView
android:layout_width="wrap_content"
@@ -148,13 +149,6 @@
android:textColor="@color/drawer_item_text_gray"
android:textSize="15sp" />
</LinearLayout>
-
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:layout_marginTop="5dp"
- android:layout_marginBottom="5dp"
- android:background="@color/drawer_divider" />
<!-- 鍙傛暟璁惧畾 -->
<LinearLayout
@@ -169,8 +163,8 @@
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
- android:src="@mipmap/icon_topbar_overflow"
- app:tint="@color/drawer_item_text_gray" />
+ android:src="@mipmap/icon_3"
+ />
<TextView
android:layout_width="wrap_content"
@@ -181,12 +175,7 @@
android:textSize="15sp" />
</LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:layout_marginTop="5dp"
- android:layout_marginBottom="5dp"
- android:background="@color/drawer_divider" />
+
<!-- 褰撳墠璁惧 -->
<LinearLayout
@@ -201,8 +190,8 @@
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
- android:src="@mipmap/icon_topbar_about"
- app:tint="@color/drawer_item_text_gray" />
+ android:src="@mipmap/icon_4"
+ />
<TextView
android:layout_width="wrap_content"
@@ -226,8 +215,8 @@
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
- android:src="@mipmap/icon_topbar_overflow"
- app:tint="@color/drawer_item_text_gray" />
+ android:src="@mipmap/icon_5"
+ />
<TextView
android:layout_width="wrap_content"
@@ -238,6 +227,32 @@
android:textSize="15sp" />
</LinearLayout>
+ <!-- 绯荤粺璁剧疆 -->
+ <LinearLayout
+ android:id="@+id/menu_system_settings"
+ android:layout_width="match_parent"
+ android:layout_height="48dp"
+ android:gravity="center_vertical"
+ android:orientation="horizontal"
+ android:paddingLeft="20dp"
+ android:paddingRight="20dp"
+ android:visibility="gone">
+
+ <ImageView
+ android:layout_width="22dp"
+ android:layout_height="22dp"
+ android:src="@mipmap/icon_6"
+ />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="25dp"
+ android:text="绯荤粺璁剧疆"
+ android:textColor="@color/drawer_item_text_gray"
+ android:textSize="15sp" />
+ </LinearLayout>
+
</LinearLayout>
</ScrollView>
diff --git a/app/src/main/res/layout/activity_parameter_setting.xml b/app/src/main/res/layout/activity_parameter_setting.xml
index 2345e2e..1343871 100644
--- a/app/src/main/res/layout/activity_parameter_setting.xml
+++ b/app/src/main/res/layout/activity_parameter_setting.xml
@@ -39,7 +39,7 @@
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="16dp"
- android:background="#FAFAFA">
+ android:background="@color/white">
<View
android:layout_width="4dp"
@@ -103,7 +103,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="鑷鎴愬姛"
+ android:text="鎴愬姛"
android:textSize="12sp"
android:textColor="#666666"
android:layout_marginEnd="16dp"/>
@@ -116,7 +116,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="鑷澶辫触"
+ android:text="澶辫触"
android:textSize="12sp"
android:textColor="#666666"
android:layout_marginEnd="16dp"/>
@@ -147,11 +147,9 @@
android:layout_height="48dp"
android:layout_weight="1"
android:text="缁撴潫鑷"
- android:textColor="@color/base_color"
+ android:textColor="@color/white"
android:textSize="14sp"
- app:qmui_backgroundColor="@color/white"
- app:qmui_borderColor="@color/base_color"
- app:qmui_borderWidth="1dp"
+ app:qmui_backgroundColor="@color/base_color"
app:qmui_radius="8dp"
android:layout_marginLeft="10dp"/>
</LinearLayout>
@@ -189,15 +187,29 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
- <Spinner
- android:id="@+id/sp_threshold_mode"
+ <FrameLayout
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1.5"
- android:entries="@array/threshold_modes"
- android:background="@drawable/bg_input_field"
- android:paddingStart="10dp"
- android:layout_marginRight="10dp" />
+ android:layout_marginRight="10dp">
+
+ <Spinner
+ android:id="@+id/sp_threshold_mode"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:entries="@array/threshold_modes"
+ android:background="@drawable/bg_input_field"
+ android:paddingStart="10dp"
+ android:paddingEnd="32dp" />
+
+ <ImageView
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:src="@drawable/ic_arrow_drop_down"
+ android:layout_gravity="center_vertical|end"
+ android:layout_marginEnd="8dp"
+ android:importantForAccessibility="no"/>
+ </FrameLayout>
<EditText
android:id="@+id/et_threshold_value"
@@ -218,18 +230,6 @@
android:orientation="horizontal">
<com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
- android:id="@+id/btn_threshold_read"
- android:layout_width="0dp"
- android:layout_height="45dp"
- android:layout_weight="1"
- android:text="璇诲彇"
- android:textColor="@color/white"
- android:textSize="14sp"
- app:qmui_backgroundColor="@color/base_color"
- app:qmui_radius="8dp"
- android:layout_marginRight="10dp"/>
-
- <com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
android:id="@+id/btn_threshold_write"
android:layout_width="0dp"
android:layout_height="45dp"
@@ -237,7 +237,7 @@
android:text="鍐欏叆"
android:textColor="@color/white"
android:textSize="14sp"
- app:qmui_backgroundColor="@color/base_color_s"
+ app:qmui_backgroundColor="@color/base_color"
app:qmui_radius="8dp"/>
</LinearLayout>
</LinearLayout>
@@ -269,15 +269,29 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
- <Spinner
- android:id="@+id/sp_sensitivity_mode"
+ <FrameLayout
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1.5"
- android:entries="@array/sensitivity_modes"
- android:background="@drawable/bg_input_field"
- android:paddingStart="10dp"
- android:layout_marginRight="10dp" />
+ android:layout_marginRight="10dp">
+
+ <Spinner
+ android:id="@+id/sp_sensitivity_mode"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:entries="@array/sensitivity_modes"
+ android:background="@drawable/bg_input_field"
+ android:paddingStart="10dp"
+ android:paddingEnd="32dp" />
+
+ <ImageView
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:src="@drawable/ic_arrow_drop_down"
+ android:layout_gravity="center_vertical|end"
+ android:layout_marginEnd="8dp"
+ android:importantForAccessibility="no"/>
+ </FrameLayout>
<EditText
android:id="@+id/et_sensitivity_value"
@@ -298,18 +312,6 @@
android:orientation="horizontal">
<com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
- android:id="@+id/btn_sensitivity_read"
- android:layout_width="0dp"
- android:layout_height="45dp"
- android:layout_weight="1"
- android:text="璇诲彇"
- android:textColor="@color/white"
- android:textSize="14sp"
- app:qmui_backgroundColor="@color/base_color"
- app:qmui_radius="8dp"
- android:layout_marginRight="10dp"/>
-
- <com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
android:id="@+id/btn_sensitivity_write"
android:layout_width="0dp"
android:layout_height="45dp"
@@ -317,7 +319,7 @@
android:text="鍐欏叆"
android:textColor="@color/white"
android:textSize="14sp"
- app:qmui_backgroundColor="@color/base_color_s"
+ app:qmui_backgroundColor="@color/base_color"
app:qmui_radius="8dp"/>
</LinearLayout>
</LinearLayout>
@@ -356,7 +358,7 @@
android:text="涓绘澘澶嶄綅"
android:textColor="@color/white"
android:textSize="14sp"
- app:qmui_backgroundColor="@color/orange"
+ app:qmui_backgroundColor="@color/base_color"
app:qmui_radius="8dp"
android:layout_marginRight="10dp"/>
@@ -368,7 +370,7 @@
android:text="浼犳劅澶嶄綅"
android:textColor="@color/white"
android:textSize="14sp"
- app:qmui_backgroundColor="@color/orange"
+ app:qmui_backgroundColor="@color/base_color"
app:qmui_radius="8dp"
android:layout_marginLeft="10dp"/>
</LinearLayout>
@@ -377,6 +379,7 @@
<!-- Log Display -->
<androidx.cardview.widget.CardView
+ android:id="@+id/cv_log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="12dp"
diff --git a/app/src/main/res/layout/activity_system_settings.xml b/app/src/main/res/layout/activity_system_settings.xml
new file mode 100644
index 0000000..7ed978a
--- /dev/null
+++ b/app/src/main/res/layout/activity_system_settings.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/qmui_config_color_background"
+ android:orientation="vertical">
+
+ <include layout="@layout/include_head"/>
+
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView
+ android:id="@+id/groupListView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="20dp"/>
+
+ </ScrollView>
+
+</LinearLayout>
diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml
index 6dc124f..d9c4d1c 100644
--- a/app/src/main/res/layout/fragment_settings.xml
+++ b/app/src/main/res/layout/fragment_settings.xml
@@ -28,40 +28,40 @@
<!-- Card Header -->
<LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:gravity="center_vertical"
- android:padding="16dp"
- android:background="#FAFAFA">
-
- <View
- android:layout_width="4dp"
- android:layout_height="16dp"
- android:background="@color/base_color"
- android:layout_marginEnd="8dp"/>
-
- <TextView
- android:layout_width="0dp"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="鐩戞帶璇︽儏"
- android:textSize="16sp"
- android:textStyle="bold"
- android:textColor="#333333" />
-
- <com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
- android:id="@+id/btn_read_data"
- android:layout_width="wrap_content"
- android:layout_height="32dp"
- android:text="璇诲彇鏁版嵁"
- android:textColor="@color/white"
- android:textSize="12sp"
- android:paddingStart="12dp"
- android:paddingEnd="12dp"
- app:qmui_backgroundColor="@color/base_color"
- app:qmui_radius="4dp"/>
- </LinearLayout>
+ android:orientation="horizontal"
+ android:gravity="center_vertical"
+ android:padding="16dp"
+ android:background="@color/white">
+
+ <View
+ android:layout_width="4dp"
+ android:layout_height="16dp"
+ android:background="@color/base_color"
+ android:layout_marginEnd="8dp"/>
+
+ <TextView
+ android:id="@+id/tv_monitor_title"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="鐩戞帶璇︽儏"
+ android:textSize="16sp"
+ android:textStyle="bold"
+ android:textColor="#333333"
+ android:clickable="true"
+ android:focusable="true"
+ />
+
+ <TextView
+ android:id="@+id/tv_monitor_update_time"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text=""
+ android:textSize="12sp"
+ android:textColor="#999999"/>
+ </LinearLayout>
<View
android:layout_width="match_parent"
@@ -163,7 +163,7 @@
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="16dp"
- android:background="#FAFAFA">
+ android:background="@color/white">
<View
android:layout_width="4dp"
@@ -192,145 +192,144 @@
android:orientation="vertical"
android:padding="16dp">
- <!-- Layer Input -->
+ <!-- Grid Layout for Parameters -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="16dp">
-
+
+ <!-- Row 1: Labels -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
- android:gravity="center_vertical"
android:layout_marginBottom="8dp">
- <TextView
- android:layout_width="wrap_content"
+ <!-- Layer Label -->
+ <LinearLayout
+ android:layout_width="0dp"
android:layout_height="wrap_content"
- android:text="灞傛暟"
- android:textSize="14sp"
- android:textColor="#666666"/>
-
- <TextView
- android:id="@+id/tv_layer_status"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="10sp"
- android:layout_marginStart="8dp"/>
- </LinearLayout>
-
- <EditText
- android:id="@+id/et_layer"
- android:layout_width="match_parent"
- android:layout_height="48dp"
- android:background="@drawable/bg_input_field"
- android:paddingStart="16dp"
- android:paddingEnd="16dp"
- android:hint="灞傛暟 (1-30)"
- android:textColorHint="#CCCCCC"
- android:textSize="14sp"
- android:focusable="false"
- android:focusableInTouchMode="false"
- android:inputType="none"/>
- </LinearLayout>
+ android:layout_weight="1"
+ android:orientation="horizontal"
+ android:gravity="center">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="灞傛暟"
+ android:textSize="14sp"
+ android:textColor="#666666"/>
+ <TextView
+ android:id="@+id/tv_layer_status"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="10sp"
+ android:layout_marginStart="4dp"/>
+ </LinearLayout>
- <!-- Station Input -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:layout_marginBottom="16dp">
-
+ <!-- Station Label -->
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:orientation="horizontal"
+ android:gravity="center">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="绔欏彿"
+ android:textSize="14sp"
+ android:textColor="#666666"/>
+ <TextView
+ android:id="@+id/tv_station_status"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="10sp"
+ android:layout_marginStart="4dp"/>
+ </LinearLayout>
+
+ <!-- Baud Label -->
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1.5"
+ android:orientation="horizontal"
+ android:gravity="center">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="娉㈢壒鐜�"
+ android:textSize="14sp"
+ android:textColor="#666666"/>
+ <TextView
+ android:id="@+id/tv_baud_status"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="10sp"
+ android:layout_marginStart="4dp"/>
+ </LinearLayout>
+ </LinearLayout>
+
+ <!-- Row 2: Values -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
- android:gravity="center_vertical"
- android:layout_marginBottom="8dp">
+ android:gravity="center_vertical">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="绔欏彿"
- android:textSize="14sp"
- android:textColor="#666666"/>
+ <!-- Layer Value -->
+ <TextView
+ android:id="@+id/et_layer"
+ android:layout_width="0dp"
+ android:layout_height="48dp"
+ android:layout_weight="1"
+ android:background="@android:color/transparent"
+ android:gravity="center"
+ android:text="寰呰鍙�"
+ android:textSize="16sp"
+ android:textStyle="bold"
+ android:textColor="#999999"
+ android:layout_marginEnd="4dp"
+ />
- <TextView
- android:id="@+id/tv_station_status"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="10sp"
- android:layout_marginStart="8dp"/>
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
-
+ <!-- Station Value -->
<EditText
android:id="@+id/et_station"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:background="@drawable/bg_input_field"
- android:paddingStart="16dp"
- android:paddingEnd="16dp"
- android:hint="璇疯緭鍏ョ珯鍙� (1-64)"
+ android:gravity="center"
+ android:hint="绔欏彿"
android:textColorHint="#CCCCCC"
android:textSize="14sp"
- android:inputType="number"/>
-
- </LinearLayout>
- </LinearLayout>
+ android:inputType="number"
+ android:layout_marginStart="4dp"
+ android:layout_marginEnd="4dp"/>
- <!-- Baud Rate -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:gravity="center_vertical"
- android:layout_marginBottom="8dp">
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="娉㈢壒鐜�"
- android:textSize="14sp"
- android:textColor="#666666"/>
-
- <TextView
- android:id="@+id/tv_baud_status"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="10sp"
- android:layout_marginStart="8dp"/>
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
-
+ <!-- Baud Value -->
<FrameLayout
android:layout_width="0dp"
android:layout_height="48dp"
- android:layout_weight="1"
- android:background="@drawable/bg_input_field">
+ android:layout_weight="1.5"
+ android:background="@drawable/bg_input_field"
+ android:layout_marginStart="4dp">
<Spinner
android:id="@+id/spinner_baud"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
- android:paddingStart="8dp"/>
+ android:paddingEnd="32dp"
+ />
+
+ <ImageView
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:src="@drawable/ic_arrow_drop_down"
+ android:layout_gravity="center_vertical|end"
+ android:layout_marginEnd="8dp"
+ android:importantForAccessibility="no"/>
</FrameLayout>
</LinearLayout>
</LinearLayout>
@@ -364,7 +363,7 @@
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
- app:qmui_backgroundColor="@color/base_color_s"
+ app:qmui_backgroundColor="@color/base_color"
app:qmui_radius="8dp"/>
</LinearLayout>
@@ -384,6 +383,7 @@
<!-- Log Display -->
<androidx.cardview.widget.CardView
+ android:id="@+id/cv_log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="12dp"
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
index 34ed9da..10ce722 100644
--- a/app/src/main/res/mipmap-hdpi/ic_launcher.png
+++ b/app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
index 06cd83c..71cdd69 100644
--- a/app/src/main/res/mipmap-mdpi/ic_launcher.png
+++ b/app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
index 2552412..ab9efc3 100644
--- a/app/src/main/res/mipmap-xhdpi/ic_launcher.png
+++ b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/icon_1.png b/app/src/main/res/mipmap-xhdpi/icon_1.png
new file mode 100644
index 0000000..9221305
--- /dev/null
+++ b/app/src/main/res/mipmap-xhdpi/icon_1.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/icon_2.png b/app/src/main/res/mipmap-xhdpi/icon_2.png
new file mode 100644
index 0000000..7c82fe2
--- /dev/null
+++ b/app/src/main/res/mipmap-xhdpi/icon_2.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/icon_3.png b/app/src/main/res/mipmap-xhdpi/icon_3.png
new file mode 100644
index 0000000..d9b5445
--- /dev/null
+++ b/app/src/main/res/mipmap-xhdpi/icon_3.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/icon_4.png b/app/src/main/res/mipmap-xhdpi/icon_4.png
new file mode 100644
index 0000000..62d8d55
--- /dev/null
+++ b/app/src/main/res/mipmap-xhdpi/icon_4.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/icon_5.png b/app/src/main/res/mipmap-xhdpi/icon_5.png
new file mode 100644
index 0000000..ae7e096
--- /dev/null
+++ b/app/src/main/res/mipmap-xhdpi/icon_5.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/icon_6.png b/app/src/main/res/mipmap-xhdpi/icon_6.png
new file mode 100644
index 0000000..ac1828e
--- /dev/null
+++ b/app/src/main/res/mipmap-xhdpi/icon_6.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
index 90ee4ad..e1143f4 100644
--- a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
+++ b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
index 13151e9..d58bff4 100644
--- a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
+++ b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/values-land/dimens.xml b/app/src/main/res/values-land/dimens.xml
index 22d7f00..6b30d8d 100644
--- a/app/src/main/res/values-land/dimens.xml
+++ b/app/src/main/res/values-land/dimens.xml
@@ -1,3 +1,3 @@
<resources>
- <dimen name="fab_margin">48dp</dimen>
+
</resources>
\ No newline at end of file
diff --git a/app/src/main/res/values-w1240dp/dimens.xml b/app/src/main/res/values-w1240dp/dimens.xml
index d73f4a3..6b30d8d 100644
--- a/app/src/main/res/values-w1240dp/dimens.xml
+++ b/app/src/main/res/values-w1240dp/dimens.xml
@@ -1,3 +1,3 @@
<resources>
- <dimen name="fab_margin">200dp</dimen>
+
</resources>
\ No newline at end of file
diff --git a/app/src/main/res/values-w600dp/dimens.xml b/app/src/main/res/values-w600dp/dimens.xml
index 22d7f00..6b30d8d 100644
--- a/app/src/main/res/values-w600dp/dimens.xml
+++ b/app/src/main/res/values-w600dp/dimens.xml
@@ -1,3 +1,3 @@
<resources>
- <dimen name="fab_margin">48dp</dimen>
+
</resources>
\ No newline at end of file
--
Gitblit v1.9.3