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.databinding.ActivityBaseBinding
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.CommonTopBar
import com.yinuo.safetywatcher.watcher.utils.PlatformUtils
@ -68,11 +69,23 @@ abstract class BaseActivity : AppCompatActivity() {
}
baseBinding.tvConfirm.setOnClickListener {
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() {
GasPortUtils.addListener(shoutDownListener)
shoutDowning = true
GasPortUtils.setSpeed(0)
// 暂停录制编码
RecordHelper.stopRecording()
}
@ -224,6 +237,7 @@ abstract class BaseActivity : AppCompatActivity() {
override fun onDestroy() {
super.onDestroy()
closeLoadingDialog()
GasPortUtils.removeListener(shoutDownListener)
GlobalScope.launch(Dispatchers.IO) {
MMKVUtils.sync()
}

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