desc:关机时主动关闭气泵gpio

main
xiaowusky 1 year ago
parent 97c16ab735
commit 1581a7e913

@ -25,6 +25,7 @@ import com.loper7.date_time_picker.number_picker.NumberPicker
import com.yinuo.safetywatcher.R import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivityBaseBinding import com.yinuo.safetywatcher.databinding.ActivityBaseBinding
import com.yinuo.safetywatcher.watcher.constant.NAMESPACE_ANDROID import com.yinuo.safetywatcher.watcher.constant.NAMESPACE_ANDROID
import com.yinuo.safetywatcher.watcher.port.GasPortUtils
import com.yinuo.safetywatcher.watcher.ui.view.CommonDialog import com.yinuo.safetywatcher.watcher.ui.view.CommonDialog
import com.yinuo.safetywatcher.watcher.ui.view.CommonTopBar import com.yinuo.safetywatcher.watcher.ui.view.CommonTopBar
import com.yinuo.safetywatcher.watcher.utils.PlatformUtils import com.yinuo.safetywatcher.watcher.utils.PlatformUtils
@ -68,11 +69,23 @@ abstract class BaseActivity : AppCompatActivity() {
} }
baseBinding.tvConfirm.setOnClickListener { baseBinding.tvConfirm.setOnClickListener {
onShutDown() onShutDown()
}
}
private val shoutDownListener: (ByteArray) -> Unit = {
if (it[0] == 0x01.toByte() && it[1] == 0x06.toByte() && it[2] == 0x05.toByte() && it[5] == 0x00.toByte()) {
if (shoutDowning) {
shoutDowning = false
PlatformUtils.shutDown() PlatformUtils.shutDown()
} }
} }
}
var shoutDowning = false
open fun onShutDown() { open fun onShutDown() {
GasPortUtils.addListener(shoutDownListener)
shoutDowning = true
GasPortUtils.setSpeed(0)
// 暂停录制编码 // 暂停录制编码
RecordHelper.stopRecording() RecordHelper.stopRecording()
} }
@ -224,6 +237,7 @@ abstract class BaseActivity : AppCompatActivity() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
closeLoadingDialog() closeLoadingDialog()
GasPortUtils.removeListener(shoutDownListener)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
MMKVUtils.sync() MMKVUtils.sync()
} }

@ -95,6 +95,7 @@ object GasPortUtils {
Thread.sleep(READ_MSG_INTERVAL) Thread.sleep(READ_MSG_INTERVAL)
ComMultiPortUtils.sendMsg(PORT_PATH, CMD.SENSOR_5) ComMultiPortUtils.sendMsg(PORT_PATH, CMD.SENSOR_5)
} }
synchronized(toDoCmdList) {
if (toDoCmdList.isNotEmpty()) { if (toDoCmdList.isNotEmpty()) {
toDoCmdList.forEach { toDoCmdList.forEach {
Thread.sleep(READ_MSG_INTERVAL) Thread.sleep(READ_MSG_INTERVAL)
@ -103,6 +104,7 @@ object GasPortUtils {
toDoCmdList.clear() toDoCmdList.clear()
} }
} }
}
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
@ -113,22 +115,30 @@ object GasPortUtils {
} }
fun setSpeed(speed: Int) { fun setSpeed(speed: Int) {
synchronized(toDoCmdList) {
toDoCmdList.add(CMD.buildSpeedCmd(speed)) toDoCmdList.add(CMD.buildSpeedCmd(speed))
} }
}
fun calibrationSensor(index: Int, value: Int) { fun calibrationSensor(index: Int, value: Int) {
synchronized(toDoCmdList) {
if (value == 0) { if (value == 0) {
toDoCmdList.add(CalibrationCmd(index, value).buildZeroCmd()) toDoCmdList.add(CalibrationCmd(index, value).buildZeroCmd())
} else { } else {
toDoCmdList.add(CalibrationCmd(index, value).buildSPANCmd()) toDoCmdList.add(CalibrationCmd(index, value).buildSPANCmd())
} }
} }
}
private fun switchSensor(index: Int, open: Boolean) { private fun switchSensor(index: Int, open: Boolean) {
synchronized(toDoCmdList) {
toDoCmdList.add(buildSwitchSensorCmd(index, open)) toDoCmdList.add(buildSwitchSensorCmd(index, open))
} }
}
fun setSensorMaxRange(index: Int, value: Int) { fun setSensorMaxRange(index: Int, value: Int) {
synchronized(toDoCmdList) {
toDoCmdList.add(buildSensorRangeCmd(index, value)) toDoCmdList.add(buildSensorRangeCmd(index, value))
} }
} }
}
Loading…
Cancel
Save