[6.1.0][Fix]解决自动驾驶中不可介入平行驾驶的问题

This commit is contained in:
chenfufeng
2023-09-19 11:46:31 +08:00
parent 6c0d8b58fe
commit 7bd215e3db

View File

@@ -50,6 +50,8 @@ class ParallelDriveView @JvmOverloads constructor(
//1:ready, 2:自动驾驶中, 7:平行驾驶中
@Volatile
private var autopilotState: Int = 1
@Volatile
private var isAutoDriving: Boolean = false
// 初始状态为0
private var state: Int = 0
@@ -107,16 +109,25 @@ class ParallelDriveView @JvmOverloads constructor(
when (state) {
7 -> {
if (this.autopilotState != 7) {
isAutoDriving = false
ThreadUtils.runOnUiThread({
updateUI(PARALLEL_DRIVING)
}, ThreadUtils.MODE.QUEUE)
}
}
2 -> {
if (this.autopilotState != state) {
isAutoDriving = true
}
}
else -> {
if (this.autopilotState == 7 && this.autopilotState != state) {
ThreadUtils.runOnUiThread({
checkAvailableAndUpdateUI()
}, ThreadUtils.MODE.QUEUE)
if (this.autopilotState != state) {
isAutoDriving = false
if (this.autopilotState == 7) {
ThreadUtils.runOnUiThread({
checkAvailableAndUpdateUI()
}, ThreadUtils.MODE.QUEUE)
}
}
}
}
@@ -177,16 +188,6 @@ class ParallelDriveView @JvmOverloads constructor(
}
}
private fun isAvailable(unableAutopilotReasons: ArrayList<UnableLaunchReason>?): Boolean {
var unavailable = false
unableAutopilotReasons?.forEach {
if (it.source.ordinal == SourceType.CHASSIS.ordinal) {
unavailable = true
}
}
return !unavailable
}
@SuppressLint("UseCompatLoadingForDrawables")
private fun updateUI(state: Int) {
when (state) {
@@ -330,12 +331,17 @@ class ParallelDriveView @JvmOverloads constructor(
}
private fun checkAvailableAndUpdateUI() {
if (CallerParallelDrivingActionsListenerManager.isParallelDrivingAbility()) {
if (isAutoDriving) {
state = 0
updateUI(0)
} else {
state = UNAVAILABLE
updateUI(UNAVAILABLE)
if (CallerParallelDrivingActionsListenerManager.isParallelDrivingAbility()) {
state = 0
updateUI(0)
} else {
state = UNAVAILABLE
updateUI(UNAVAILABLE)
}
}
}