From 91be837ab4e9e121706db50006e938e1c852673b Mon Sep 17 00:00:00 2001 From: xinfengkun Date: Tue, 14 Jan 2025 19:26:06 +0800 Subject: [PATCH] =?UTF-8?q?[690][led]=E4=BC=98=E5=8C=96led=E6=92=AD?= =?UTF-8?q?=E6=8A=A5=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A4=84=E7=90=86=E5=B4=A9?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/mogo-hardware-devices/build.gradle | 2 +- .../support/device/led/BaseLedUIViewModel.kt | 44 ++++++++++++------- .../support/device/led/LedSourceManager.kt | 5 +-- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/libraries/mogo-hardware-devices/build.gradle b/libraries/mogo-hardware-devices/build.gradle index f3e63471cb..1b93ac653e 100644 --- a/libraries/mogo-hardware-devices/build.gradle +++ b/libraries/mogo-hardware-devices/build.gradle @@ -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 } diff --git a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/led/BaseLedUIViewModel.kt b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/led/BaseLedUIViewModel.kt index 5f519c79d8..557c48d9e3 100644 --- a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/led/BaseLedUIViewModel.kt +++ b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/led/BaseLedUIViewModel.kt @@ -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 diff --git a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/led/LedSourceManager.kt b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/led/LedSourceManager.kt index c50454c1b1..e722267b33 100644 --- a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/led/LedSourceManager.kt +++ b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/led/LedSourceManager.kt @@ -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);