فهرست منبع

添加钥匙底座灯控制

Frankensteinly 1 سال پیش
والد
کامیت
6439da4e92

+ 15 - 0
app/src/main/java/com/grkj/iscs/activity/ModbusActivity.kt

@@ -156,6 +156,21 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
             }
         }
 
+        mBinding?.keyLight?.setOnClickListener {
+            if (mBinding?.leftLight?.text.toString().isEmpty()) {
+                ToastUtils.tip("请输入左灯操作")
+                return@setOnClickListener
+            }
+            if (mBinding?.rightLight?.text.toString().isEmpty()) {
+                ToastUtils.tip("请输入右灯操作")
+                return@setOnClickListener
+            }
+            mBinding?.keyLight?.setOnClickListener {
+                // TODO 暂时写死,调试用
+                ModBusController.controlKeyLight(1, mBinding?.leftLight?.text.toString().toInt(), mBinding?.rightLight?.text.toString().toInt())
+            }
+        }
+
         mBinding?.exit?.setOnClickListener { finish() }
     }
 

+ 20 - 0
app/src/main/java/com/grkj/iscs/modbus/ModBusController.kt

@@ -97,6 +97,15 @@ object ModBusController {
 
     /*****************************************************************************************/
 
+    /**
+     * 初始化所有设备的状态
+     */
+    fun initDevicesStatus() {
+        readDeviceType {
+            // TODO 待完善
+        }
+    }
+
     fun checkStatus(byteArray: ByteArray): Any? {
         if (byteArray.isEmpty()) {
             return null
@@ -179,4 +188,15 @@ object ModBusController {
     fun updateLockRfid(slaveIdx: Int, lockIdx: Int, rfid: String) {
         deviceList.find { it.idx?.toInt() == slaveIdx }?.lockList?.find { it.idx == lockIdx }?.rfid = rfid
     }
+
+    /**
+     * 操作钥匙灯
+     */
+    fun controlKeyLight(slaveIdx: Int?, leftAction: Int = 0, rightAction: Int = 0) {
+        slaveIdx?.let {
+            modBusManager?.generateKeyLightCmd(leftAction, rightAction)?.let { cmd ->
+                modBusManager?.sendTo(it, cmd)
+            }
+        }
+    }
 }

+ 12 - 0
app/src/main/java/com/grkj/iscs/modbus/ModBusManager.kt

@@ -281,6 +281,18 @@ class ModBusManager(
         )
     }
 
+    /**
+     * 生成钥匙底座灯光指令
+     *
+     * @param leftAction、rightAction 0:保持当前状态 1:点亮 2:熄灭 默认0
+     */
+    fun generateKeyLightCmd(leftAction: Int = 0, rightAction: Int = 0): MBFrame {
+        return MBFrame(
+            FRAME_TYPE_WRITE,
+            byteArrayOf(0x00, 0x15, leftAction.toByte(), rightAction.toByte())
+        )
+    }
+
     /**
      * 生成锁具 RFID 读指令
      *

+ 42 - 0
app/src/main/res/layout/activity_modbus.xml

@@ -78,6 +78,7 @@
             android:background="#852852"
             android:hint="Slave Idx"
             android:text="0"
+            android:inputType="number"
             android:textColorHint="@color/white"
             android:textColor="@color/white"
             android:layout_margin="10dp"/>
@@ -88,6 +89,7 @@
             android:layout_height="40dp"
             android:background="#852852"
             android:hint="Lock Idx"
+            android:inputType="number"
             android:textColorHint="@color/white"
             android:textColor="@color/white"
             android:layout_margin="10dp"/>
@@ -122,4 +124,44 @@
             android:textSize="8sp"
             android:layout_margin="5dp"/>
     </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <EditText
+            android:id="@+id/leftLight"
+            android:layout_width="100dp"
+            android:layout_height="40dp"
+            android:background="#852852"
+            android:hint="Key Left Light"
+            android:text="0"
+            android:inputType="number"
+            android:textColorHint="@color/white"
+            android:textColor="@color/white"
+            android:layout_margin="10dp"/>
+
+        <EditText
+            android:id="@+id/rightLight"
+            android:layout_width="100dp"
+            android:layout_height="40dp"
+            android:background="#852852"
+            android:hint="Key Right Light"
+            android:text="0"
+            android:inputType="number"
+            android:textColorHint="@color/white"
+            android:textColor="@color/white"
+            android:layout_margin="10dp"/>
+
+        <Button
+            android:id="@+id/keyLight"
+            android:layout_width="100dp"
+            android:layout_height="40dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Key Light"
+            android:textSize="8sp"
+            android:layout_margin="5dp"/>
+    </LinearLayout>
 </LinearLayout>