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 4670e57a84..9facfa6489 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 @@ -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 { 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 8030607c25..8cd5ab27f0 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 @@ -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() + //红绿灯定时器,超时未更新隐藏红绿灯 + @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()) {