Ver código fonte

Merge branch 'FaceScenic_V2_baiduface' of http://218.108.80.158:8081/shangyp/FaceScenic into FaceScenic_V2_baiduface

xwh 1 semana atrás
pai
commit
d4adff9b9f

+ 1 - 0
app/build.gradle

@@ -115,6 +115,7 @@ dependencies {
     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
     implementation files('libs\\RocoApiManager.jar')
     implementation 'org.jetbrains:annotations:15.0'
+    implementation files('libs\\YNHAPI-20230413.jar')
     testImplementation 'junit:junit:4.+'
     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

BIN
app/libs/YNHAPI-20230413.jar


+ 7 - 4
app/src/main/java/com/hanghui/senic/service/usbserialdemo/utile/X1/RelaysAndLedUtile.java

@@ -11,6 +11,7 @@ import com.hanghui.senic.service.usbserialdemo.utile.ConfigManager;
 import com.hanghui.senic.service.usbserialdemo.utile.FaceScenicUtile;
 import com.hanghui.senic.service.usbserialdemo.utile.StringIsNull;
 import com.hanghui.senic.service.usbserialdemo.utile.StringUtils;
+import com.hanghui.senic.service.usbserialdemo.utile.X5.X5RelaysAndLedUtile;
 import com.hanghui.senic.service.usbserialdemo.utile.devicesUI.Constants;
 import com.hanghui.senic.service.usbserialdemo.utile.devicesUI.DeviceUtils;
 import com.hanghui.senic.service.usbserialdemo.utile.loacat.AppLogUtils;
@@ -36,8 +37,7 @@ public class RelaysAndLedUtile {
     //继电器开关
     public void isOpenRelays(int newValue) {
         if (DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP) ||
-                DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A10) ||
-                DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A50)) {
+                DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A10)) {
             if (newValue == 1) {
                 AppLogUtils.e(false, "硬件处理—X1继电器 ", "打开继电器  ");
                 Intent intent = new Intent();
@@ -51,7 +51,9 @@ public class RelaysAndLedUtile {
                 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
                 MyAppliction.getContext().sendBroadcast(intent);
             }
-        } else {
+        } else if (DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A50)){
+            X5RelaysAndLedUtile.getInstance().isOpenRelays(newValue);
+        }else {
             AppLogUtils.e(false, "硬件处理—非X1继电器 ", "执行继电器打开或关闭操作 newValue " + newValue);
             PosUtil.setRelayPower(newValue);//1-开门  or 0-关门
         }
@@ -88,7 +90,8 @@ public class RelaysAndLedUtile {
             }
             return;
         } else if (DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A50)){
-            CommonUtil.setLedLight(isOpenLedLight);
+            X5RelaysAndLedUtile.getInstance().setLedLight(Type,isOpenLedLight);
+            return;
         }
         switch (Type) {
             case "open":

+ 77 - 0
app/src/main/java/com/hanghui/senic/service/usbserialdemo/utile/X5/GpioUtile.java

@@ -0,0 +1,77 @@
+package com.hanghui.senic.service.usbserialdemo.utile.X5;
+
+import android.preference.Preference;
+
+import com.hanghui.senic.service.usbserialdemo.utile.loacat.AppLogUtils;
+import com.innohi.YNHAPI;
+
+public class GpioUtile implements Preference.OnPreferenceChangeListener{
+    private static GpioUtile instance;
+    private static OnGpioListener listener;
+    private static final String KEY_GPIO_MODE = "gpio_mode";
+    private static final String KEY_SET_GPIO_STATE = "set_gpio_state";
+    private static final String KEY_GPIO_STATE = "gpio_state";
+    private YNHAPI.GpioListenerCallback mCallback = null;
+    private YNHAPI mYNHAPI = YNHAPI.getInstance();
+    private GpioUtile() {
+    }
+    public static GpioUtile getInstance() {
+        synchronized (GpioUtile.class) {
+            if (instance == null) {
+                instance = new GpioUtile();
+            }
+        }
+        return instance;
+    }
+    public void setListener(OnGpioListener listener) {
+        this.listener = listener;
+    }
+    public void init(){
+        YNHAPI.GpioMode mode = mYNHAPI.getGpioMode(YNHAPI.GPIO_5);
+        YNHAPI.GpioState state = mYNHAPI.getGpioState(YNHAPI.GPIO_5);
+        AppLogUtils.i(true,"紫鹏门磁信号初始化","init: mode =" + mode + ", state = " + state);
+        if (mode == YNHAPI.GpioMode.UNKNOWN || state == YNHAPI.GpioState.UNKNOWN) {
+            AppLogUtils.e(true,"紫鹏门磁信号初始化","无法正确获取获取GPIO的模式/状态!");
+            return;
+        }
+        listenInputGpioState();
+    }
+
+    private void listenInputGpioState() {
+        if (mCallback == null) {
+            mCallback = (index, oldState, newState) -> {
+                AppLogUtils.i(true,"紫鹏门磁信号回调","index = YNHAPI.GPIO_5" + ", old state = " + oldState + ", new state = " + newState);
+                //newState 1 - 断开   0 - 短接
+                listener.OnGpioListener(oldState,newState);
+            };
+            mYNHAPI.listenGpio(YNHAPI.GPIO_5, mCallback);
+        }
+    }
+
+    public void unlistenGpioState() {
+        if (mCallback != null) {
+            mYNHAPI.unlistenGpio(YNHAPI.GPIO_5, mCallback);
+            mCallback = null;
+        }
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        switch (preference.getKey()) {
+            case KEY_GPIO_MODE:
+                boolean output = "1".equals(String.valueOf(newValue));
+                mYNHAPI.setGpioMode(YNHAPI.GPIO_5,YNHAPI.GpioMode.INPUT);
+                return true;
+
+            case KEY_SET_GPIO_STATE:
+                boolean high = "1".equals(String.valueOf(newValue));
+                mYNHAPI.setGpioState(YNHAPI.GPIO_5, high ? YNHAPI.GpioState.HIGH : YNHAPI.GpioState.LOW);
+                return true;
+        }
+        return false;
+    }
+
+    public interface OnGpioListener {
+        void OnGpioListener(int oldState,int newState);
+    }
+}

+ 75 - 0
app/src/main/java/com/hanghui/senic/service/usbserialdemo/utile/X5/X5RelaysAndLedUtile.java

@@ -0,0 +1,75 @@
+package com.hanghui.senic.service.usbserialdemo.utile.X5;
+
+import com.common.pos.api.util.PosUtil;
+import com.hanghui.senic.service.usbserialdemo.utile.FaceScenicUtile;
+import com.hanghui.senic.service.usbserialdemo.utile.devicesUI.Constants;
+import com.hanghui.senic.service.usbserialdemo.utile.devicesUI.DeviceUtils;
+import com.hanghui.senic.service.usbserialdemo.utile.loacat.AppLogUtils;
+import com.innohi.YNHAPI;
+
+/**
+ * @author David Chow
+ * @since 2021/3/27
+ */
+public class X5RelaysAndLedUtile {
+    private static X5RelaysAndLedUtile instance;
+    protected YNHAPI mYNHAPI;
+    private X5RelaysAndLedUtile() {
+        mYNHAPI = YNHAPI.getInstance();
+    }
+    public static X5RelaysAndLedUtile getInstance() {
+        synchronized (X5RelaysAndLedUtile.class) {
+            if (instance == null) {
+                instance = new X5RelaysAndLedUtile();
+            }
+        }
+        return instance;
+    }
+    //继电器开关
+    public void isOpenRelays(int newValue) {
+        if (DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP)||
+                DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A10) ||
+                DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A50)) {
+            boolean isOpen = false;
+            if (newValue == 1){
+                isOpen = true;
+            }
+            AppLogUtils.e(false, "硬件处理—X5继电器 ", "继电器开关门  "+isOpen);
+            mYNHAPI.setGpioState(YNHAPI.RELAY, isOpen ? YNHAPI.GpioState.HIGH : YNHAPI.GpioState.LOW);
+        }else {
+            PosUtil.setRelayPower(newValue);//1-开门  or 0-关门
+        }
+    }
+    //补光灯
+    public void setLedLight(String Type, boolean isOpenLedLight){
+        if (DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP)||
+                DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A10)||
+                DeviceUtils.getDeviceModel().equals(Constants.DeviceModel.ZP_A50)) {
+            switch (Type) {
+                case "open":
+                    mYNHAPI.setLightBrightness(YNHAPI.LIGHT_WHITE, true ? 204 : 0);
+                    break;
+                case "auto":
+                    mYNHAPI.setLightBrightness(YNHAPI.LIGHT_WHITE, isOpenLedLight ? 204 : 0);
+                    break;
+                case "close":
+                default:
+                    mYNHAPI.setLightBrightness(YNHAPI.LIGHT_WHITE, false ? 204 : 0);
+                    break;
+            }
+            return;
+        }
+        switch (Type) {
+            case "open":
+                FaceScenicUtile.setLedLight(true);
+                break;
+            case "auto":
+                FaceScenicUtile.setLedLight(isOpenLedLight);
+                break;
+            case "close":
+            default:
+                FaceScenicUtile.setLedLight(false);
+                break;
+        }
+    }
+}