[690][led]优化led播报逻辑,处理崩溃

This commit is contained in:
xinfengkun
2025-01-14 19:26:06 +08:00
parent eaea27517d
commit 91be837ab4
3 changed files with 32 additions and 19 deletions

View File

@@ -39,6 +39,6 @@ android {
dependencies {
implementation rootProject.ext.dependencies.androidxappcompat
api rootProject.ext.dependencies.serialport
implementation "com.mogo.support.device.manager:led_screen_cpower5a:1.0.10"
implementation "com.mogo.support.device.manager:led_screen_cpower5a:1.0.11"
implementation rootProject.ext.dependencies.view_model_scope
}

View File

@@ -31,7 +31,6 @@ open class BaseLedUIViewModel(protected val writeChainLogListener: IWriteChainLo
init {
currentLedUI = DEFAULT_UI
start()
}
fun start() {
@@ -43,17 +42,25 @@ open class BaseLedUIViewModel(protected val writeChainLogListener: IWriteChainLo
/**
* 更新线路信息
*/
fun updateCurrentRouteInfo(lineName: String) {
suspend fun updateCurrentRouteInfo(lineName: String) {
Log.i(TAG, "线路信息更新 线路名称:$lineName")
currentRouteInfoUI = RouteInfoUI(lineName)
currentRouteInfoUI?.let {
showUI(it)
}
basicUISwitchInternal()
}
/**
* 更新报站信息
*/
fun updateCurrentStationReport(stationName: String, state: String) {
suspend fun updateCurrentStationReport(stationName: String, state: String) {
Log.i(TAG, "报站信息更新 ${state}$stationName 站点状态")
currentStationReportUI = StationReportUI(stationName, state)
currentStationReportUI?.let {
showUI(it)
}
basicUISwitchInternal()
}
open suspend fun receive(msg: LedUI) {
@@ -98,7 +105,7 @@ open class BaseLedUIViewModel(protected val writeChainLogListener: IWriteChainLo
removeRestoreLedUI(msg)
// 当前正在展示,取消展示
if (currentLedUI.javaClass.simpleName == msg.javaClass.simpleName) {
dismissUI(msg)
dismissUI(msg, false)
}
}
} else {
@@ -113,8 +120,9 @@ open class BaseLedUIViewModel(protected val writeChainLogListener: IWriteChainLo
viewModelScope.launch {
currentLedUI = DEFAULT_UI
restoreLedUIQueue.clear()
currentCountDownJob?.cancel()
baseUICountDownJob?.cancel()
currentCountDownJob?.also {
it.cancel()
}
cancelBasicUISwitch()
currentRouteInfoUI = null
currentStationReportUI = null
@@ -160,12 +168,14 @@ open class BaseLedUIViewModel(protected val writeChainLogListener: IWriteChainLo
}
}
private suspend fun dismissUI(msg: LedUI) {
private suspend fun dismissUI(msg: LedUI, isRemove: Boolean = true) {
Log.i(TAG, "dismissUI ledUI=${msg.javaClass.simpleName}[priority=${msg.priority}]")
currentCountDownJob?.also {
it.cancel()
}
removeRestoreLedUI(msg)
if (isRemove) {
removeRestoreLedUI(msg)
}
restoreLastUI()
}
@@ -231,14 +241,18 @@ open class BaseLedUIViewModel(protected val writeChainLogListener: IWriteChainLo
* 过滤队列中时间戳小于指定时间的消息,取出优先级最高的消息
*/
private fun pollRestoreLedUI(): LedUI? {
while (restoreLedUIQueue.isNotEmpty()) {
val message = restoreLedUIQueue.poll()
if (message is LedUICountDown) {
if (message.countDownSeconds > 0 && message.absCountDownTimestamp > System.currentTimeMillis()) {
return message
kotlin.runCatching {
synchronized(restoreLedUIQueue) {
while (restoreLedUIQueue.isNotEmpty()) {
val message = restoreLedUIQueue.poll() ?: continue
if (message is LedUICountDown) {
if (message.countDownSeconds > 0 && message.absCountDownTimestamp > System.currentTimeMillis()) {
return message
}
} else {
return message
}
}
} else {
return message
}
}
return null

View File

@@ -68,6 +68,8 @@ object LedSourceManager : IWriteChainLogListener {
this.isB2 = isB2
if (isDriver && isB2) {
LedScreenCpower5aManager.getInstance().addListener(cpower5aListener)
frontViewModel.start()
backViewModel.start()
}
}
@@ -288,9 +290,6 @@ object LedSourceManager : IWriteChainLogListener {
"LED外屏数据源",
"行程 type=${type} lineName=${lineName} departureStopName=${departureStopName} arrivalStopName=${arrivalStopName} isLastStop=${isLastStop}"
)
if (lineName.isNotEmpty()) {
updateLineNameUI(lineName)
}
if (type == 1) {
//开始
updateLineNameUI(lineName);