From 2b405f64210216ff819612f704d1173a2313f609 Mon Sep 17 00:00:00 2001 From: xinfengkun Date: Wed, 25 Dec 2024 15:19:00 +0800 Subject: [PATCH] =?UTF-8?q?[684][hardware]LED=E5=B1=8F=E5=B9=95=20?= =?UTF-8?q?=E7=BA=A2=E7=BB=BF=E7=81=AF=E4=B8=8D=E6=B6=88=E5=A4=B1=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/device/led/BaseLedUIViewModel.kt | 14 +++--- .../support/device/led/LedSourceManager.kt | 49 +++++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) 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()) {