| | |
| | | private TextView tv_sensor_status; |
| | | private StringBuilder logBuilder = new StringBuilder(); |
| | | private String currentExecutingCmd = ""; |
| | | private View currentOperatingButton; |
| | | |
| | | |
| | | @Override |
| | | protected void contentView() { |
| | |
| | | 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); |
| | |
| | | } |
| | | } |
| | | |
| | | 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) { |
| | |
| | | |
| | | // 写入指令的返回 (A55A06开头) |
| | | if (hex.startsWith("A55A06") && hex.length() >= 12) { |
| | | restoreCurrentButton(); |
| | | parseWriteResponse(hex); |
| | | return; |
| | | } |
| | | |
| | | // 读取指令的返回 (A55A03开头) |
| | | if (hex.startsWith("A55A03") && hex.length() >= 8) { |
| | | restoreCurrentButton(); |
| | | parseReadResponse(hex); |
| | | } |
| | | } |