From 894af980153c32d0ca283be70f79e7d69389748b Mon Sep 17 00:00:00 2001 From: liup <1454939542@qq.com> Date: Fri, 29 Nov 2024 17:50:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=85=E5=8F=A3=E6=9C=9D=E5=90=91=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/ConfigName.java | 2 + .../adapter/FilePickerShowAdapter.java | 8 +- .../newui/activity/SystemSetActivity.java | 7 +- .../setting/WokDirectionSetFragment.java | 329 +++++++ .../new/layout/fragment_wok_direction_set.xml | 837 ++++++++++++++++++ app/src/main/res/mipmap-xxhdpi/status_y.png | Bin 0 -> 674 bytes app/src/main/res/mipmap-xxhdpi/status_z.png | Bin 0 -> 646 bytes 7 files changed, 1176 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/bonait/bnframework/newui/fragment/setting/WokDirectionSetFragment.java create mode 100644 app/src/main/res/layout/new/layout/fragment_wok_direction_set.xml create mode 100644 app/src/main/res/mipmap-xxhdpi/status_y.png create mode 100644 app/src/main/res/mipmap-xxhdpi/status_z.png diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java index 6e8195de..2b612a4e 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java @@ -217,6 +217,8 @@ public class ConfigName { add(new Res_PLCADDRESS("洗锅位置上限", "VD162", 0, 1)); add(new Res_PLCADDRESS("倒菜位置下限", "VD166", 0, 1)); add(new Res_PLCADDRESS("倒菜位置上限", "VD170", 0, 1)); + add(new Res_PLCADDRESS("维护位置下限", "VD1130", 0, 1)); + add(new Res_PLCADDRESS("维护位置上限", "VD1134", 0, 1)); add(new Res_PLCADDRESS("抽调料位置下限", "VD174", 0, 1)); add(new Res_PLCADDRESS("抽调料位置上限", "VD178", 0, 1)); add(new Res_PLCADDRESS("1#炒制位置下限", "VD182", 0, 1)); diff --git a/app/src/main/java/com/bonait/bnframework/common/filepicker/adapter/FilePickerShowAdapter.java b/app/src/main/java/com/bonait/bnframework/common/filepicker/adapter/FilePickerShowAdapter.java index e8087309..1b33c0d0 100644 --- a/app/src/main/java/com/bonait/bnframework/common/filepicker/adapter/FilePickerShowAdapter.java +++ b/app/src/main/java/com/bonait/bnframework/common/filepicker/adapter/FilePickerShowAdapter.java @@ -61,11 +61,11 @@ public class FilePickerShowAdapter extends RecyclerView.Adapter{ @@ -102,9 +103,9 @@ public class SystemSetActivity extends BaseActivity { */ private void initFragment() { FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager()); - fragmentAdapter.addFragment(new PicManagerFragment()); - fragmentAdapter.addFragment(new DeviceSetFragment()); fragmentAdapter.addFragment(new SceneSetFragment()); + fragmentAdapter.addFragment(new PicManagerFragment()); + fragmentAdapter.addFragment(new WokDirectionSetFragment()); fragmentAdapter.addFragment(new PlcAddressFragment()); viewBinding.viewpager.setAdapter(fragmentAdapter); diff --git a/app/src/main/java/com/bonait/bnframework/newui/fragment/setting/WokDirectionSetFragment.java b/app/src/main/java/com/bonait/bnframework/newui/fragment/setting/WokDirectionSetFragment.java new file mode 100644 index 00000000..0591ee2e --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/newui/fragment/setting/WokDirectionSetFragment.java @@ -0,0 +1,329 @@ +package com.bonait.bnframework.newui.fragment.setting; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.widget.EditText; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.bonait.bnframework.HBL.Thread.ThreadManager; +import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.base.BaseFragment; +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.utils.DisplayManager; +import com.bonait.bnframework.common.utils.PreferenceUtils; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.databinding.FragmentSystemDeviceBinding; +import com.bonait.bnframework.databinding.FragmentWokDirectionSetBinding; +import com.bonait.bnframework.modbus.ModbusCenter; +import com.bonait.bnframework.newui.widget.NewToastUtil; + +/** + * @author: liup + * @description: 设备信息设置 + * @date: 2024/6/13 11:05. + */ +public class WokDirectionSetFragment extends BaseFragment { + private FragmentWokDirectionSetBinding viewBinding; + private int deviceNum = 1; + private boolean visible = false; + private boolean isFresh = false; + + private Handler handler = new Handler(Looper.getMainLooper()){ + @Override + public void handleMessage(@NonNull Message msg) { + super.handleMessage(msg); + } + }; + @Override + protected View onCreateView() { + View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_wok_direction_set, null); + viewBinding = FragmentWokDirectionSetBinding .bind(root); + DisplayManager.scaleViewGroup(viewBinding.getRoot()); + return root; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initView(); + } + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if(isVisibleToUser){ + visible = true; + if(!isFresh){ + RefreshThread(); + } + }else { + visible = false; + } + } + + @SuppressLint("ClickableViewAccessibility") + private void initView(){ + ThreadManager.get().execute(new Runnable() { + @Override + public void run() { + isFresh = true; + while (!visible){ + try { + Object o0=ExecuteTheRecipe.ReadPLC(deviceNum,"编码器当前位值"); + Object o1=ExecuteTheRecipe.ReadPLC(deviceNum,"原点位反馈"); + Object o2=ExecuteTheRecipe.ReadPLC(deviceNum,"清洗位反馈"); + Object o3=ExecuteTheRecipe.ReadPLC(deviceNum,"倒菜位反馈"); + Object o4=ExecuteTheRecipe.ReadPLC(deviceNum,"抽料位反馈"); + Object o5=ExecuteTheRecipe.ReadPLC(deviceNum,"炒菜位1反馈"); + Object o6=ExecuteTheRecipe.ReadPLC(deviceNum,"炒菜位2反馈"); + Object o7=ExecuteTheRecipe.ReadPLC(deviceNum,"炒菜位3反馈"); + Object o8=ExecuteTheRecipe.ReadPLC(deviceNum,"维护位反馈"); + + if(handler!=null){ + handler.post(()->{ + if(o0!=null) { viewBinding.chaoguoWeizhi.setText(o0 + ""); } + else {viewBinding.chaoguoWeizhi.setText("未知");} + + if(o1!=null) { viewBinding.ydwStatus.setBackgroundResource((boolean)o1?R.mipmap.status_z:R.mipmap.status_y); } + else {viewBinding.ydwStatus.setBackgroundResource(R.mipmap.status_y); } + + if(o2!=null) { viewBinding.xgwStatus.setBackgroundResource((boolean)o2?R.mipmap.status_z:R.mipmap.status_y); } + else {viewBinding.xgwStatus.setBackgroundResource(R.mipmap.status_y); } + + if(o8!=null) { viewBinding.whwStatus.setBackgroundResource((boolean)o8?R.mipmap.status_z:R.mipmap.status_y); } + else {viewBinding.whwStatus.setBackgroundResource(R.mipmap.status_y); } + + if(o3!=null) { viewBinding.ccwStatus.setBackgroundResource((boolean)o3?R.mipmap.status_z:R.mipmap.status_y); } + else {viewBinding.ccwStatus.setBackgroundResource(R.mipmap.status_y); } + + if(o4!=null) { viewBinding.ctlStatus.setBackgroundResource((boolean)o4?R.mipmap.status_z:R.mipmap.status_y); } + else {viewBinding.ctlStatus.setBackgroundResource(R.mipmap.status_y); } + + if(o5!=null) { viewBinding.czw1Status.setBackgroundResource((boolean)o5?R.mipmap.status_z:R.mipmap.status_y); } + else {viewBinding.czw1Status.setBackgroundResource(R.mipmap.status_y); } + + if(o6!=null) { viewBinding.czw2Status.setBackgroundResource((boolean)o6?R.mipmap.status_z:R.mipmap.status_y); } + else {viewBinding.czw2Status.setBackgroundResource(R.mipmap.status_y); } + + if(o7!=null) { viewBinding.czw3Status.setBackgroundResource((boolean)o7?R.mipmap.status_z:R.mipmap.status_y); } + else {viewBinding.czw3Status.setBackgroundResource(R.mipmap.status_y); } + }); + } + Thread.sleep(500); + }catch (Exception e){ + + } + } + isFresh = false; + } + }); + + viewBinding.gkzxButton.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { + Log.e("鼠标", "按下: "); + ExecuteTheRecipe.WritePLC(deviceNum,"转动速度", 50, null); + ExecuteTheRecipe.WritePLC(deviceNum,"翻转正转", true, null); + } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { + Log.e("鼠标", "松开: "); + ExecuteTheRecipe.WritePLC(deviceNum,"翻转正转", false, null); + } + return false; + } + }); + + viewBinding.gkfxButton.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { + Log.e("鼠标", "按下: "); + ExecuteTheRecipe.WritePLC(deviceNum,"转动速度", 50,null); + ExecuteTheRecipe.WritePLC(deviceNum,"翻转反转", true, null); + } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { + Log.e("鼠标", "松开: "); + ExecuteTheRecipe.WritePLC(deviceNum,"翻转反转", false, null); + } + return false; + } + }); + + viewBinding.deviceNumSave.setOnClickListener(v->{ + String num = viewBinding.edtDeviceNum.getText().toString(); + if(num.equals("2")){ + deviceNum = 2; + }else if(num.equals("1")){ + deviceNum = 1; + }else { + NewToastUtil.getInstance().showToastError("请输入有效设备号!"); + return; + } + viewBinding.tvDeviceNum.setText(deviceNum+"号设备"); + }); + + viewBinding.ydwSave.setOnClickListener(v->{ + SaveValue("原点位置",viewBinding.editYdw1,viewBinding.editYdw2); + }); + viewBinding.xgwSave.setOnClickListener(v->{ + SaveValue("洗锅位置",viewBinding.editXgw1,viewBinding.editXgw2); + }); + viewBinding.whwSave.setOnClickListener(v->{ + SaveValue("维护位置",viewBinding.editWhw1,viewBinding.editWhw2); + }); + viewBinding.ydwSave.setOnClickListener(v->{ + SaveValue("原点位置",viewBinding.editYdw1,viewBinding.editYdw2); + }); + viewBinding.ccwSave.setOnClickListener(v->{ + SaveValue("倒菜位置",viewBinding.editCcw1,viewBinding.editCcw2); + }); + viewBinding.ctlSave.setOnClickListener(v->{ + SaveValue("抽调料位置",viewBinding.editCtl1,viewBinding.editCtl2); + }); + viewBinding.czw1Save.setOnClickListener(v->{ + SaveValue("1#炒制位置",viewBinding.editCzw11,viewBinding.editCzw12); + }); + viewBinding.czw2Save.setOnClickListener(v->{ + SaveValue("2#炒制位置",viewBinding.editCzw21,viewBinding.editCzw22); + }); + viewBinding.czw3Save.setOnClickListener(v->{ + SaveValue("3#炒制位置",viewBinding.editCzw31,viewBinding.editCzw32); + }); + viewBinding.gzfwSave.setOnClickListener(v->{ + SaveValue("炒锅工作范围",viewBinding.editGzfw1,viewBinding.editGzfw2); + }); + + + viewBinding.ydwButton.setOnClickListener(v->{ + ButtomZhiWeiZhi("原点位"); + }); + viewBinding.xgwButton.setOnClickListener(v->{ + ButtomZhiWeiZhi("清洗位"); + }); + viewBinding.whwButton.setOnClickListener(v->{ + ButtomZhiWeiZhi("维护位"); + }); + viewBinding.ctlButton.setOnClickListener(v->{ + ButtomZhiWeiZhi("抽料位"); + }); + viewBinding.czw1Button.setOnClickListener(v->{ + ButtomZhiWeiZhi("炒菜位1"); + }); + viewBinding.czw2Button.setOnClickListener(v->{ + ButtomZhiWeiZhi("炒菜位2"); + }); + viewBinding.czw3Button.setOnClickListener(v->{ + ButtomZhiWeiZhi("炒菜位3"); + }); + + + } + + /** + * 刷新UI线程 + */ + public void RefreshThread() + { + ThreadManager.get().execute(new Runnable() { + @Override + public void run() { + SetShowValue("原点位置",viewBinding.editYdw1,viewBinding.editYdw2); + SetShowValue("洗锅位置",viewBinding.editXgw1,viewBinding.editXgw2); + SetShowValue("维护位置",viewBinding.editWhw1,viewBinding.editWhw2); + SetShowValue("倒菜位置",viewBinding.editCcw1,viewBinding.editCcw2); + SetShowValue("抽调料位置",viewBinding.editCtl1,viewBinding.editCtl2); + SetShowValue("1#炒制位置",viewBinding.editCzw11,viewBinding.editCzw12); + SetShowValue("2#炒制位置",viewBinding.editCzw21,viewBinding.editCzw22); + SetShowValue("3#炒制位置",viewBinding.editCzw31,viewBinding.editCzw32); + SetShowValue("炒锅工作范围",viewBinding.editGzfw1,viewBinding.editGzfw2); + } + }); + + } + + /** + * 根据监听设置值 + * @param name + * @param edit1 + * @param edit2 + */ + private void SetShowValue(String name, EditText edit1, EditText edit2) + { + Object val1= ModbusCenter.ReadPlc(deviceNum,name+"下限"); + Object val2=ModbusCenter.ReadPlc(deviceNum,name+"上限"); + if(handler!=null){ + handler.post(()->{ + if(val1!=null) + { + String str=String.valueOf(val1); + edit1.setText(str.toCharArray(), 0, str.length()); + } + + if(val2!=null) + { + String str=String.valueOf(val2); + edit2.setText(str.toCharArray(), 0, str.length()); + } + }); + } + } + + + /** + * 写入设置值 + * @param name + * @param edit1 + * @param edit2 + */ + private void SaveValue(String name,EditText edit1,EditText edit2) { + String val1 = edit1.getText().toString(); + String val2 = edit2.getText().toString(); + if (val1.isEmpty()) { + NewToastUtil.getInstance().showToastError(name + "下限不能为空!"); + return; + } + if (val2.isEmpty()) { + NewToastUtil.getInstance().showToastError(name + "上限不能为空!"); + return; + } + int va1 = 0; + int va2 = 0; + try { + va1=Integer.parseInt(val1); + va2=Integer.parseInt(val2); + } catch (Exception ex) + { + NewToastUtil.getInstance().showToastError(name + "异常了,"+ex.getMessage()); + return; + } + + ExecuteTheRecipe.WritePLC(deviceNum,name+"下限",va1,null); + ExecuteTheRecipe.WritePLC(deviceNum,name+"上限",va2,null); + NewToastUtil.getInstance().showToast(name + "-保存成功!"); + } + + /** + * 执行去某个位置 + */ + private void ButtomZhiWeiZhi(String name) + { + ExecuteTheRecipe.WritePLC(deviceNum,name,true,null); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + ExecuteTheRecipe.WritePLC(deviceNum,name, false, null); + } + }, 500); + NewToastUtil.getInstance().showToast(name+"-执行成功!"); + } + +} diff --git a/app/src/main/res/layout/new/layout/fragment_wok_direction_set.xml b/app/src/main/res/layout/new/layout/fragment_wok_direction_set.xml new file mode 100644 index 00000000..4745f667 --- /dev/null +++ b/app/src/main/res/layout/new/layout/fragment_wok_direction_set.xml @@ -0,0 +1,837 @@ + + + + + + + + + + + + +