Procházet zdrojové kódy

优化护理灯显示

weizhengliang před 3 roky
rodič
revize
1fb6feecc7

+ 64 - 37
callingbed/src/main/java/com/wdkl/app/ncs/callingbed/helper/SerialPortHelper.java

@@ -3,11 +3,20 @@ package com.wdkl.app.ncs.callingbed.helper;
 import com.wdkl.ncs.android.middleware.model.dto.NurseConfigDto;
 
 import java.util.ArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import serialporttest.utils.SerialPortUtil;
 import serialporttest.utils.StringUtils;
 
 public class SerialPortHelper {
+    private static int brightnessPercent;
+    private static ArrayList<NurseConfigDto> nurseConfigs;
+    private static boolean dismissLed;
+
+    private final static Object lockObject = new Object();
+    private final static ExecutorService threadPool = Executors.newSingleThreadExecutor();
+    private static NurseLedRunnable ledRunnable;
 
     //MIC设置
     public static void setHandsMIC(boolean isHandsMIC) {
@@ -86,11 +95,58 @@ public class SerialPortHelper {
     /**
      * 设置护理灯2
      */
-    public static void setNurseLedLight2(final int brightnessPercent, final ArrayList<NurseConfigDto> nurseConfigs) {
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
+    public static synchronized void setNurseLedLight2(final int brightness, final ArrayList<NurseConfigDto> configs) {
+        synchronized (lockObject) {
+            brightnessPercent = brightness;
+            nurseConfigs = configs;
+            dismissLed = false;
+
+            updateNurseLed();
+        }
+    }
+
+    /**
+     * 熄灭护理灯
+     */
+    public static synchronized void dismissNurseLedLight() {
+        synchronized (lockObject) {
+            dismissLed = true;
+
+            updateNurseLed();
+        }
+    }
+
+    private static String beComeDoubleStr(int b) {
+        if (b >= 0 && b < 10) {
+            return "0" + b;
+        } else if (b >= 10 && b < 100) {
+            return "" + b;
+        } else {
+            return "99";
+        }
+    }
+
+    private static void updateNurseLed() {
+        if (ledRunnable == null) {
+            ledRunnable = new NurseLedRunnable();
+        }
+        threadPool.execute(ledRunnable);
+    }
+
+    public static class NurseLedRunnable implements Runnable {
+        @Override
+        public void run() {
+            try {
+                if (dismissLed) {
+                    for (int i = 0; i < 5; i++) {
+                        SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NURSELIGHT + i, "000000", "F");
+                        Thread.sleep(300);
+                    }
+                } else {
+                    if (nurseConfigs == null) {
+                        return;
+                    }
+
                     float p = (float) brightnessPercent / 100;
                     int size = nurseConfigs.size();
                     //只有5个护理灯,超出无效
@@ -105,41 +161,12 @@ public class SerialPortHelper {
                             int bb = (int) ((StringUtils.parseHex2Int(StringUtils.substringByLengh(color, 4, 6))) * p);
                             SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NURSELIGHT + i, beComeDoubleStr(rr) + beComeDoubleStr(gg) + beComeDoubleStr(bb), "F");
                         }
-                        Thread.sleep(150);
+                        Thread.sleep(300);
                     }
-                } catch (Exception e) {
-                    e.printStackTrace();
                 }
+            } catch (Exception e) {
+                e.printStackTrace();
             }
-        }).start();
-    }
-
-    /**
-     * 熄灭护理灯
-     */
-    public static void dismissNurseLedLight() {
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    for (int i = 0; i < 5; i++) {
-                        SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NURSELIGHT + i, "000000", "F");
-                        Thread.sleep(150);
-                    }
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-        }).start();
-    }
-
-    private static String beComeDoubleStr(int b) {
-        if (b >= 0 && b < 10) {
-            return "0" + b;
-        } else if (b >= 10 && b < 100) {
-            return "" + b;
-        } else {
-            return "99";
         }
     }
 }

+ 0 - 3
welcome/src/main/AndroidManifest.xml

@@ -5,9 +5,6 @@
         android:allowBackup="true"
         android:label="@string/app_name"
         android:supportsRtl="true">
-        <activity android:name="com.wdkl.ncs.android.component.welcome.activity.WelcomeActivity"
-            >
-        </activity>
     </application>
 </manifest>