From c41c615f3f1d32d321ea6ea50a61b450e868f773 Mon Sep 17 00:00:00 2001 From: Tomek Zebrowski Date: Sun, 5 Jan 2025 20:34:18 +0100 Subject: [PATCH] feat: Add vehicle status reading --- .../org/obd/graphs/activity/MainActivity.kt | 2 + .../DynamicSelectorModeEventBroadcaster.kt | 11 ++-- .../bl/datalogger/DataLoggerPreferences.kt | 6 +- .../bl/extra/VehicleStatusEventBroadcaster.kt | 61 +++++++++++++++++++ .../org/obd/graphs/bl/query/ObdMetricExt.kt | 27 +++++++- .../bl/drag/DragRacingMetricsProcessor.kt | 47 +++++++------- gradle.properties | 2 +- .../graphs/renderer/drag/DragRacingDrawer.kt | 3 +- .../obd/graphs/renderer/gauge/GaugeDrawer.kt | 3 +- .../graphs/renderer/giulia/GiuliaDrawer.kt | 3 +- .../graphs/renderer/trip/TripInfoDrawer.kt | 3 +- 11 files changed, 128 insertions(+), 40 deletions(-) create mode 100644 datalogger/src/main/java/org/obd/graphs/bl/extra/VehicleStatusEventBroadcaster.kt diff --git a/app/src/main/java/org/obd/graphs/activity/MainActivity.kt b/app/src/main/java/org/obd/graphs/activity/MainActivity.kt index ca8f06dd..472e781b 100644 --- a/app/src/main/java/org/obd/graphs/activity/MainActivity.kt +++ b/app/src/main/java/org/obd/graphs/activity/MainActivity.kt @@ -43,6 +43,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton import org.obd.graphs.* import org.obd.graphs.bl.datalogger.dataLogger import org.obd.graphs.bl.drag.dragRacingMetricsProcessor +import org.obd.graphs.bl.extra.vehicleStatusEventBroadcaster import org.obd.graphs.bl.generator.MetricsGenerator import org.obd.graphs.bl.trip.tripManager import org.obd.graphs.profile.profile @@ -228,6 +229,7 @@ class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks { dataLogger .observe(dragRacingMetricsProcessor) .observe(tripManager) + .observe(vehicleStatusEventBroadcaster) if (BuildConfig.DEBUG){ dataLogger.observe(MetricsGenerator(BuildConfig.DEBUG)) diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/DynamicSelectorModeEventBroadcaster.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/DynamicSelectorModeEventBroadcaster.kt index 7a4c1bb7..5c23be93 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/DynamicSelectorModeEventBroadcaster.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/DynamicSelectorModeEventBroadcaster.kt @@ -3,6 +3,7 @@ package org.obd.graphs.aa.screen import android.util.Log import org.obd.graphs.bl.datalogger.MetricsProcessor import org.obd.graphs.bl.query.isDynamicSelector +import org.obd.graphs.bl.query.valueToNumber import org.obd.graphs.sendBroadcastEvent import org.obd.metrics.api.model.ObdMetric @@ -23,17 +24,17 @@ internal class DynamicSelectorModeEventBroadcaster: MetricsProcessor { if (obdMetric.isDynamicSelector()) { if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { - Log.v(LOG_TAG, "Received=${obdMetric.value.toInt()}, current=${currentMode} ") + Log.v(LOG_TAG, "Received=${obdMetric.valueToNumber()!!.toInt()}, current=${currentMode} ") } - if (currentMode != obdMetric.value) { + if (currentMode != obdMetric.valueToNumber()!!) { if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { - Log.v(LOG_TAG, "Broadcasting Dynamic Selector Mode Change, new=${obdMetric.value.toInt()}") + Log.v(LOG_TAG, "Broadcasting Dynamic Selector Mode Change, new=${obdMetric.valueToNumber()!!.toInt()}") } - currentMode = obdMetric.value.toInt() - when (obdMetric.value.toInt()) { + currentMode = obdMetric.valueToNumber()!!.toInt() + when (obdMetric.valueToNumber()!!.toInt()) { 0 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_NORMAL) 2 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_SPORT) 4 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_ECO) diff --git a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerPreferences.kt b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerPreferences.kt index f8014491..28de157a 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerPreferences.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerPreferences.kt @@ -63,7 +63,8 @@ data class DataLoggerPreferences( var gracefulStop: Boolean, var dumpRawConnectorResponse: Boolean, var delayAfterReset: Long, - var fuelTankSize: Int + var fuelTankSize: Int, + var vehicleStatusReading: Boolean ) @@ -157,10 +158,11 @@ class DataLoggerPreferencesManager { val resources = Prefs.getStringSet(PREF_MODULE_LIST, modules.getDefaultModules().keys)!! - val fuelTankSize = Prefs.getS("pref.vehicle_settings.fuelTankSize", "58").toInt() + val vehicleStatusReading = Prefs.getBoolean("pref.vehicle_settings.vehicleStatusReading", false) val dataLoggerPreferences = DataLoggerPreferences( + vehicleStatusReading = vehicleStatusReading, dragRacingCommandFrequency = dragRacingCommandFrequency, otherModesBatchSize = mode22batchSize?.toInt(), mode01BatchSize = mode01batchSize?.toInt(), diff --git a/datalogger/src/main/java/org/obd/graphs/bl/extra/VehicleStatusEventBroadcaster.kt b/datalogger/src/main/java/org/obd/graphs/bl/extra/VehicleStatusEventBroadcaster.kt new file mode 100644 index 00000000..b91ffa26 --- /dev/null +++ b/datalogger/src/main/java/org/obd/graphs/bl/extra/VehicleStatusEventBroadcaster.kt @@ -0,0 +1,61 @@ +package org.obd.graphs.bl.extra + +import android.util.Log +import org.obd.graphs.bl.datalogger.MetricsProcessor +import org.obd.graphs.bl.datalogger.dataLoggerPreferences +import org.obd.graphs.bl.query.isVehicleStatus +import org.obd.graphs.sendBroadcastEvent +import org.obd.metrics.api.model.ObdMetric + +const val EVENT_VEHICLE_STATUS_VEHICLE_MOVING = "event.vehicle.status.vehicle.moving" +const val EVENT_VEHICLE_STATUS_VEHICLE_IDLING = "event.vehicle.status.vehicle.idling" +const val EVENT_VEHICLE_STATUS_IGNITION_OFF = "event.vehicle.status.vehicle.ignition_off" +const val EVENT_VEHICLE_STATUS_VEHICLE_ACCELERATING = "event.vehicle.status.vehicle.accelerating" +const val EVENT_VEHICLE_STATUS_VEHICLE_DECELERATING = "event.vehicle.status.vehicle.decelerating" + +val vehicleStatusEventBroadcaster:MetricsProcessor = VehicleStatusEventBroadcaster() + +private const val LOG_TAG = "VehicleStatBroad" + +internal class VehicleStatusEventBroadcaster: MetricsProcessor { + private var currVehicleRunning = false + private var currEngineRunning = false + private var currKeyStatusOn = false + private var currVehicleAccelerating = false + private var currVehicleDecelerating = false + + + override fun postValue(obdMetric: ObdMetric) { + + if (dataLoggerPreferences.instance.vehicleStatusReading && obdMetric.isVehicleStatus()) { + + if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { + Log.v(LOG_TAG, "Received=${obdMetric.value}, ") + } + val value: Map = obdMetric.value as Map + val engineRunning = value["engine.running"]!! + val vehicleRunning = value["vehicle.running"]!! + val keyStatusOn = value["key.status"]!! + + if (currVehicleRunning != vehicleRunning || currEngineRunning != engineRunning || currKeyStatusOn != keyStatusOn) { + currVehicleRunning = vehicleRunning + currEngineRunning = engineRunning + currKeyStatusOn = keyStatusOn + currVehicleAccelerating = value["vehicle.accelerating"]!! + currVehicleDecelerating = value["vehicle.decelerating"]!! + + if (currEngineRunning && currVehicleRunning){ + sendBroadcastEvent(EVENT_VEHICLE_STATUS_VEHICLE_MOVING) + }else if (currEngineRunning && !currVehicleRunning){ + sendBroadcastEvent(EVENT_VEHICLE_STATUS_VEHICLE_IDLING) + }else if (!currEngineRunning && !currVehicleRunning && !currKeyStatusOn){ + sendBroadcastEvent(EVENT_VEHICLE_STATUS_IGNITION_OFF) + }else if (currVehicleAccelerating){ + sendBroadcastEvent(EVENT_VEHICLE_STATUS_VEHICLE_ACCELERATING) + }else if (currVehicleDecelerating){ + sendBroadcastEvent(EVENT_VEHICLE_STATUS_VEHICLE_DECELERATING) + } + } + } + } +} \ No newline at end of file diff --git a/datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt b/datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt index 080358e6..99763785 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt @@ -11,14 +11,32 @@ fun ObdMetric.valueToString(castToInt: Boolean = false, precision: Int = 2): Str if (this.value == null) { "No data" } else { - if (castToInt) value.toInt().toString() - else if (this.value is Double) value.toDouble().round(precision).toString() - else this.value.toString() + if (value is Number) { + if (castToInt) (value as Number).toInt().toString() + else if (this.value is Double) (value as Number).toDouble().round(precision).toString() + else this.value.toString() + } else { + "No data" + } } +fun ObdMetric.valueToNumber(): Number? = + if (this.value == null) { + null + } else { + if (value is Number) { + value as Number + } else { + null + } + } + + fun ObdMetric.isAtmPressure(): Boolean = command.pid.id == namesRegistry.getAtmPressurePID() fun ObdMetric.isAmbientTemp(): Boolean = command.pid.id == namesRegistry.getAmbientTempPID() +fun ObdMetric.isVehicleStatus(): Boolean = command.pid.id == namesRegistry.getVehicleStatusPID() + fun ObdMetric.isDynamicSelector(): Boolean = command.pid.id == namesRegistry.getDynamicSelectorPID() fun ObdMetric.isVehicleSpeed(): Boolean = command.pid.id == namesRegistry.getVehicleSpeedPID() fun ObdMetric.isEngineRpm(): Boolean = command.pid.id == namesRegistry.getEngineRpmPID() @@ -58,6 +76,7 @@ private const val OIL_PRESSURE_PID_ID = 7018L private const val GAS_PID_ID = 7007L private const val OIL_DEGRADATION_PID_ID = 7015L +private const val VEHICLE_STATUS_PID_ID = 17091L class PIDsNamesRegistry { @@ -97,4 +116,6 @@ class PIDsNamesRegistry { fun getEngineRpmPID(): Long = if (isGMEExtensionsEnabled()) EXT_ENGINE_RPM_PID_ID else ENGINE_RPM_PID_ID fun getDynamicSelectorPID(): Long = EXT_DYNAMIC_SELECTOR_PID_ID + + fun getVehicleStatusPID(): Long = VEHICLE_STATUS_PID_ID } \ No newline at end of file diff --git a/dragracing/src/main/java/org/obd/graphs/bl/drag/DragRacingMetricsProcessor.kt b/dragracing/src/main/java/org/obd/graphs/bl/drag/DragRacingMetricsProcessor.kt index e2746a2d..001445e5 100644 --- a/dragracing/src/main/java/org/obd/graphs/bl/drag/DragRacingMetricsProcessor.kt +++ b/dragracing/src/main/java/org/obd/graphs/bl/drag/DragRacingMetricsProcessor.kt @@ -20,10 +20,7 @@ package org.obd.graphs.bl.drag import android.util.Log import org.obd.graphs.bl.datalogger.MetricsProcessor -import org.obd.graphs.bl.query.isAmbientTemp -import org.obd.graphs.bl.query.isAtmPressure -import org.obd.graphs.bl.query.isEngineRpm -import org.obd.graphs.bl.query.isVehicleSpeed +import org.obd.graphs.bl.query.* import org.obd.metrics.api.model.ObdMetric import org.obd.metrics.api.model.VehicleCapabilities import kotlin.math.min @@ -70,14 +67,14 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult if (Log.isLoggable(LOG_KEY, Log.VERBOSE)) { Log.v( LOG_KEY, "Current revLimit='${registry.getShiftLightsRevThreshold()}', " + - "current rev: ${obdMetric.value.toInt()}, rising: ${obdMetric.value.toInt() > registry.getShiftLightsRevThreshold()}" + "current rev: ${obdMetric.valueToNumber()!!.toInt()}, rising: ${obdMetric.valueToNumber()!!.toInt() > registry.getShiftLightsRevThreshold()}" ) } - registry.enableShiftLights(obdMetric.value.toInt() > registry.getShiftLightsRevThreshold()) + registry.enableShiftLights(obdMetric.valueToNumber()!!.toInt() > registry.getShiftLightsRevThreshold()) } else if (obdMetric.isAtmPressure()) { - atmosphericPressure = obdMetric.value.toInt() + atmosphericPressure = obdMetric.valueToNumber()!!.toInt() } else if (obdMetric.isAmbientTemp()) { - ambientTemperature = obdMetric.value.toInt() + ambientTemperature = obdMetric.valueToNumber()!!.toInt() } else if (obdMetric.isVehicleSpeed()) { @@ -87,11 +84,11 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult private fun processVehicleSpeedData(obdMetric: ObdMetric) { - if (obdMetric.value.toInt() == SPEED_0_KM_H) { + if (obdMetric.valueToNumber()!!.toInt() == SPEED_0_KM_H) { reset0() if (Log.isLoggable(LOG_KEY, Log.VERBOSE)) { - Log.v(LOG_KEY, "Ready to measure, current speed: ${obdMetric.value}") + Log.v(LOG_KEY, "Ready to measure, current speed: ${obdMetric.valueToNumber()!!}") } registry.readyToRace(true) @@ -102,8 +99,8 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult } - if (isGivenSpeedReached(obdMetric, SPEED_60_KM_H - 5) && obdMetric.value.toInt() < SPEED_60_KM_H) { - Log.i(LOG_KEY, "Reset 60-140 measurement at speed: ${obdMetric.value.toInt()}") + if (isGivenSpeedReached(obdMetric, SPEED_60_KM_H - 5) && obdMetric.valueToNumber()!!.toInt() < SPEED_60_KM_H) { + Log.i(LOG_KEY, "Reset 60-140 measurement at speed: ${obdMetric.valueToNumber()!!.toInt()}") result60_140 = null _60ts = null } @@ -121,19 +118,19 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult registry.update060( dragRacingMetric.apply { time = result0_60!! - speed = obdMetric.value.toInt() + speed = obdMetric.valueToNumber()!!.toInt() ambientTemp = ambientTemperature atmPressure = atmosphericPressure } ) - Log.i(LOG_KEY, "Current speed: ${obdMetric.value}. Result: 0-60 ${result0_60}ms") + Log.i(LOG_KEY, "Current speed: ${obdMetric.valueToNumber()!!}. Result: 0-60 ${result0_60}ms") } } } - if (isGivenSpeedReached(obdMetric, SPEED_100_KM_H - 5) && obdMetric.value.toInt() < SPEED_100_KM_H) { - Log.i(LOG_KEY, "Reset 100-200 measurement at speed: ${obdMetric.value.toInt()}") + if (isGivenSpeedReached(obdMetric, SPEED_100_KM_H - 5) && obdMetric.valueToNumber()!!.toInt() < SPEED_100_KM_H) { + Log.i(LOG_KEY, "Reset 100-200 measurement at speed: ${obdMetric.valueToNumber()!!.toInt()}") result100_200 = null _100ts = null } @@ -151,7 +148,7 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult registry.update0100( dragRacingMetric.apply { time = result0_100!! - speed = obdMetric.value.toInt() + speed = obdMetric.valueToNumber()!!.toInt() ambientTemp = ambientTemperature atmPressure = atmosphericPressure } @@ -159,7 +156,7 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult ) if (Log.isLoggable(LOG_KEY, Log.VERBOSE)) { - Log.v(LOG_KEY, "Current speed: ${obdMetric.value}. Result: 0-100 ${result0_100}ms") + Log.v(LOG_KEY, "Current speed: ${obdMetric.valueToNumber()!!}. Result: 0-100 ${result0_100}ms") } } } @@ -171,13 +168,13 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult registry.update0160( dragRacingMetric.apply { time = result0_160!! - speed = obdMetric.value.toInt() + speed = obdMetric.valueToNumber()!!.toInt() ambientTemp = ambientTemperature atmPressure = atmosphericPressure } ) - Log.i(LOG_KEY, "Current speed: ${obdMetric.value}. Result: 0-160 ${result0_160}ms") + Log.i(LOG_KEY, "Current speed: ${obdMetric.valueToNumber()!!}. Result: 0-160 ${result0_160}ms") } } @@ -187,12 +184,12 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult registry.update100200( dragRacingMetric.apply { time = result100_200!! - speed = obdMetric.value.toInt() + speed = obdMetric.valueToNumber()!!.toInt() ambientTemp = ambientTemperature atmPressure = atmosphericPressure } ) - Log.i(LOG_KEY, "Current speed: ${obdMetric.value}. Result: 100-200 ${result100_200}ms") + Log.i(LOG_KEY, "Current speed: ${obdMetric.valueToNumber()!!}. Result: 100-200 ${result100_200}ms") } } @@ -202,20 +199,20 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult registry.update60140( dragRacingMetric.apply { time = result60_140!! - speed = obdMetric.value.toInt() + speed = obdMetric.valueToNumber()!!.toInt() ambientTemp = ambientTemperature atmPressure = atmosphericPressure } ) Log.i( LOG_KEY, - "Current speed: ${obdMetric.value}, _60ts=${_60ts}, _140ts=${obdMetric.timestamp}, Result: 60-140 ${result60_140}ms" + "Current speed: ${obdMetric.valueToNumber()!!}, _60ts=${_60ts}, _140ts=${obdMetric.timestamp}, Result: 60-140 ${result60_140}ms" ) } } } - private fun isGivenSpeedReached(obdMetric: ObdMetric, givenSpeed: Int): Boolean = min(obdMetric.value.toInt(), givenSpeed) == givenSpeed + private fun isGivenSpeedReached(obdMetric: ObdMetric, givenSpeed: Int): Boolean = min(obdMetric.valueToNumber()!!.toInt(), givenSpeed) == givenSpeed private fun reset0() { _0ts = null diff --git a/gradle.properties b/gradle.properties index 5ed0d387..5af25db9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,4 +19,4 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official -obdMetricVersion=9.33.3-SNAPSHOT +obdMetricVersion=11.0.0-SNAPSHOT diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingDrawer.kt index 9232b248..b76f865b 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingDrawer.kt @@ -24,6 +24,7 @@ import org.obd.graphs.bl.collector.Metric import org.obd.graphs.bl.drag.DragRacingEntry import org.obd.graphs.bl.drag.DragRacingResults import org.obd.graphs.bl.drag.VALUE_NOT_SET +import org.obd.graphs.bl.query.valueToNumber import org.obd.graphs.renderer.AbstractDrawer import org.obd.graphs.renderer.ScreenSettings import org.obd.graphs.round @@ -281,7 +282,7 @@ internal class DragRacingDrawer(context: Context, settings: ScreenSettings) : Ab paint.color = color val progress = valueScaler.scaleToNewRange( - it.source.value?.toFloat() ?: it.source.command.pid.min.toFloat(), + it.source.valueToNumber()?.toFloat() ?: it.source.command.pid.min.toFloat(), it.source.command.pid.min.toFloat(), it.source.command.pid.max.toFloat(), left, left + width - MARGIN_END ) diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/gauge/GaugeDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/gauge/GaugeDrawer.kt index 4a95da19..bd4215a5 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/gauge/GaugeDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/gauge/GaugeDrawer.kt @@ -21,6 +21,7 @@ package org.obd.graphs.renderer.gauge import android.content.Context import android.graphics.* import org.obd.graphs.bl.collector.Metric +import org.obd.graphs.bl.query.valueToNumber import org.obd.graphs.commons.R import org.obd.graphs.renderer.AbstractDrawer import org.obd.graphs.renderer.GaugeProgressBarType @@ -177,7 +178,7 @@ internal class GaugeDrawer( setProgressGradient(rect) } - val value = metric.source.value?.toFloat() ?: metric.source.command.pid.min.toFloat() + val value = metric.source.valueToNumber()?.toFloat() ?: metric.source.command.pid.min.toFloat() val startValue = metric.source.command.pid.min.toFloat() val endValue = metric.source.command.pid.max.toFloat() diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/giulia/GiuliaDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/giulia/GiuliaDrawer.kt index bd2b43cc..6024f8f9 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/giulia/GiuliaDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/giulia/GiuliaDrawer.kt @@ -21,6 +21,7 @@ package org.obd.graphs.renderer.giulia import android.content.Context import android.graphics.* import org.obd.graphs.bl.collector.Metric +import org.obd.graphs.bl.query.valueToNumber import org.obd.graphs.renderer.AbstractDrawer import org.obd.graphs.renderer.ScreenSettings @@ -173,7 +174,7 @@ internal class GiuliaDrawer(context: Context, settings: ScreenSettings): Abstrac paint.color = color val progress = valueScaler.scaleToNewRange( - it.source.value?.toFloat() ?: it.source.command.pid.min.toFloat(), + it.source.valueToNumber()?.toFloat() ?: it.source.command.pid.min.toFloat(), it.source.command.pid.min.toFloat(), it.source.command.pid.max.toFloat(), left, left + width - MARGIN_END ) diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt index fdb44769..d8300571 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt @@ -22,6 +22,7 @@ import android.content.Context import android.graphics.* import org.obd.graphs.bl.collector.Metric import org.obd.graphs.bl.collector.MetricsBuilder +import org.obd.graphs.bl.query.valueToNumber import org.obd.graphs.bl.query.valueToString import org.obd.graphs.renderer.AbstractDrawer import org.obd.graphs.renderer.ScreenSettings @@ -240,7 +241,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst paint.color = color val progress = valueScaler.scaleToNewRange( - it.source.value?.toFloat() ?: it.source.command.pid.min.toFloat(), + it.source.valueToNumber()?.toFloat() ?: it.source.command.pid.min.toFloat(), it.source.command.pid.min.toFloat(), it.source.command.pid.max.toFloat(), left, left + width - MARGIN_END )