diff --git a/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt b/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt index 0eee5b0f02..2338a96eeb 100644 --- a/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt +++ b/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt @@ -133,7 +133,7 @@ class TestAutoPilotBeforeLaunch { CallerChassisThrottleStateListenerManager.invokeAutopilotThrottle(Random.nextInt(0..100).toFloat()) CallerChassisGearStateListenerManager.invokeAutopilotGearData(GEAR_R) val current = CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02() - CallerChassisLocationGCJ02ListenerManager.invokeChassisLocationGCJ02(current.also { it.gnssSpeed = Random.nextInt(0 ..20).toFloat() }, DEFAULT) + CallerChassisLocationGCJ02ListenerManager.invokeChassisLocationGCJ02(current.also { it.gnssSpeed = Random.nextInt(0 ..20).toFloat(); it.setAcceleration(Random.nextInt(-100, 100).toDouble()) }, DEFAULT) delay(Random.nextInt(10..50).toLong()) } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt index 510f5f65a0..da3bd8b718 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt @@ -297,12 +297,31 @@ interface IAutopilotPreLaunchStatus /** * 速度 */ -data class SpeedStatus(val speed: Float): Status(), IAutopilotPreLaunchStatus { - +data class SpeedStatus(val speed: Float, var acc: Float): Status(), IAutopilotPreLaunchStatus { override fun isException(): Boolean { return false } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as SpeedStatus + + if (speed != other.speed) return false + if (acc != other.acc) return false + + return true + } + + override fun hashCode(): Int { + var result = speed.hashCode() + result = 31 * result + acc.hashCode() + return result + } + + } /** diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/SpeedImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/SpeedImpl.kt index 23448af35f..aac970108a 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/SpeedImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/SpeedImpl.kt @@ -24,7 +24,10 @@ internal class SpeedImpl(ctx: Context): IFlow(ctx), IMoGoChassisLoc } @Volatile - private var last: Float? = null + private var lastSpeed: Float? = null + + @Volatile + private var lastAcc: Float? = null override fun onCreate() { CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 5, this) @@ -36,10 +39,17 @@ internal class SpeedImpl(ctx: Context): IFlow(ctx), IMoGoChassisLoc } override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) { - if (last != mogoLocation?.gnssSpeed) { - send(SpeedStatus(mogoLocation?.gnssSpeed ?: 0f)) - last = mogoLocation?.gnssSpeed + var isChanged = false + if (lastSpeed != mogoLocation?.gnssSpeed) { + isChanged = true + lastSpeed = mogoLocation?.gnssSpeed + } + if (!isChanged && lastAcc != mogoLocation?.acceleration) { + isChanged = true + lastAcc = mogoLocation?.acceleration + } + if (isChanged) { + send(SpeedStatus(mogoLocation?.gnssSpeed ?: 0f, mogoLocation?.acceleration ?: 0f)) } } - } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/model/StatusModel.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/model/StatusModel.kt index 64b1e24b93..22e35db332 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/model/StatusModel.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/model/StatusModel.kt @@ -26,7 +26,7 @@ internal class StatusModel : ViewModel() { it += DoubleFlashStatus(0) it += GearStatus(0) it += RouteDownloadStatus() - it += SpeedStatus(0f) + it += SpeedStatus(0f, 0f) }) } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/AutoPilotLaunchBeforeView.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/AutoPilotLaunchBeforeView.kt index f49364708a..61e8c028de 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/AutoPilotLaunchBeforeView.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/AutoPilotLaunchBeforeView.kt @@ -88,9 +88,7 @@ class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener { } } is AcceleratorStatus -> { - val angle = status.angle iv_brake_or_accelerator?.isSelected = isError - tv_brake_or_accelerator?.text = "a:${angle.toInt()}" } is BrakeStatus -> { val angle = status.angle @@ -105,6 +103,7 @@ class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener { } is SpeedStatus -> { speed?.text = "${(abs(status.speed) * 3.6f).toInt()}" + tv_brake_or_accelerator?.text = String.format("%.1f", status.acc) } else -> { Logger.d(TAG, "other state: $status")