[清扫车]车辆基本信息view修改
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
package com.mogo.och.sweeper.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import chassis.Chassis.GearPosition
|
||||
import chassis.Chassis.LightSwitch
|
||||
import chassis.ChassisStatesOuterClass.BMSSystemStates
|
||||
import chassis.ChassisStatesOuterClass.SweeperFuTianTaskSystemStates
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotVehicleStateListener
|
||||
import com.mogo.eagle.core.function.api.v2x.LimitingVelocityListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotVehicleStateListenerManager.addListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotVehicleStateListenerManager.removeListener
|
||||
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager.setProxyTrafficLightView
|
||||
import com.mogo.eagle.core.function.call.v2x.CallLimitingVelocityListenerManager.addListener
|
||||
import com.mogo.eagle.core.function.call.v2x.CallLimitingVelocityListenerManager.removeListener
|
||||
import com.mogo.eagle.core.function.hmi.ui.widget.TapPositionView
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.sweeper.R
|
||||
import planning.RoboSweeperTaskIndexOuterClass
|
||||
import kotlin.math.abs
|
||||
|
||||
class SweeperTrafficDataView : ConstraintLayout {
|
||||
private var tapPositionView //方向盘
|
||||
: TapPositionView? = null
|
||||
private var speedImage //速度图标
|
||||
: ImageView? = null
|
||||
private var speedTextView //速度值
|
||||
: TextView? = null
|
||||
private var sweeperTurnSignal //转向灯
|
||||
: TurnSignalView? = null
|
||||
private var sweeperLimitingVelocity //限速
|
||||
: SweeperLimitingVelocityView? = null
|
||||
private var tvBattery //电量百分比展示
|
||||
: TextView? = null
|
||||
private var ivBgWaterWarning //水位预警背景图
|
||||
: ImageView? = null
|
||||
private var ivWater //水位图标
|
||||
: ImageView? = null
|
||||
private var trafficLight //红绿灯
|
||||
: SweeperTrafficLightView? = null
|
||||
|
||||
constructor(context: Context) : super(context) {}
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
|
||||
initView(context)
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {}
|
||||
|
||||
private fun initView(context: Context) {
|
||||
LayoutInflater.from(context).inflate(R.layout.sweeper_traffic_data, this)
|
||||
tapPositionView = findViewById(R.id.sweeperTrafficPosition)
|
||||
speedImage = findViewById(R.id.sweeperSpeedImage)
|
||||
speedTextView = findViewById(R.id.sweeperSpeedText)
|
||||
sweeperTurnSignal = findViewById(R.id.sweeperTurnSignal)
|
||||
sweeperLimitingVelocity = findViewById(R.id.sweeperLimitingVelocity)
|
||||
tvBattery = findViewById(R.id.tvBattery)
|
||||
ivBgWaterWarning = findViewById(R.id.sweeperIvBgWaterWarning)
|
||||
ivWater = findViewById(R.id.sweeperIvWater)
|
||||
trafficLight = findViewById(R.id.sweeperTrafficLight)
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
addListener(TAG, mIMoGoAutopilotVehicleStateListener)
|
||||
//增加限速监听
|
||||
addListener(TAG, limitingVelocityListener)
|
||||
setProxyTrafficLightView(trafficLight!!)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
removeListener(mIMoGoAutopilotVehicleStateListener)
|
||||
removeListener(limitingVelocityListener)
|
||||
}
|
||||
|
||||
private val mIMoGoAutopilotVehicleStateListener: IMoGoAutopilotVehicleStateListener = object : IMoGoAutopilotVehicleStateListener {
|
||||
override fun onSweeperFutianTaskIndexData(roboSweeperTaskIndex: RoboSweeperTaskIndexOuterClass.RoboSweeperTaskIndex) {}
|
||||
override fun onSweeperFutianCleanSystemState(cleanSystemState: SweeperFuTianTaskSystemStates) {
|
||||
if (cleanSystemState.hasSecuCleanWaterTankLow()) { //清水箱水位低不能清洗作业报警信号
|
||||
ivBgWaterWarning?.visibility = VISIBLE
|
||||
ivWater?.isSelected = true
|
||||
} else {
|
||||
ivBgWaterWarning?.visibility = GONE
|
||||
ivWater?.isSelected = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBMSSystemStates(bmsSystemStates: BMSSystemStates) {
|
||||
tvBattery?.text = String.format("%s%", bmsSystemStates.bmsSoc)
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆转向灯
|
||||
* @param lightSwitch
|
||||
*/
|
||||
override fun onAutopilotLightSwitchData(lightSwitch: LightSwitch?) {
|
||||
//转向灯状态 0是正常 1是左转 2是右转
|
||||
if (lightSwitch != null) {
|
||||
d(TAG, "车辆转向灯:$lightSwitch")
|
||||
if (lightSwitch.number == 1) {
|
||||
sweeperTurnSignal?.showLeftSignal()
|
||||
} else if (lightSwitch.number == 2) {
|
||||
sweeperTurnSignal?.showRightSignal()
|
||||
} else {
|
||||
sweeperTurnSignal?.showDirection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刹车灯
|
||||
* @param brakeLight
|
||||
*/
|
||||
override fun onAutopilotBrakeLightData(brakeLight: Boolean) {
|
||||
d(TAG, "刹车灯:$brakeLight")
|
||||
}
|
||||
|
||||
/**
|
||||
* 方向盘转向角 左+右-
|
||||
* @param steering
|
||||
*/
|
||||
override fun onAutopilotSteeringData(steering: Float) {
|
||||
var steering = steering
|
||||
d(TAG, "steering原始值====$steering")
|
||||
if (abs(steering) < 1) {
|
||||
steering = 0f
|
||||
}
|
||||
d(TAG, "steering忽略小数点后====" + steering.toInt())
|
||||
}
|
||||
|
||||
/**
|
||||
* 档位
|
||||
* @param gear
|
||||
*/
|
||||
override fun onAutopilotGearData(gear: GearPosition) {
|
||||
d(TAG, "司机屏档位$gear")
|
||||
ThreadUtils.runOnUiThread {
|
||||
tapPositionView?.updateWithGear(gear)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotDataException(timestamp: Long) {}
|
||||
override fun onAutopilotAcc(carAcc: Float) {}
|
||||
override fun onAutopilotBrake(brake: Float) {
|
||||
d(TAG, "刹车:$brake")
|
||||
}
|
||||
|
||||
override fun onAutopilotThrottle(throttle: Float) {
|
||||
d(TAG, "油门:$throttle")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 限速监听
|
||||
*/
|
||||
private val limitingVelocityListener: LimitingVelocityListener = object : LimitingVelocityListener {
|
||||
override fun onLimitingVelocityChange(limitingVelocity: Int) {
|
||||
//设置限速
|
||||
sweeperLimitingVelocity!!.updateLimitingSpeed(limitingVelocity)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 速度设置
|
||||
*/
|
||||
fun updateSpeedWithValue(newSpeed: Int) {
|
||||
speedTextView?.text = newSpeed.toString()
|
||||
speedImage?.setBackgroundResource(if (newSpeed > 60) R.drawable.sweeper_traffic_data_speed_warning else R.drawable.sweeper_bg_traffic_data_speed)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SweeperTrafficDataView"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user