[684][led]添加明鑫亮LED外面控制
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'kotlin-android'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -30,10 +31,14 @@ android {
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
api rootProject.ext.dependencies.serialport
|
||||
implementation "com.mogo.support.device.manager:led_screen_cpower5a:1.0.5"
|
||||
implementation rootProject.ext.dependencies.view_model_scope
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
package com.mogo.support.device.led
|
||||
|
||||
import android.util.Log
|
||||
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.Program
|
||||
|
||||
/**
|
||||
* 后屏
|
||||
*/
|
||||
open class BackLedUIViewModel : BaseLedUIViewModel() {
|
||||
companion object {
|
||||
const val TAG = "BackLedUIViewModel"
|
||||
|
||||
val supportUIList = mutableSetOf<String?>().also {
|
||||
it += WelcomeUI::class.simpleName
|
||||
it += FinishUI::class.simpleName
|
||||
it += RouteInfoUI::class.simpleName
|
||||
it += StationReportUI::class.simpleName
|
||||
it += ArriveStationUI::class.simpleName
|
||||
it += LeaveStationUI::class.simpleName
|
||||
it += EmergencyBrakeUI::class.simpleName
|
||||
it += TrafficLightUI::class.simpleName
|
||||
it += TurnSignalUI::class.simpleName
|
||||
it += RoadWorkAheadWarningUI::class.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun receive(msg: LedUI) {
|
||||
if (supportUIList.contains(msg.javaClass.simpleName)) {
|
||||
Log.i(
|
||||
FrontLedUIViewModel.TAG,
|
||||
"receive --> ${msg.javaClass.simpleName}[priority=${msg.priority}] "
|
||||
)
|
||||
super.receive(msg)
|
||||
} else {
|
||||
Log.i(
|
||||
FrontLedUIViewModel.TAG,
|
||||
"receive --> 不支持的类型,放弃 ${msg.javaClass.simpleName}[priority=${msg.priority}] "
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleLedUIShow(ledUI: LedUI) {
|
||||
super.handleLedUIShow(ledUI)
|
||||
when (ledUI) {
|
||||
is WelcomeUI -> {
|
||||
LedScreenCpower5aManager.getInstance().playProgramWelcome(
|
||||
null,
|
||||
LedScreen.OUTWARD_BACK,
|
||||
ledUI.hintMsg,
|
||||
ledUI.isForever
|
||||
)
|
||||
Log.e(TAG, "后屏 播放欢迎语:${ledUI.hintMsg} 是否永久展示:${ledUI.isForever}")
|
||||
}
|
||||
|
||||
is FinishUI -> {
|
||||
LedScreenCpower5aManager.getInstance().playProgramFinish(
|
||||
LedScreen.OUTWARD_BACK,
|
||||
ledUI.hintMsg,
|
||||
)
|
||||
Log.e(TAG, "后屏 播放结束语:${ledUI.hintMsg}")
|
||||
}
|
||||
|
||||
is RouteInfoUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramLineInformation(LedScreen.OUTWARD_BACK, ledUI.lineName)
|
||||
Log.e(TAG, "后屏 播放线路信息:${ledUI.lineName}")
|
||||
}
|
||||
|
||||
is StationReportUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramLineStationReport(
|
||||
LedScreen.OUTWARD_BACK,
|
||||
ledUI.stationName,
|
||||
ledUI.state
|
||||
)
|
||||
Log.e(TAG, "后屏 播放报站 站点:${ledUI.stationName} 状态:${ledUI.state}")
|
||||
}
|
||||
|
||||
is ArriveStationUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramLineStationReportHint(
|
||||
LedScreen.OUTWARD_BACK,
|
||||
"车辆进站"
|
||||
)
|
||||
Log.e(TAG, "后屏 播放车辆进站")
|
||||
}
|
||||
|
||||
is LeaveStationUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramLineStationReportHint(
|
||||
LedScreen.OUTWARD_BACK,
|
||||
"车辆起步"
|
||||
)
|
||||
Log.e(TAG, "后屏 播放车辆起步")
|
||||
}
|
||||
|
||||
is EmergencyBrakeUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgram(LedScreen.OUTWARD_BACK, Program.REMIND_FRONT_CAR_EMERGENCY_BRAKE)
|
||||
Log.e(TAG, "后屏 车辆急刹")
|
||||
}
|
||||
|
||||
is RoadWorkAheadWarningUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgram(LedScreen.OUTWARD_BACK, Program.REMIND_ROAD_WORK_AHEAD)
|
||||
Log.e(TAG, "后屏 道路施工")
|
||||
}
|
||||
|
||||
is TurnSignalUI -> {
|
||||
var program: Program? = null
|
||||
program = when (ledUI.type) {
|
||||
1 -> {
|
||||
Program.REMIND_TURN_LEFT
|
||||
}
|
||||
|
||||
2 -> {
|
||||
Program.REMIND_TURN_RIGHT
|
||||
}
|
||||
|
||||
3 -> {
|
||||
Program.REMIND_VEHICLE_ANOMALY
|
||||
}
|
||||
|
||||
else -> {
|
||||
null
|
||||
}
|
||||
}
|
||||
program?.let {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgram(
|
||||
LedScreen.OUTWARD_BACK,
|
||||
it
|
||||
)
|
||||
}
|
||||
Log.e(TAG, "后屏 播放节目${program}")
|
||||
}
|
||||
|
||||
is TrafficLightUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramTrafficLights(
|
||||
LedScreen.OUTWARD_BACK,
|
||||
ledUI.stateTurnRound, ledUI.durationTurnRound,
|
||||
ledUI.stateTurnLeft, ledUI.durationTurnLeft,
|
||||
ledUI.stateStraight, ledUI.durationStraight,
|
||||
ledUI.stateTurnRight, ledUI.durationTurnRight
|
||||
)
|
||||
Log.e(
|
||||
TAG,
|
||||
"后屏 播放信号灯节目 掉头:${ledUI.stateTurnRound} 掉头倒计时:${ledUI.durationTurnRound}\n" +
|
||||
"左转:${ledUI.stateTurnLeft} 左转倒计时:${ledUI.durationTurnLeft}\n" +
|
||||
"直行:${ledUI.stateStraight} 直行倒计时:${ledUI.stateStraight}\n" +
|
||||
"右转:${ledUI.stateTurnRight} 右转倒计时:${ledUI.durationTurnRight}\n"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package com.mogo.support.device.led
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.PriorityQueue
|
||||
import kotlin.math.ceil
|
||||
|
||||
open class BaseLedUIViewModel : ViewModel() {
|
||||
companion object {
|
||||
const val TAG = "LedUIViewModel"
|
||||
val DEFAULT_UI = WelcomeUI()
|
||||
}
|
||||
|
||||
private var baseUICountDownJob: Job? = null
|
||||
private var currentLedUI: LedUI
|
||||
private var currentCountDownJob: Job? = null
|
||||
private val restoreLedUIQueue = PriorityQueue<LedUI>()
|
||||
|
||||
private val currentLedUILiveData = MutableLiveData<LedUI>()
|
||||
|
||||
private var currentRouteInfoUI: RouteInfoUI? = null//当前线路信息UI
|
||||
private var currentStationReportUI: StationReportUI? = null//当前报站信息
|
||||
|
||||
|
||||
init {
|
||||
currentLedUI = DEFAULT_UI
|
||||
}
|
||||
|
||||
fun start() {
|
||||
viewModelScope.launch {
|
||||
restoreLastUI()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新线路信息
|
||||
*/
|
||||
fun updateCurrentRouteInfo(lineName: String) {
|
||||
Log.i(TAG, "线路信息更新 线路名称:$lineName")
|
||||
currentRouteInfoUI = RouteInfoUI(lineName)
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新报站信息
|
||||
*/
|
||||
fun updateCurrentStationReport(stationName: String, state: String) {
|
||||
Log.i(TAG, "报站信息更新 ${state}:$stationName 站点状态")
|
||||
currentStationReportUI = StationReportUI(stationName, state)
|
||||
}
|
||||
|
||||
open suspend fun receive(msg: LedUI) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"receive --> ${msg.javaClass.simpleName}[priority=${msg.priority}] current:${currentLedUI.javaClass.simpleName}[priority=${currentLedUI.priority}]"
|
||||
)
|
||||
if (msg.priority > currentLedUI.priority) {
|
||||
//优先级低但是需要打断恢复,放入队列,否则直接舍弃
|
||||
if (msg.interruptRestore) {
|
||||
Log.i(
|
||||
TAG,
|
||||
"receive --> 优先级低,放入等待队列 ${msg.javaClass.simpleName}[priority=${msg.priority}]"
|
||||
)
|
||||
if (msg is LedUICountDown) {
|
||||
val countdown = if (msg.countDownSeconds < 0) 0 else msg.countDownSeconds
|
||||
|
||||
// 如果是打断恢复的,不重新设置值
|
||||
if (msg.absCountDownTimestamp == 0L) {
|
||||
msg.absCountDownTimestamp =
|
||||
System.currentTimeMillis() + countdown * 1000L
|
||||
}
|
||||
}
|
||||
restoreLedUIQueue.offer(msg)
|
||||
} else {
|
||||
Log.i(
|
||||
TAG,
|
||||
"receive --> 优先级低,舍弃 ${msg.javaClass.simpleName}[priority=${msg.priority}]"
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// 打断当前 UI
|
||||
Log.i(
|
||||
TAG,
|
||||
"receive --> 优先级高或相等,打断当前 ${msg.javaClass.simpleName}[priority=${msg.priority}]"
|
||||
)
|
||||
if (msg is LedUIDataChange) {
|
||||
if (msg.isShow) {
|
||||
showUI(msg)
|
||||
} else {
|
||||
// 删除恢复队列中数据
|
||||
removeRestoreLedUI(msg)
|
||||
// 当前正在展示,取消展示
|
||||
if (currentLedUI.javaClass.simpleName == msg.javaClass.simpleName) {
|
||||
dismissUI(msg)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showUI(msg)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
suspend fun reset() {
|
||||
Log.i(TAG, "reset()")
|
||||
viewModelScope.launch {
|
||||
currentLedUI = DEFAULT_UI
|
||||
restoreLedUIQueue.clear()
|
||||
currentCountDownJob?.cancel()
|
||||
baseUICountDownJob?.cancel()
|
||||
cancelBasicUISwitch()
|
||||
currentRouteInfoUI = null
|
||||
currentStationReportUI = null
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun showUI(msg: LedUI) {
|
||||
Log.i(TAG, "showUI ledUI=${msg.javaClass.simpleName}[priority=${msg.priority}]")
|
||||
// 如果当前类型是 需要打断恢复的,放入等待队列
|
||||
if (currentLedUI.interruptRestore) {
|
||||
restoreLedUIQueue.offer(msg)
|
||||
}
|
||||
|
||||
currentCountDownJob?.also {
|
||||
it.cancel()
|
||||
}
|
||||
cancelBasicUISwitch()
|
||||
|
||||
handleLedUIShow(msg)
|
||||
currentLedUI = msg
|
||||
|
||||
// 倒计时类型的 处理倒计时逻辑
|
||||
if (msg is LedUICountDown) {
|
||||
val countdown = if (msg.countDownSeconds < 0) 0 else msg.countDownSeconds
|
||||
Log.d(TAG, "LedUICountDown delay=${msg.countDownSeconds}秒")
|
||||
|
||||
// 如果是打断恢复的,不重新设置值
|
||||
if (msg.absCountDownTimestamp == 0L) {
|
||||
msg.absCountDownTimestamp =
|
||||
System.currentTimeMillis() + countdown * 1000L
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
val delaySeconds =
|
||||
if (msg.absCountDownTimestamp > 0) {
|
||||
ceil((msg.absCountDownTimestamp - System.currentTimeMillis()) / 1000.0).toInt()
|
||||
} else
|
||||
countdown
|
||||
Log.d(TAG, "设置currentCountDownJob delay=${delaySeconds}秒")
|
||||
delay(delaySeconds * 1000L)
|
||||
restoreLastUI()
|
||||
}.also { currentCountDownJob = it }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun dismissUI(msg: LedUI) {
|
||||
Log.i(TAG, "dismissUI ledUI=${msg.javaClass.simpleName}[priority=${msg.priority}]")
|
||||
currentCountDownJob?.also {
|
||||
it.cancel()
|
||||
}
|
||||
removeRestoreLedUI(msg)
|
||||
restoreLastUI()
|
||||
}
|
||||
|
||||
private suspend fun restoreLastUI() {
|
||||
//恢复打断
|
||||
val restoreUI = pollRestoreLedUI()
|
||||
if (restoreUI != null) {
|
||||
showUI(restoreUI)
|
||||
} else {
|
||||
// 启动 车辆基础状态 切换
|
||||
startBasicUISwitchLoop()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun startBasicUISwitchLoop() {
|
||||
if (currentRouteInfoUI != null) {
|
||||
showUI(currentRouteInfoUI!!)
|
||||
} else if (currentStationReportUI != null) {
|
||||
showUI(currentStationReportUI!!)
|
||||
} else {
|
||||
showUI(WelcomeUI())
|
||||
}
|
||||
basicUISwitchInternal()
|
||||
}
|
||||
|
||||
private fun cancelBasicUISwitch() {
|
||||
Log.i(TAG, "cancelBaseUISwitch()")
|
||||
kotlin.runCatching { baseUICountDownJob?.cancel() }
|
||||
}
|
||||
|
||||
private suspend fun basicUISwitchInternal() {
|
||||
Log.i(TAG, "baseUISwitchInternal()")
|
||||
cancelBasicUISwitch()
|
||||
viewModelScope.launch {
|
||||
delay(10 * 1000L)
|
||||
if (currentLedUI.javaClass.simpleName == WelcomeUI::class.simpleName) {
|
||||
if (currentRouteInfoUI != null) {
|
||||
showUI(currentRouteInfoUI!!)
|
||||
} else {
|
||||
showUI(WelcomeUI())
|
||||
}
|
||||
} else if (currentLedUI.javaClass.simpleName == RouteInfoUI::class.simpleName) {
|
||||
if (currentStationReportUI != null) {
|
||||
showUI(currentStationReportUI!!)
|
||||
} else {
|
||||
showUI(WelcomeUI())
|
||||
}
|
||||
} else if (currentLedUI.javaClass.simpleName == StationReportUI::class.simpleName) {
|
||||
showUI(WelcomeUI())
|
||||
}
|
||||
basicUISwitchInternal()
|
||||
}.also { baseUICountDownJob = it }
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制屏幕 UI 展示
|
||||
*/
|
||||
protected open fun handleLedUIShow(ledUI: LedUI) {
|
||||
currentLedUILiveData.postValue(ledUI)
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤队列中时间戳小于指定时间的消息,取出优先级最高的消息
|
||||
*/
|
||||
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
|
||||
}
|
||||
} else {
|
||||
return message
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 从等待队列中删除目标类型数据
|
||||
*/
|
||||
private fun removeRestoreLedUI(msg: LedUI) {
|
||||
val toRemove = restoreLedUIQueue.filter {
|
||||
it.javaClass == msg.javaClass ||
|
||||
(it is LedUICountDown && it.countDownSeconds > 0
|
||||
&& it.absCountDownTimestamp <= System.currentTimeMillis())
|
||||
}
|
||||
restoreLedUIQueue.removeAll(toRemove.toSet())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.mogo.support.device.led
|
||||
|
||||
import android.util.Log
|
||||
import com.mogo.support.device.manager.cpower5a.LedScreenCpower5aManager
|
||||
import com.mogo.support.device.manager.cpower5a.common.LedScreen
|
||||
|
||||
/**
|
||||
* 前屏幕
|
||||
*/
|
||||
class FrontLedUIViewModel : BaseLedUIViewModel() {
|
||||
companion object {
|
||||
const val TAG = "FrontLedUIViewModel"
|
||||
|
||||
val supportUIList = mutableSetOf<String?>().also {
|
||||
it += WelcomeUI::class.simpleName
|
||||
it += FinishUI::class.simpleName
|
||||
it += RouteInfoUI::class.simpleName
|
||||
it += StationReportUI::class.simpleName
|
||||
it += ArriveStationUI::class.simpleName
|
||||
it += LeaveStationUI::class.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun receive(msg: LedUI) {
|
||||
if (supportUIList.contains(msg.javaClass.simpleName)) {
|
||||
Log.i(TAG, "receive --> ${msg.javaClass.simpleName}[priority=${msg.priority}] ")
|
||||
super.receive(msg)
|
||||
} else {
|
||||
Log.i(
|
||||
TAG,
|
||||
"receive --> 不支持的类型,放弃 ${msg.javaClass.simpleName}[priority=${msg.priority}] "
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleLedUIShow(ledUI: LedUI) {
|
||||
super.handleLedUIShow(ledUI)
|
||||
when (ledUI) {
|
||||
is WelcomeUI -> {
|
||||
LedScreenCpower5aManager.getInstance().playProgramWelcome(
|
||||
null,
|
||||
LedScreen.OUTWARD_FRONT,
|
||||
ledUI.hintMsg,
|
||||
ledUI.isForever
|
||||
)
|
||||
Log.e(TAG, "前屏 播放欢迎语:${ledUI.hintMsg} 是否永久展示:${ledUI.isForever}")
|
||||
}
|
||||
|
||||
is FinishUI -> {
|
||||
LedScreenCpower5aManager.getInstance().playProgramFinish(
|
||||
LedScreen.OUTWARD_FRONT,
|
||||
ledUI.hintMsg,
|
||||
)
|
||||
Log.e(TAG, "前屏 播放结束语:${ledUI.hintMsg}")
|
||||
}
|
||||
|
||||
is RouteInfoUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramLineInformation(LedScreen.OUTWARD_FRONT, ledUI.lineName)
|
||||
Log.e(TAG, "前屏 播放线路信息:${ledUI.lineName}")
|
||||
}
|
||||
|
||||
is StationReportUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramLineStationReport(
|
||||
LedScreen.OUTWARD_FRONT,
|
||||
ledUI.stationName,
|
||||
ledUI.state
|
||||
)
|
||||
Log.e(TAG, "前屏 播放报站 站点:${ledUI.stationName} 状态:${ledUI.state}")
|
||||
}
|
||||
|
||||
is ArriveStationUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramLineStationReportHint(
|
||||
LedScreen.OUTWARD_FRONT,
|
||||
"车辆进站"
|
||||
)
|
||||
Log.e(TAG, "前屏 播放车辆进站")
|
||||
}
|
||||
|
||||
is LeaveStationUI -> {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramLineStationReportHint(
|
||||
LedScreen.OUTWARD_FRONT,
|
||||
"车辆起步"
|
||||
)
|
||||
Log.e(TAG, "前屏 播放车辆起步")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package com.mogo.support.device.led
|
||||
|
||||
|
||||
import android.content.Context
|
||||
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
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object LedSourceManager {
|
||||
private val frontViewModel: FrontLedUIViewModel by lazy {
|
||||
FrontLedUIViewModel() // 初始化
|
||||
}
|
||||
private val backViewModel: BackLedUIViewModel by lazy {
|
||||
BackLedUIViewModel() // 初始化
|
||||
}
|
||||
private var typeTurnSignal = 0;//转向灯状态 0:无灯;1:左转;2:右转;3:双闪
|
||||
private var lastUpdateEmergencyBrakeTime = 0L//上次触发急刹展示的时间
|
||||
private var isDriver by Delegates.notNull<Boolean>()
|
||||
|
||||
fun init(isDriver: Boolean) {
|
||||
this.isDriver = isDriver
|
||||
}
|
||||
|
||||
|
||||
private fun receiveUI(ledUI: LedUI) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
frontViewModel.receive(ledUI)
|
||||
backViewModel.receive(ledUI)
|
||||
}
|
||||
}
|
||||
|
||||
//更新线路信息
|
||||
private fun updateLineNameUI(lineName: String) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
frontViewModel.updateCurrentRouteInfo(lineName)
|
||||
backViewModel.updateCurrentRouteInfo(lineName)
|
||||
}
|
||||
}
|
||||
|
||||
//更新报站信息
|
||||
private fun updateStationReportUI(stationName: String, state: String) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
frontViewModel.updateCurrentStationReport(stationName, state)
|
||||
backViewModel.updateCurrentStationReport(stationName, state)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新转向灯
|
||||
* type: 0:无灯;1:左转;2:右转;3:双闪
|
||||
*/
|
||||
fun updateTurnSignalData(type: Int) {
|
||||
if (isDriver) {
|
||||
if (typeTurnSignal != type) {
|
||||
typeTurnSignal = type
|
||||
receiveUI(TurnSignalUI(type != 0, type))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆急刹
|
||||
*/
|
||||
fun updateAccelerationData(acceleration: Double) {
|
||||
if (isDriver) {
|
||||
if (acceleration <= -2) {
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - lastUpdateEmergencyBrakeTime > 60 * 1000L) {//1m内不进行多次提示
|
||||
lastUpdateEmergencyBrakeTime = now
|
||||
receiveUI(EmergencyBrakeUI())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新红绿灯数据
|
||||
* state -1:表示 null; 0:表示 CLEAR; 1:表示 NONE; 2:表示 RED; 3:表示 YELLOW; 4:表示 GREEN;
|
||||
*/
|
||||
fun updateTrafficLightData(
|
||||
stateTurnRound: Int, durationTurnRound: Int,
|
||||
stateTurnLeft: Int, durationTurnLeft: Int,
|
||||
stateStraight: Int, durationStraight: Int,
|
||||
stateTurnRight: Int, durationTurnRight: Int
|
||||
) {
|
||||
if (isDriver) {
|
||||
var stateTurnRoundTemp: TrafficLightState? = null
|
||||
var stateTurnLeftTemp: TrafficLightState? = null
|
||||
var stateStraightTemp: TrafficLightState? = null
|
||||
var stateTurnRightTemp: TrafficLightState? = null
|
||||
|
||||
var durationTurnRoundTemp = durationTurnRound
|
||||
var durationTurnLeftTemp = durationTurnLeft
|
||||
var durationStraightTemp = durationStraight
|
||||
var durationTurnRightTemp = durationTurnRight
|
||||
|
||||
var isShow = true
|
||||
if (stateTurnRound == -1 && stateTurnLeft == -1 && stateStraight == -1 && stateTurnRight == -1) {
|
||||
isShow = false
|
||||
durationTurnRoundTemp = -1
|
||||
durationTurnLeftTemp = -1
|
||||
durationStraightTemp = -1
|
||||
durationTurnRightTemp = -1
|
||||
} else {
|
||||
stateTurnRoundTemp = transitionTurnType(stateTurnRound)
|
||||
stateTurnLeftTemp = transitionTurnType(stateTurnLeft)
|
||||
stateStraightTemp = transitionTurnType(stateStraight)
|
||||
stateTurnRightTemp = transitionTurnType(stateTurnRight)
|
||||
}
|
||||
|
||||
receiveUI(
|
||||
TrafficLightUI(
|
||||
isShow,
|
||||
stateTurnRoundTemp, durationTurnRoundTemp,
|
||||
stateTurnLeftTemp, durationTurnLeftTemp,
|
||||
stateStraightTemp, durationStraightTemp,
|
||||
stateTurnRightTemp, durationTurnRightTemp
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun transitionTurnType(type: Int): TrafficLightState {
|
||||
return when (type) {
|
||||
2 -> {
|
||||
TrafficLightState.RED
|
||||
}
|
||||
|
||||
3 -> {
|
||||
TrafficLightState.YELLOW
|
||||
}
|
||||
|
||||
4 -> {
|
||||
TrafficLightState.GREEN
|
||||
}
|
||||
|
||||
else -> {
|
||||
TrafficLightState.NONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发生行程相关
|
||||
* type=1或2的时 需要参数 lineName
|
||||
* type=3或4的时 需要参数 lineName departureStopName arrivalStopName isLastStop
|
||||
* type=5时 不需要任何参数
|
||||
*
|
||||
* @param type 事件类型, 1:行程开始, 2:行程结束, 3:出站, 4:进站, 5:城市占道施工预警
|
||||
* @param lineName 路线名
|
||||
* @param departureStopName 出站站点名
|
||||
* @param arrivalStopName 下一站到达站点名
|
||||
* @param isLastStop 是否最终站
|
||||
*/
|
||||
fun updateTripInfoData(
|
||||
type: Int,
|
||||
lineName: String,
|
||||
departureStopName: String,
|
||||
arrivalStopName: String,
|
||||
isLastStop: Boolean
|
||||
) {
|
||||
if (isDriver) {
|
||||
if (lineName.isNotEmpty()) {
|
||||
updateLineNameUI(lineName)
|
||||
}
|
||||
if (type == 1) {
|
||||
//开始
|
||||
updateLineNameUI(lineName);
|
||||
} else if (type == 2) {
|
||||
//结束
|
||||
receiveUI(FinishUI())
|
||||
} else if (type == 3) {
|
||||
//出站
|
||||
if (arrivalStopName.isNotEmpty()) {
|
||||
updateStationReportUI(arrivalStopName, "下一站")
|
||||
}
|
||||
} else if (type == 4) {
|
||||
//进站
|
||||
if (departureStopName.isNotEmpty()) {
|
||||
updateStationReportUI(
|
||||
departureStopName, if (isLastStop) {
|
||||
"终点站"
|
||||
} else {
|
||||
"下一站"
|
||||
}
|
||||
)
|
||||
}
|
||||
} else if (type == 5) {
|
||||
//道路施工
|
||||
receiveUI(RoadWorkAheadWarningUI())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 永久更改欢迎节目显示内容
|
||||
* context如果是null会设置失败
|
||||
*/
|
||||
fun foreverChangeWelcomeHint(context: Context?, hintMsg: String?) {
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramWelcome(context, LedScreen.OUTWARD_FRONT, hintMsg, true)
|
||||
LedScreenCpower5aManager.getInstance()
|
||||
.playProgramWelcome(context, LedScreen.OUTWARD_BACK, hintMsg, true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.mogo.support.device.led
|
||||
|
||||
import com.mogo.support.device.manager.cpower5a.common.TrafficLightState
|
||||
|
||||
open class LedUI(
|
||||
var priority: Int = 0,
|
||||
var interruptRestore: Boolean = false,
|
||||
) : Comparable<LedUI> {
|
||||
override fun compareTo(other: LedUI): Int = other.priority - this.priority
|
||||
override fun toString(): String {
|
||||
return "LedUI(priority=$priority, interruptRestore=$interruptRestore)"
|
||||
}
|
||||
}
|
||||
|
||||
open class LedUIBaseSwitch(
|
||||
priority: Int = 0,
|
||||
interruptRestore: Boolean = false,
|
||||
) : LedUI(priority, interruptRestore) {
|
||||
override fun toString(): String {
|
||||
return "LedUIBaseSwitch() ${super.toString()}"
|
||||
}
|
||||
}
|
||||
|
||||
open class LedUIDataChange(
|
||||
var isShow: Boolean = false,
|
||||
priority: Int = 0,
|
||||
interruptRestore: Boolean = false,
|
||||
) : LedUI(priority, interruptRestore) {
|
||||
override fun toString(): String {
|
||||
return "LedUIDataChange(isShow=$isShow) ${super.toString()}"
|
||||
}
|
||||
}
|
||||
|
||||
open class LedUICountDown(
|
||||
open var countDownSeconds: Int = 0,
|
||||
open var absCountDownTimestamp: Long = 0L,
|
||||
priority: Int = 0,
|
||||
interruptRestore: Boolean = false,
|
||||
) : LedUI(priority, interruptRestore) {
|
||||
override fun toString(): String {
|
||||
return "LedUICountDown(countDownSeconds=$countDownSeconds, absCountDownTimestamp=$absCountDownTimestamp) ${super.toString()}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//欢迎提示
|
||||
class WelcomeUI(val hintMsg: String? = null, val isForever: Boolean = false) :
|
||||
LedUIBaseSwitch(priority = 5) {
|
||||
}
|
||||
|
||||
//结束提示
|
||||
class FinishUI(val hintMsg: String = "感谢一路相伴") :
|
||||
LedUICountDown(priority = 5, countDownSeconds = 10)
|
||||
|
||||
//线路信息提示
|
||||
class RouteInfoUI(val lineName: String) : LedUIBaseSwitch(priority = 5)
|
||||
|
||||
//报站提示
|
||||
class StationReportUI(val stationName: String, val state: String) : LedUIBaseSwitch(priority = 5)
|
||||
|
||||
//进站提示 暂时没用
|
||||
class ArriveStationUI() :
|
||||
LedUICountDown(priority = 0, countDownSeconds = 10)
|
||||
|
||||
//出站提示 暂时没用
|
||||
class LeaveStationUI() :
|
||||
LedUICountDown(priority = 0, countDownSeconds = 10)
|
||||
|
||||
|
||||
/**
|
||||
* 转向灯提示
|
||||
* type: 0:无灯;1:左转;2:右转;3:双闪
|
||||
*/
|
||||
class TurnSignalUI(isShow: Boolean, val type: Int) :
|
||||
LedUIDataChange(isShow = isShow, priority = 3, interruptRestore = true)
|
||||
|
||||
|
||||
//急刹提示
|
||||
class EmergencyBrakeUI() :
|
||||
LedUICountDown(priority = 1, countDownSeconds = 5)
|
||||
|
||||
//信号灯提示
|
||||
class TrafficLightUI(
|
||||
isShow: Boolean,
|
||||
val stateTurnRound: TrafficLightState?, val durationTurnRound: Int,
|
||||
val stateTurnLeft: TrafficLightState?, val durationTurnLeft: Int,
|
||||
val stateStraight: TrafficLightState?, val durationStraight: Int,
|
||||
val stateTurnRight: TrafficLightState?, val durationTurnRight: Int
|
||||
) :
|
||||
LedUIDataChange(isShow = isShow, priority = 4, interruptRestore = true)
|
||||
|
||||
|
||||
//前方施工提示
|
||||
class RoadWorkAheadWarningUI() : LedUICountDown(priority = 2, countDownSeconds = 10)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user