|
@@ -1,6 +1,11 @@
|
|
|
package com.wdkl.app.ncs.callingbed.helper;
|
|
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.dto.NurseConfigDto;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
import serialporttest.utils.SerialPortUtil;
|
|
|
+import serialporttest.utils.StringUtils;
|
|
|
|
|
|
public class SerialPortHelper {
|
|
|
|
|
@@ -26,4 +31,110 @@ public class SerialPortHelper {
|
|
|
public static void resetDevice() {
|
|
|
SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NET_STATUS , "1", "F");
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置护理灯
|
|
|
+ */
|
|
|
+ public static void setNurseLedLight(final int brightnessPercent, final String oneColor, final String twoColor, final String threeColor, final String fourColor, final String fiveColor) {
|
|
|
+ //需要在子线程中设置
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ float p = (float) brightnessPercent / 100;
|
|
|
+ if (StringUtils.notEmpty(oneColor)) {
|
|
|
+ int rr = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(oneColor, 0, 2))) * p);
|
|
|
+ int gg = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(oneColor, 2, 4))) * p);
|
|
|
+ int bb = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(oneColor, 4, 6))) * p);
|
|
|
+ SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NURSELIGHT + "0", beComeDoubleStr(rr) + beComeDoubleStr(gg) + beComeDoubleStr(bb), "F");
|
|
|
+ }
|
|
|
+ Thread.sleep(300);
|
|
|
+ if (StringUtils.notEmpty(twoColor)) {
|
|
|
+ int rr = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(twoColor, 0, 2))) * p);
|
|
|
+ int gg = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(twoColor, 2, 4))) * p);
|
|
|
+ int bb = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(twoColor, 4, 6))) * p);
|
|
|
+ SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NURSELIGHT + "1", beComeDoubleStr(rr) + beComeDoubleStr(gg) + beComeDoubleStr(bb), "F");
|
|
|
+ }
|
|
|
+ Thread.sleep(300);
|
|
|
+ if (StringUtils.notEmpty(threeColor)) {
|
|
|
+ int rr = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(threeColor, 0, 2))) * p);
|
|
|
+ int gg = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(threeColor, 2, 4))) * p);
|
|
|
+ int bb = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(threeColor, 4, 6))) * p);
|
|
|
+ SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NURSELIGHT + "2", beComeDoubleStr(rr) + beComeDoubleStr(gg) + beComeDoubleStr(bb), "F");
|
|
|
+ }
|
|
|
+ Thread.sleep(300);
|
|
|
+ if (StringUtils.notEmpty(fourColor)) {
|
|
|
+ int rr = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(fourColor, 0, 2))) * p);
|
|
|
+ int gg = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(fourColor, 2, 4))) * p);
|
|
|
+ int bb = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(fourColor, 4, 6))) * p);
|
|
|
+ SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NURSELIGHT + "3", beComeDoubleStr(rr) + beComeDoubleStr(gg) + beComeDoubleStr(bb), "F");
|
|
|
+ }
|
|
|
+ Thread.sleep(300);
|
|
|
+ if (StringUtils.notEmpty(fiveColor)) {
|
|
|
+ int rr = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(fiveColor, 0, 2))) * p);
|
|
|
+ int gg = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(fiveColor, 2, 4))) * p);
|
|
|
+ int bb = (int) ((StringUtils.parseFloat(StringUtils.substringByLengh(fiveColor, 4, 6))) * p);
|
|
|
+ SerialPortUtil.getInstance().sendCommand(SerialPortUtil.NURSELIGHT + "4", beComeDoubleStr(rr) + beComeDoubleStr(gg) + beComeDoubleStr(bb), "F");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置护理灯2
|
|
|
+ */
|
|
|
+ public static void setNurseLedLight2(final int brightnessPercent, final ArrayList<NurseConfigDto> nurseConfigs) {
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ float p = (float) brightnessPercent / 100;
|
|
|
+ for (int i = 0; i < nurseConfigs.size(); i++) {
|
|
|
+ String color = nurseConfigs.get(i).getNurseColorRbg();
|
|
|
+ if (StringUtils.notEmpty(color)) {
|
|
|
+ int rr = (int) ((StringUtils.parseHex2Int(StringUtils.substringByLengh(color, 0, 2))) * p);
|
|
|
+ int gg = (int) ((StringUtils.parseHex2Int(StringUtils.substringByLengh(color, 2, 4))) * p);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ } 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";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|