desc:关机时主动关闭气泵gpio; 长按弹出关机弹框不再通过up事件,再down中处理

main
xiaowusky 1 year ago
parent 1581a7e913
commit b446522003

@ -17,7 +17,6 @@ import android.widget.SeekBar
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatRadioButton import androidx.appcompat.widget.AppCompatRadioButton
import androidx.core.view.postDelayed
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.common.commonlib.utils.LogUtils import com.common.commonlib.utils.LogUtils
import com.common.commonlib.utils.MMKVUtils import com.common.commonlib.utils.MMKVUtils
@ -25,9 +24,9 @@ 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.GPIOUtils
import com.yinuo.safetywatcher.watcher.utils.PlatformUtils import com.yinuo.safetywatcher.watcher.utils.PlatformUtils
import com.yinuo.safetywatcher.watcher.utils.RecordHelper import com.yinuo.safetywatcher.watcher.utils.RecordHelper
import com.yinuo.safetywatcher.watcher.utils.SoundUtils import com.yinuo.safetywatcher.watcher.utils.SoundUtils
@ -72,22 +71,11 @@ abstract class BaseActivity : AppCompatActivity() {
} }
} }
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()
GPIOUtils.shoutDownMotor()
PlatformUtils.shutDown()
} }
private val setVoiceAreaRunnable = Runnable { private val setVoiceAreaRunnable = Runnable {
@ -237,13 +225,11 @@ 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()
} }
} }
var isHomeLongPress = false
var isLeftRightLongPress = false var isLeftRightLongPress = false
override fun dispatchKeyEvent(event: KeyEvent): Boolean { override fun dispatchKeyEvent(event: KeyEvent): Boolean {
LogUtils.w("cyy dispatchKeyEvent keyCode = ${event?.keyCode} count = ${event?.repeatCount} acton = ${event?.action}") LogUtils.w("cyy dispatchKeyEvent keyCode = ${event?.keyCode} count = ${event?.repeatCount} acton = ${event?.action}")
@ -264,13 +250,6 @@ abstract class BaseActivity : AppCompatActivity() {
baseBinding.areaSound.postDelayed(hideVoiceAreaRunnable, 1500) baseBinding.areaSound.postDelayed(hideVoiceAreaRunnable, 1500)
return true return true
} }
} else if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (isHomeLongPress) {
lastFocusView = currentFocus
baseBinding.layoutShutdown.visibility = View.VISIBLE
baseBinding.tvCancel.requestFocus()
return true
}
} else if (keyCode == KeyEvent.KEYCODE_F1) { } else if (keyCode == KeyEvent.KEYCODE_F1) {
LogUtils.w("BaseActivity F1 up") LogUtils.w("BaseActivity F1 up")
SoundUtils.stopSoundIo() SoundUtils.stopSoundIo()
@ -279,6 +258,8 @@ abstract class BaseActivity : AppCompatActivity() {
return super.dispatchKeyEvent(event) return super.dispatchKeyEvent(event)
} }
private var centerDownTime = 0L
private fun dealActionDown(event: KeyEvent): Boolean { private fun dealActionDown(event: KeyEvent): Boolean {
val repeatCount = event.repeatCount val repeatCount = event.repeatCount
val keyCode = event.keyCode val keyCode = event.keyCode
@ -289,10 +270,17 @@ abstract class BaseActivity : AppCompatActivity() {
var mediaVolume = baseBinding.sbSound.progress var mediaVolume = baseBinding.sbSound.progress
if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) mediaVolume-- else mediaVolume++ if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) mediaVolume-- else mediaVolume++
baseBinding.sbSound.progress = mediaVolume baseBinding.sbSound.progress = mediaVolume
return super.dispatchKeyEvent(event)
} }
} else if (keyCode == KeyEvent.KEYCODE_ENTER) { } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
isHomeLongPress = repeatCount > 8 if (repeatCount == 0) {
centerDownTime = System.currentTimeMillis()
} else {
if (System.currentTimeMillis() - centerDownTime > 2000 && baseBinding.layoutShutdown.visibility == View.GONE) {
lastFocusView = currentFocus
baseBinding.layoutShutdown.visibility = View.VISIBLE
baseBinding.tvCancel.requestFocus()
}
}
} else if (keyCode == KeyEvent.KEYCODE_F1) { } else if (keyCode == KeyEvent.KEYCODE_F1) {
LogUtils.w("BaseActivity F1 pressed") LogUtils.w("BaseActivity F1 pressed")
SoundUtils.playSoundIo() SoundUtils.playSoundIo()

@ -10,7 +10,7 @@ import java.io.IOException
object GPIOUtils { object GPIOUtils {
private const val TAG: String = "GPIOUtils" private const val TAG: String = "GPIOUtils"
fun setGpioDirection(gpio: Int, direction: String) { fun setGpioDirection(gpio: Int, direction: String) {
val path = "/sys/class/gpio/gpio$gpio/direction" val path = "/sys/class/gpio/gpio$gpio/direction"
if (File(path).exists()) { if (File(path).exists()) {
var writer: FileWriter? = null var writer: FileWriter? = null
@ -37,7 +37,7 @@ object GPIOUtils {
* @param gpio 端口号 * @param gpio 端口号
* @param value 1高电平 0低电平 * @param value 1高电平 0低电平
*/ */
fun setGpioValue(gpio: Int, value: Int) { fun setGpioValue(gpio: Int, value: Int) {
val path = "/sys/class/gpio/gpio$gpio/value" val path = "/sys/class/gpio/gpio$gpio/value"
if (File(path).exists()) { if (File(path).exists()) {
var writer: FileWriter? = null var writer: FileWriter? = null
@ -60,7 +60,7 @@ object GPIOUtils {
} }
} }
fun getGpioValue(gpio: Int): String? { fun getGpioValue(gpio: Int): String? {
val path = "/sys/class/gpio/gpio$gpio/value" val path = "/sys/class/gpio/gpio$gpio/value"
if (File(path).exists()) { if (File(path).exists()) {
var reader: FileReader? = null var reader: FileReader? = null
@ -79,12 +79,42 @@ object GPIOUtils {
return null return null
} }
fun openCamera(){ fun openCamera() {
setGpioDirection(123, "out") setGpioDirection(123, "out")
setGpioValue(123, 1) setGpioValue(123, 1)
} }
fun closeCamera(){ fun closeCamera() {
setGpioValue(123, 0) setGpioValue(123, 0)
} }
/**
* 关闭电机
*/
fun shoutDownMotor() {
setAttributeValue(0)
}
private fun setAttributeValue(value: Int) {
val path = "/sys/class/leds/moto_en/brightness"
if (File(path).exists()) {
var writer: FileWriter? = null
try {
writer = FileWriter(path)
writer.write(value.toString())
writer.flush()
} catch (ex: IOException) {
ex.printStackTrace()
} catch (ex: NumberFormatException) {
ex.printStackTrace()
} finally {
if (writer != null) {
try {
writer.close()
} catch (ex: IOException) {
}
}
}
}
}
} }
Loading…
Cancel
Save