Explorar o código

A133门口机增加串口功能配置

weizhengliang hai 10 meses
pai
achega
d31ae8af01

+ 62 - 0
android_door/src/main/h10_3128/java/com/wdkl/app/ncs/callingdoor/adapter/SerialPortAdapter.java

@@ -0,0 +1,62 @@
+package com.wdkl.app.ncs.callingdoor.adapter;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import com.wdkl.app.ncs.callingdoor.R;
+
+import java.util.List;
+
+public class SerialPortAdapter extends BaseAdapter {
+
+    private Context context;
+    private List<String> serialPortList;
+
+    public SerialPortAdapter(Context context, List<String> list) {
+        this.context = context;
+        this.serialPortList = list;
+    }
+
+    @Override
+    public int getCount() {
+        return serialPortList.size();
+    }
+
+    @Override
+    public Object getItem(int position) {
+        return serialPortList.get(position);
+    }
+
+    @Override
+    public long getItemId(int position) {
+        return position;
+    }
+
+    @Override
+    public View getView(int position, View convertView, ViewGroup parent) {
+
+        ViewHolder holder = null;
+
+        if (convertView == null) {
+            convertView = View.inflate(context, R.layout.frame_item, null);
+
+            holder = new ViewHolder();
+            holder.tv = (TextView) convertView.findViewById(R.id.tv_frame_name);
+
+            convertView.setTag(holder);
+        } else {
+            holder = (ViewHolder) convertView.getTag();
+        }
+
+        holder.tv.setText(serialPortList.get(position));
+
+        return convertView;
+    }
+
+    static class ViewHolder {
+        private TextView tv;
+    }
+}

+ 6 - 0
android_door/src/main/h10_3128/java/com/wdkl/app/ncs/callingdoor/fragment/QrCodeFragment.kt

@@ -205,6 +205,12 @@ class QrCodeFragment : BaseFragment<QrCodeFragmentPresenter, QrCodeLayBinding>()
             }
             clickTime = System.currentTimeMillis()
         }
+
+        tv_serial_port_config.setOnClickListener {
+            PasswordDialogHelper.showPasswordDialog(activity) {
+                SerialPortConfigDialogHelper.showDialog(activity)
+            }
+        }
     }
 
     override fun destory() {

+ 119 - 0
android_door/src/main/h10_3128/java/com/wdkl/app/ncs/callingdoor/helper/SerialPortConfigDialogHelper.java

@@ -0,0 +1,119 @@
+package com.wdkl.app.ncs.callingdoor.helper;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.Toast;
+
+import com.wdkl.app.ncs.callingdoor.R;
+import com.wdkl.app.ncs.callingdoor.adapter.SerialPortAdapter;
+import com.wdkl.ncs.android.lib.base.BaseApplication;
+import com.wdkl.ncs.android.lib.settings.SettingConfig;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static com.wdkl.ncs.android.lib.utils.ExtendMethodsKt.showMessage;
+
+public class SerialPortConfigDialogHelper {
+
+    private static AlertDialog alertDialog;
+    private static final ArrayList<String> serialPorts = new ArrayList<>(Arrays.asList("/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2"));
+    private static String selectPanelKeySerial, select433Serial;
+
+    public static void showDialog(Activity activity) {
+        View contentView = LayoutInflater.from(activity).inflate(R.layout.serial_port_config_dialog, null);
+        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+        builder.setView(contentView);
+        LinearLayout layout = contentView.findViewById(R.id.ll_serial_config_view);
+        Spinner panelKeySpinner = contentView.findViewById(R.id.spinner_keys);
+        Spinner s433Spinner = contentView.findViewById(R.id.spinner_433);
+        Button cancelButton = contentView.findViewById(R.id.cancel_button);
+        Button confirmButton = contentView.findViewById(R.id.confirm_button);
+
+        layout.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                try {
+                    Utils.hideInputKeyboard(alertDialog.getWindow().getDecorView().getWindowToken());
+                } catch (Exception e) {
+                    //
+                }
+            }
+        });
+
+        String panelKeysSerial = SettingConfig.getPanelKeySerialPort(BaseApplication.appContext);
+        String s433Serial = SettingConfig.get433SerialPort(BaseApplication.appContext);
+
+        SerialPortAdapter panelKeyAdapter = new SerialPortAdapter(activity, serialPorts);
+        panelKeySpinner.setAdapter(panelKeyAdapter);
+        panelKeySpinner.setSelection(serialPorts.indexOf(panelKeysSerial));
+        panelKeySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+            @Override
+            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+                selectPanelKeySerial = serialPorts.get(position);
+            }
+
+            @Override
+            public void onNothingSelected(AdapterView<?> parent) {
+
+            }
+        });
+
+        SerialPortAdapter s433Adapter = new SerialPortAdapter(activity, serialPorts);
+        s433Spinner.setAdapter(s433Adapter);
+        s433Spinner.setSelection(serialPorts.indexOf(s433Serial));
+        s433Spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+            @Override
+            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+                select433Serial = serialPorts.get(position);
+            }
+
+            @Override
+            public void onNothingSelected(AdapterView<?> parent) {
+
+            }
+        });
+
+        cancelButton.setOnClickListener(v -> {
+            if (alertDialog != null) {
+                alertDialog.dismiss();
+            }
+        });
+
+        confirmButton.setOnClickListener(v -> {
+            if (!TextUtils.isEmpty(selectPanelKeySerial) && !TextUtils.isEmpty(select433Serial)
+                    && !selectPanelKeySerial.equals(select433Serial)) {
+                SettingConfig.setPanelKeySerialPort(BaseApplication.appContext, selectPanelKeySerial);
+                SettingConfig.set433SerialPort(BaseApplication.appContext, select433Serial);
+
+                if (alertDialog != null ) {
+                    alertDialog.dismiss();
+                }
+
+                Toast.makeText(activity, "restart now...", Toast.LENGTH_LONG).show();
+                new Handler().postDelayed(new Runnable() {
+                    @Override
+                    public void run() {
+                        AppUpdateHelper.restartApp(BaseApplication.appContext);
+                    }
+                }, 3000);
+            } else {
+                showMessage("select error!");
+            }
+        });
+
+        alertDialog = builder.create();
+        alertDialog.setCanceledOnTouchOutside(true);
+        alertDialog.setCancelable(true);
+        alertDialog.show();
+
+    }
+}

+ 20 - 0
android_door/src/main/h10_3128/res/layout/frame_item.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_height="40dp"
+    android:layout_width="match_parent"
+    android:orientation="vertical">
+
+    <TextView
+        android:id="@+id/tv_frame_name"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="8dp"
+        android:text="--"
+        android:textSize="22sp" />
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:background="@color/black"
+        android:layout_marginBottom="10dp"/>
+</LinearLayout>

+ 13 - 0
android_door/src/main/h10_3128/res/layout/qr_code_lay.xml

@@ -159,6 +159,19 @@
                     android:textSize="24sp" />
 
                 <TextView
+                    android:id="@+id/tv_serial_port_config"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="10dp"
+                    android:padding="10dp"
+                    android:background="?attr/myBackgroundColor"
+                    android:gravity="center_horizontal"
+                    android:singleLine="true"
+                    android:text="@string/serial_port_config"
+                    android:textColor="@drawable/selector_bottom_btn_text_color"
+                    android:textSize="24sp" />
+
+                <TextView
                     android:id="@+id/tv_btn_power_reset"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"

+ 107 - 0
android_door/src/main/h10_3128/res/layout/serial_port_config_dialog.xml

@@ -0,0 +1,107 @@
+<?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:gravity="center"
+    android:background="@android:color/transparent">
+
+    <LinearLayout
+        android:id="@+id/ll_serial_config_view"
+        android:layout_width="480dp"
+        android:layout_height="448dp"
+        android:background="@color/white"
+        android:gravity="center"
+        android:orientation="vertical">
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="23dp"
+            android:gravity="center"
+            android:text="@string/serial_port_config"
+            android:textColor="@color/black"
+            android:textSize="@dimen/font_size_18"
+            android:textStyle="bold" />
+
+        <LinearLayout
+            android:layout_width="380dp"
+            android:layout_height="52dp"
+            android:layout_marginTop="24dp"
+            android:gravity="center_vertical"
+            android:orientation="horizontal">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/serial_port_panel_keys"
+                android:textColor="@color/black"
+                android:textSize="@dimen/font_size_18"
+                android:textStyle="bold" />
+
+            <Spinner
+                android:id="@+id/spinner_keys"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:layout_marginStart="20dp"
+                android:gravity="center_vertical"
+                android:spinnerMode="dropdown" />
+
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="380dp"
+            android:layout_height="52dp"
+            android:layout_marginTop="10dp"
+            android:gravity="center_vertical"
+            android:orientation="horizontal">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/serial_port_433"
+                android:textColor="@color/black"
+                android:textSize="@dimen/font_size_18"
+                android:textStyle="bold" />
+
+            <Spinner
+                android:id="@+id/spinner_433"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:layout_marginStart="20dp"
+                android:gravity="center_vertical"
+                android:spinnerMode="dropdown" />
+
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="380dp"
+            android:layout_height="52dp"
+            android:layout_marginTop="24dp"
+            android:layout_marginBottom="40dp"
+            android:gravity="center_vertical"
+            android:orientation="horizontal">
+
+            <Button
+                android:id="@+id/cancel_button"
+                android:layout_width="176dp"
+                android:layout_height="48dp"
+                android:background="@drawable/shape_callconfig_bt_bg"
+                android:gravity="center"
+                android:text="@string/str_cancel"
+                android:textColor="@drawable/selector_bottom_btn_text_color"
+                android:textSize="16sp" />
+
+            <Button
+                android:id="@+id/confirm_button"
+                android:layout_width="176dp"
+                android:layout_height="48dp"
+                android:layout_marginLeft="30dp"
+                android:background="@drawable/shape_main_hos_txt_bg"
+                android:gravity="center"
+                android:text="@string/str_confirm"
+                android:textColor="@drawable/selector_bottom_btn_text_color"
+                android:textSize="16sp" />
+        </LinearLayout>
+    </LinearLayout>
+
+</LinearLayout>

+ 13 - 3
app/src/main/code/com/wdkl/app/ncs/application/Application.kt

@@ -3,6 +3,7 @@ package com.wdkl.app.ncs.application
 import android.content.Context
 import android.content.res.Configuration
 import android.os.Build
+import android.text.TextUtils
 import android.util.Log
 import com.enation.javashop.android.jrouter.JRouter
 import com.wdkl.ncs.android.lib.base.BaseApplication
@@ -98,7 +99,7 @@ class Application : BaseApplication() {
             }
 
             //打开433串口0
-            SerialPortUtil433.getInstance().openSerialPort()
+            SerialPortUtil433.getInstance().openSerialPort("/dev/ttyS0")
 
             //卸载原来二代系统apk
             if (uninstallApk) {
@@ -114,10 +115,19 @@ class Application : BaseApplication() {
                 SerialPortUtil.getInstance().openSerialPort("/dev/ttyS0")
             } else {
                 //志合A133主板
-                SerialPortUtil.getInstance().openSerialPort("/dev/ttyS2")
+                //功能板串口
+                if (!TextUtils.isEmpty(SettingConfig.getPanelKeySerialPort(baseContext))) {
+                    SerialPortUtil.getInstance().openSerialPort(SettingConfig.getPanelKeySerialPort(baseContext))
+                } else {
+                    SerialPortUtil.getInstance().openSerialPort("/dev/ttyS2")
+                }
 
                 //打开433串口0
-                SerialPortUtil433.getInstance().openSerialPort()
+                if (!TextUtils.isEmpty(SettingConfig.get433SerialPort(baseContext))) {
+                    SerialPortUtil433.getInstance().openSerialPort(SettingConfig.get433SerialPort(baseContext))
+                } else {
+                    SerialPortUtil433.getInstance().openSerialPort("/dev/ttyS0")
+                }
             }
         }
 

+ 1 - 1
bedlib/src/main/java/serialporttest/utils/SerialPortUtil.java

@@ -57,7 +57,7 @@ public class SerialPortUtil {
      * 打开串口的方法
      */
     public void openSerialPort(String path) {
-        Log.i(TAG, "打开串口...");
+        Log.i(TAG, "打开功能板串口...");
         try {
             serialPort = new SerialPort();
             serialPort.setCallback(new SerialPort.Callback() {

+ 5 - 5
bedlib/src/main/java/serialporttest/utils/SerialPortUtil433.java

@@ -40,8 +40,8 @@ public class SerialPortUtil433 {
     /**
      * 打开串口的方法
      */
-    public void openSerialPort() {
-        Log.i(TAG, "打开串口0");
+    public void openSerialPort(String path) {
+        Log.i(TAG, "打开433串口");
         try {
             serialPort = new SerialPort();
             serialPort.setCallback(new SerialPort.Callback() {
@@ -52,14 +52,14 @@ public class SerialPortUtil433 {
                     outputStream = serialPort.getOutputStream();
                     isOpenSerialPortUtil = true;
 
-                    Log.i(TAG, "open openSerialPort0 success...");
+                    Log.i(TAG, "open " + path + " success...");
                     receiveSerialPort();
                 }
             });
-            serialPort.open(new File("/dev/ttyS0"), 115200, 0);
+            serialPort.open(new File(path), 115200, 0);
         } catch (Exception e) {
             e.printStackTrace();
-            Log.e(TAG, "open openSerialPort0 failed...");
+            Log.i(TAG, "open " + path + " failed...");
         }
     }
 

+ 27 - 0
common/src/main/code/com/wdkl/ncs/android/lib/settings/SettingConfig.java

@@ -2,6 +2,7 @@ package com.wdkl.ncs.android.lib.settings;
 
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.text.TextUtils;
 
 import com.wdkl.ncs.android.lib.BuildConfig;
 
@@ -85,6 +86,10 @@ public class SettingConfig {
     //开关机压力测试
     private static final String KEY_SP_REBOOT_TEST = "KEY_SP_REBOOT_TEST";
 
+    //串口路径
+    private static final String KEY_SP_PANEL_KEY_SERIAL_PORT = "KEY_SP_PANEL_KEY_SERIAL_PORT";
+    private static final String KEY_SP_433_SERIAL_PORT = "KEY_SP_433_SERIAL_PORT";
+
     public static void setMIC(Context context, int mode) {
         getEditor(context).putInt(KEY_SP_MIC_ENABLE, mode).apply();
     }
@@ -193,6 +198,28 @@ public class SettingConfig {
         getEditor(context).putBoolean(KEY_SP_REBOOT_TEST, enable).apply();
     }
 
+    public static String getPanelKeySerialPort(Context context) {
+        //按键板串口默认为ttyS2
+        return getSP(context).getString(KEY_SP_PANEL_KEY_SERIAL_PORT, "/dev/ttyS2");
+    }
+
+    public static void setPanelKeySerialPort(Context context, String path) {
+        if (!TextUtils.isEmpty(path)) {
+            getEditor(context).putString(KEY_SP_PANEL_KEY_SERIAL_PORT, path).apply();
+        }
+    }
+
+    public static String get433SerialPort(Context context) {
+        //433串口默认为ttyS0
+        return getSP(context).getString(KEY_SP_433_SERIAL_PORT, "/dev/ttyS0");
+    }
+
+    public static void set433SerialPort(Context context, String path) {
+        if (!TextUtils.isEmpty(path)) {
+            getEditor(context).putString(KEY_SP_433_SERIAL_PORT, path).apply();
+        }
+    }
+
     /**
      * 获取白天亮度
      *

+ 4 - 0
resource/src/main/res/values-es/strings.xml

@@ -260,4 +260,8 @@
 
     <string name="reboot_test">Reboot test…</string>
     <string name="str_exit">Exit</string>
+
+    <string name="serial_port_config">Serial port config</string>
+    <string name="serial_port_panel_keys">Panel keys:</string>
+    <string name="serial_port_433">433:</string>
 </resources>

+ 4 - 0
resource/src/main/res/values-ru/strings.xml

@@ -246,4 +246,8 @@
 
     <string name="reboot_test">Reboot test…</string>
     <string name="str_exit">Exit</string>
+
+    <string name="serial_port_config">Serial port config</string>
+    <string name="serial_port_panel_keys">Panel keys:</string>
+    <string name="serial_port_433">433:</string>
 </resources>

+ 4 - 0
resource/src/main/res/values-zh/strings.xml

@@ -259,4 +259,8 @@
 
     <string name="reboot_test">设备开关机测试中…</string>
     <string name="str_exit">退出</string>
+
+    <string name="serial_port_config">串口设置</string>
+    <string name="serial_port_panel_keys">按键板:</string>
+    <string name="serial_port_433">433:</string>
 </resources>

+ 4 - 0
resource/src/main/res/values/strings.xml

@@ -258,4 +258,8 @@
 
     <string name="reboot_test">Reboot test…</string>
     <string name="str_exit">Exit</string>
+
+    <string name="serial_port_config">Serial port config</string>
+    <string name="serial_port_panel_keys">Panel keys:</string>
+    <string name="serial_port_433">433:</string>
 </resources>