@@ -1,12 +1,16 @@
package com.mogo.eagle.core.function.hmi.ui.widget
import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.eagle.core.data.autopilot.AdasOCHData
import com.mogo.eagle.core.function.call.hmi.CallerHmiListenerManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.util.LogUtils
import com.mogo.module.common.MogoApisHandler
import com.mogo.service.adas.IMogoAdasOCHCallback
import kotlinx.android.synthetic.main.view_autopilot_status.view.*
/**
@@ -17,20 +21,13 @@ import kotlinx.android.synthetic.main.view_autopilot_status.view.*
class AutoPilotStatusView @JvmOverloads constructor (
context : Context ,
attrs : AttributeSet
) : ConstraintLayout ( context , attrs ) {
) : ConstraintLayout ( context , attrs ) , View . OnClickListener , IMogoAdasOCHCallback {
private val TAG = " AutopilotStatusView "
private var mAutopilotStatus : Int = 0
init {
val typedArray : TypedArray =
context . obtainStyledAttributes ( attrs , R . styleable . AutopilotStatusView )
mAutopilotStatus = typedArray . getInt ( R . styleable . AutopilotStatusView _autopilotStatus , 0 )
typedArray . recycle ( )
LogUtils . dTag ( TAG , " autopilotStatus: $mAutopilotStatus " )
initView ( context )
}
@@ -40,16 +37,38 @@ class AutoPilotStatusView @JvmOverloads constructor(
val lp = LayoutParams ( LayoutParams . WRAP _CONTENT , LayoutParams . WRAP _CONTENT )
layoutParams = lp
// 设置点击监听
setOnClickListener ( this )
// 首次查询自动驾驶状态
mAutopilotStatus = MogoApisHandler . getInstance ( ) . apis . adasControllerApi . autopilotStatus
// 自动驾驶状态监听
MogoApisHandler . getInstance ( ) . apis . adasControllerApi . addAdasOCHCallback ( this )
LogUtils . dTag ( TAG , " autopilotStatus: $mAutopilotStatus " )
setAutoPilotStatus ( mAutopilotStatus )
}
override fun onClick ( v : View ? ) {
when ( mAutopilotStatus ) {
0 -> { // 不可自动驾驶, adas与工控机没有链接, 或工控机异常
LogUtils . eTag ( TAG , " 不可自动驾驶, adas与工控机没有链接, 或工控机异常,请检查链路 " )
}
1 -> { // 可自动驾驶,目前处于人工干预状态
CallerHmiListenerManager . invokeCheckAutoPilotBtnListener ( true )
}
2 -> { // 自动驾驶中
CallerHmiListenerManager . invokeCheckAutoPilotBtnListener ( false )
}
}
}
/**
* 设置自动驾驶状态
* 0-// 不可自动驾驶, adas与工控机没有链接, 或工控机异常
* 1-// 可自动驾驶,目前处于人工干预状态
* 2-// 自动驾驶中
*/
fun setAutoPilotStatus ( autopilotStatus : Int ) {
private fun setAutoPilotStatus ( autopilotStatus : Int ) {
mAutopilotStatus = autopilotStatus
when ( autopilotStatus ) {
0 -> { // 不可自动驾驶, adas与工控机没有链接, 或工控机异常
@@ -67,4 +86,13 @@ class AutoPilotStatusView @JvmOverloads constructor(
}
}
override fun onArriveAt ( data : AdasOCHData ? ) {
}
override fun onStateChanged ( state : Int , reason : String ? ) {
setAutoPilotStatus ( state )
}
}