[684][hardware]LED屏幕 红绿灯不消失问题修复

This commit is contained in:
xinfengkun
2024-12-25 15:19:00 +08:00
parent e7a8916d12
commit 2b405f6421
2 changed files with 56 additions and 7 deletions

View File

@@ -53,7 +53,7 @@ open class BaseLedUIViewModel : ViewModel() {
currentStationReportUI = StationReportUI(stationName, state)
}
open suspend fun receive(msg: LedUI) {
open fun receive(msg: LedUI) {
Log.e(
TAG,
"receive --> ${msg.javaClass.simpleName}[priority=${msg.priority}] current:${currentLedUI.javaClass.simpleName}[priority=${currentLedUI.priority}]"
@@ -105,7 +105,7 @@ open class BaseLedUIViewModel : ViewModel() {
}
suspend fun reset() {
fun reset() {
Log.i(TAG, "reset()")
viewModelScope.launch {
currentLedUI = DEFAULT_UI
@@ -118,7 +118,7 @@ open class BaseLedUIViewModel : ViewModel() {
}
}
private suspend fun showUI(msg: LedUI) {
private fun showUI(msg: LedUI) {
Log.i(TAG, "showUI ledUI=${msg.javaClass.simpleName}[priority=${msg.priority}]")
// 如果当前类型是 需要打断恢复的,放入等待队列
if (currentLedUI.interruptRestore) {
@@ -157,7 +157,7 @@ open class BaseLedUIViewModel : ViewModel() {
}
}
private suspend fun dismissUI(msg: LedUI) {
private fun dismissUI(msg: LedUI) {
Log.i(TAG, "dismissUI ledUI=${msg.javaClass.simpleName}[priority=${msg.priority}]")
currentCountDownJob?.also {
it.cancel()
@@ -166,7 +166,7 @@ open class BaseLedUIViewModel : ViewModel() {
restoreLastUI()
}
private suspend fun restoreLastUI() {
private fun restoreLastUI() {
//恢复打断
val restoreUI = pollRestoreLedUI()
if (restoreUI != null) {
@@ -177,7 +177,7 @@ open class BaseLedUIViewModel : ViewModel() {
}
}
private suspend fun startBasicUISwitchLoop() {
private fun startBasicUISwitchLoop() {
if (currentRouteInfoUI != null) {
showUI(currentRouteInfoUI!!)
} else if (currentStationReportUI != null) {
@@ -193,7 +193,7 @@ open class BaseLedUIViewModel : ViewModel() {
kotlin.runCatching { baseUICountDownJob?.cancel() }
}
private suspend fun basicUISwitchInternal() {
private fun basicUISwitchInternal() {
Log.i(TAG, "baseUISwitchInternal()")
cancelBasicUISwitch()
viewModelScope.launch {

View File

@@ -2,6 +2,7 @@ package com.mogo.support.device.led
import android.content.Context
import android.os.CountDownTimer
import com.mogo.support.device.manager.cpower5a.LedScreenCpower5aManager
import com.mogo.support.device.manager.cpower5a.common.LedScreen
import com.mogo.support.device.manager.cpower5a.common.TrafficLightState
@@ -21,6 +22,10 @@ object LedSourceManager {
private var lastUpdateEmergencyBrakeTime = 0L//上次触发急刹展示的时间
private var isDriver by Delegates.notNull<Boolean>()
//红绿灯定时器,超时未更新隐藏红绿灯
@Volatile
private var lightCountDownTimer: CountDownTimer? = null
private var lastLightTime: Long = System.currentTimeMillis()
fun init(isDriver: Boolean) {
this.isDriver = isDriver
}
@@ -80,6 +85,47 @@ object LedSourceManager {
}
}
private fun updateLightCountDownTimer(){
lastLightTime = System.currentTimeMillis()
if (lightCountDownTimer == null) {
lightCountDownTimer = object : CountDownTimer(300000, 500) {
override fun onTick(millisUntilFinished: Long) {
if ((System.currentTimeMillis() - lastLightTime) > 1000) {
//隐藏红绿灯显示
receiveUI(
TrafficLightUI(
false,
null, -1,
null, -1,
null, -1,
null, -1
)
)
lightCountDownTimer?.cancel()
lightCountDownTimer = null
}
}
override fun onFinish() {
//隐藏红绿灯显示
receiveUI(
TrafficLightUI(
false,
null, -1,
null, -1,
null, -1,
null, -1
)
)
lightCountDownTimer?.cancel()
lightCountDownTimer = null
}
}
lightCountDownTimer?.start()
}
}
/**
* 更新红绿灯数据
* state -1表示 null; 0表示 CLEAR; 1表示 NONE; 2表示 RED; 3表示 YELLOW; 4表示 GREEN;
@@ -101,6 +147,7 @@ object LedSourceManager {
var durationStraightTemp = durationStraight
var durationTurnRightTemp = durationTurnRight
updateLightCountDownTimer()
var isShow = true
if (stateTurnRound == -1 && stateTurnLeft == -1 && stateStraight == -1 && stateTurnRight == -1) {
isShow = false
@@ -176,6 +223,8 @@ object LedSourceManager {
} else if (type == 2) {
//结束
receiveUI(FinishUI())
frontViewModel.reset()
backViewModel.reset()
} else if (type == 3) {
//出站
if (arrivalStopName.isNotEmpty()) {