From 9256b3c013cbe5a50fb6d6d5ab2075cbcacb4b0e Mon Sep 17 00:00:00 2001 From: Tomek Zebrowski Date: Tue, 16 Jul 2024 18:19:55 +0200 Subject: [PATCH] feat: Put all metrics to trip screen --- .../renderer/AbstractSurfaceRenderer.kt | 12 +++ .../drag/DragRacingSurfaceRenderer.kt | 11 --- .../obd/graphs/renderer/trip/TripDrawer.kt | 83 +++++++------------ .../renderer/trip/TripSurfaceRenderer.kt | 40 ++++++--- 4 files changed, 70 insertions(+), 76 deletions(-) diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/AbstractSurfaceRenderer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/AbstractSurfaceRenderer.kt index 6dd4bb65..d4bb43e1 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/AbstractSurfaceRenderer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/AbstractSurfaceRenderer.kt @@ -19,6 +19,7 @@ package org.obd.graphs.renderer import android.content.Context +import android.graphics.Canvas import android.graphics.Rect import org.obd.graphs.bl.collector.MetricsCollector import org.obd.graphs.bl.datalogger.dataLoggerPreferences @@ -49,6 +50,17 @@ internal abstract class AbstractSurfaceRenderer( } } + protected fun getArea(area: Rect, canvas: Canvas, margin: Int): Rect { + val newArea = Rect() + if (area.isEmpty) { + newArea[0 + margin, viewSettings.marginTop, canvas.width - 1 - margin] = canvas.height - 1 + } else { + val width = canvas.width - 1 - (margin) + newArea[area.left + margin, area.top + viewSettings.marginTop, width] = canvas.height + } + return newArea + } + protected fun metrics() = metricsCollector.getMetrics().subList( 0, min( metricsCollector.getMetrics().size, diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingSurfaceRenderer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingSurfaceRenderer.kt index d3951afc..086898de 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingSurfaceRenderer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingSurfaceRenderer.kt @@ -102,17 +102,6 @@ internal class DragRacingSurfaceRenderer( } } - private fun getArea(area: Rect, canvas: Canvas, margin: Int) : Rect { - val newArea = Rect() - if (area.isEmpty) { - newArea[0 + margin, viewSettings.marginTop, canvas.width - 1 - margin] = canvas.height - 1 - } else { - val width = canvas.width - 1 - (margin) - newArea[area.left + margin, area.top + viewSettings.marginTop, width] = canvas.height - } - return newArea - } - private fun isShiftLight(dragRaceResults: DragRacingResults) = settings.getDragRacingSettings().shiftLightsEnabled && dragRaceResults.enableShiftLights diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripDrawer.kt index 83709896..daddf9d1 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripDrawer.kt @@ -39,40 +39,29 @@ internal class TripDrawer(context: Context, settings: ScreenSettings) : Abstract tripInfo: TripInfoDetails ) { - val (_, textSizeBase) = calculateFontSize(area) + val textSizeBase = calculateFontSize(area) - val currentXPos = area.centerX() / 1.5f - val lastXPos = area.centerX() + 60f - val bestXPos = area.centerX() * 1.60f + val x = 130 + var rowTop = top + 10f + drawMetric(tripInfo.airTemp, "Intake Temp", rowTop, left, canvas, textSizeBase) + drawMetric(tripInfo.ambientTemp, "Ambient Temp", rowTop, left + x, canvas, textSizeBase) + drawMetric(tripInfo.coolantTemp, "Coolant Temp", rowTop, left + 2 * x, canvas, textSizeBase) + drawMetric(tripInfo.oilTemp, "Oil Temp", rowTop, left + 3 * x, canvas, textSizeBase) + drawMetric(tripInfo.exhaustTemp, "Exhaust Temp", rowTop, left + 4 * x, canvas, textSizeBase) + drawMetric(tripInfo.gearboxOilTemp, "Gearbox Temp", rowTop, left + 5 * x, canvas, textSizeBase) - // legend - drawText(canvas, "Current", currentXPos, top, textSizeBase, color = Color.LTGRAY) - drawText(canvas, "Last", lastXPos, top, textSizeBase, color = Color.LTGRAY) - drawText(canvas, "Best", bestXPos, top, textSizeBase, color = Color.LTGRAY) - // 0-60 - var rowTop = top + textSizeBase + 12f - drawDragRacingEntry(area, tripInfo.airTemp, "airTemp", rowTop, left,canvas, textSizeBase) + rowTop = top + (textSizeBase) + 42f + drawMetric(tripInfo.fuellevel, "Fuel Level", rowTop, left, canvas, textSizeBase) + drawMetric(tripInfo.gearboxEngaged, "Selected gear", rowTop, left + x, canvas, textSizeBase) + drawMetric(tripInfo.atmPressure, "Atm pressure", rowTop, left + 2 * x, canvas, textSizeBase) + drawMetric(tripInfo.vehicleSpeed, "Vehicle speed", rowTop, left + 3 * x, canvas, textSizeBase) + drawMetric(tripInfo.fuelConsumption, "Fuel Consumption", rowTop, left + 4 * x, canvas, textSizeBase) - // 0 - 100 - rowTop = top + (2 * textSizeBase) + 24f - drawDragRacingEntry(area, tripInfo.ambientTemp, "ambientTemp", rowTop, left, canvas, textSizeBase) - - // 60 - 140 - rowTop = top + (3 * textSizeBase) + 36f - drawDragRacingEntry(area,tripInfo.coolantTemp, "coolantTemp", rowTop, left,canvas, textSizeBase) - - // 0 - 160 - rowTop = top + (4 * textSizeBase) + 48f - drawDragRacingEntry(area,tripInfo.fuellevel, "fuelevel", rowTop, left, canvas, textSizeBase) - - // 100 - 200 - rowTop = top + (5 * textSizeBase) + 60f - drawDragRacingEntry(area, tripInfo.fuelConsumption, "fuelConsumption", rowTop, left, canvas, textSizeBase) } - fun drawText( + private fun drawText( canvas: Canvas, text: String, left: Float, @@ -94,34 +83,22 @@ internal class TripDrawer(context: Context, settings: ScreenSettings) : Abstract private inline fun calculateFontSize( area: Rect - ): Pair { - - val scaleRatio = valueScaler.scaleToNewRange(settings.getDragRacingSettings().fontSize.toFloat(), - CURRENT_MIN, CURRENT_MAX, NEW_MIN, NEW_MAX) - - val areaWidth = area.width() - val valueTextSize = (areaWidth / 18f) * scaleRatio - val textSizeBase = (areaWidth / 21f) * scaleRatio - return Pair(valueTextSize, textSizeBase) - } - + ): Float = (area.width() / 12f) * valueScaler.scaleToNewRange( + settings.getDragRacingSettings().fontSize.toFloat(), + CURRENT_MIN, CURRENT_MAX, NEW_MIN, NEW_MAX + ) - private inline fun drawDragRacingEntry(area: Rect, - value: Number?, - label: String, - top: Float, - left:Float, - canvas: Canvas, - textSizeBase: Float) { - - val currentXPos = area.centerX() / 1.5f - val lastXPos = area.centerX() + 60f - - drawText(canvas, label, left, top, textSizeBase, color = Color.LTGRAY) - drawText(canvas, timeToString(value), currentXPos, top, textSizeBase) - - drawText(canvas, timeToString(value), lastXPos, top, textSizeBase) + private inline fun drawMetric( + value: Number?, + label: String, + top: Float, + left: Float, + canvas: Canvas, + textSizeBase: Float + ) { + drawText(canvas, timeToString(value), left, top, textSizeBase, color = Color.WHITE) + drawText(canvas, label, left, top + 24, textSizeBase * 0.35F, color = Color.LTGRAY) } private inline fun timeToString(value: Number?): String = value?.toString() ?: "---" diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripSurfaceRenderer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripSurfaceRenderer.kt index 175a63b2..641ee66b 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripSurfaceRenderer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripSurfaceRenderer.kt @@ -78,8 +78,6 @@ internal class TripSurfaceRenderer( top += 40 } - - tripDrawer.drawScreen( canvas = canvas, area = area, @@ -103,21 +101,39 @@ internal class TripSurfaceRenderer( tripInfo.apply { atmPressure = it.value } } - return tripInfo - } + metricsCollector.getMetric(namesRegistry.getFuelLevelPID())?.let { + tripInfo.apply { fuellevel = it.value } + } + + metricsCollector.getMetric(namesRegistry.getFuelConsumptionPID())?.let { + tripInfo.apply { fuelConsumption = it.value } + } + + metricsCollector.getMetric(namesRegistry.getCoolantTempPID())?.let { + tripInfo.apply { coolantTemp = it.value } + } - private fun getArea(area: Rect, canvas: Canvas, margin: Int): Rect { - val newArea = Rect() - if (area.isEmpty) { - newArea[0 + margin, viewSettings.marginTop, canvas.width - 1 - margin] = canvas.height - 1 - } else { - val width = canvas.width - 1 - (margin) - newArea[area.left + margin, area.top + viewSettings.marginTop, width] = canvas.height + metricsCollector.getMetric(namesRegistry.getExhaustTempPID())?.let { + tripInfo.apply { exhaustTemp = it.value } } - return newArea + + metricsCollector.getMetric(namesRegistry.getOilTempPID())?.let { + tripInfo.apply { oilTemp = it.value } + } + + metricsCollector.getMetric(namesRegistry.getGearboxOilTempPID())?.let { + tripInfo.apply { gearboxOilTemp = it.value } + } + + metricsCollector.getMetric(namesRegistry.getGearboxEngagedPID())?.let { + tripInfo.apply { gearboxEngaged = it.value } + } + + return tripInfo } + override fun recycle() { tripDrawer.recycle() }