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()
PlatformUtils.shutDown()
} }
} }
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()
}
}
}
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,12 +95,14 @@ 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)
} }
if (toDoCmdList.isNotEmpty()) { synchronized(toDoCmdList) {
toDoCmdList.forEach { if (toDoCmdList.isNotEmpty()) {
Thread.sleep(READ_MSG_INTERVAL) toDoCmdList.forEach {
ComMultiPortUtils.sendMsg(PORT_PATH, it) Thread.sleep(READ_MSG_INTERVAL)
ComMultiPortUtils.sendMsg(PORT_PATH, it)
}
toDoCmdList.clear()
} }
toDoCmdList.clear()
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -113,22 +115,30 @@ object GasPortUtils {
} }
fun setSpeed(speed: Int) { fun setSpeed(speed: Int) {
toDoCmdList.add(CMD.buildSpeedCmd(speed)) synchronized(toDoCmdList) {
toDoCmdList.add(CMD.buildSpeedCmd(speed))
}
} }
fun calibrationSensor(index: Int, value: Int) { fun calibrationSensor(index: Int, value: Int) {
if (value == 0) { synchronized(toDoCmdList) {
toDoCmdList.add(CalibrationCmd(index, value).buildZeroCmd()) if (value == 0) {
} else { toDoCmdList.add(CalibrationCmd(index, value).buildZeroCmd())
toDoCmdList.add(CalibrationCmd(index, value).buildSPANCmd()) } else {
toDoCmdList.add(CalibrationCmd(index, value).buildSPANCmd())
}
} }
} }
private fun switchSensor(index: Int, open: Boolean) { private fun switchSensor(index: Int, open: Boolean) {
toDoCmdList.add(buildSwitchSensorCmd(index, open)) synchronized(toDoCmdList) {
toDoCmdList.add(buildSwitchSensorCmd(index, open))
}
} }
fun setSensorMaxRange(index: Int, value: Int) { fun setSensorMaxRange(index: Int, value: Int) {
toDoCmdList.add(buildSensorRangeCmd(index, value)) synchronized(toDoCmdList) {
toDoCmdList.add(buildSensorRangeCmd(index, value))
}
} }
} }
Loading…
Cancel
Save