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 01d86002..ac6b7874 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 @@ -37,12 +37,22 @@ private const val AIR_TEMP_PID_ID = 7002L private const val TOTAL_MISFIRES_PID_ID = 17078L private const val OIL_LEVEL_PID_ID = 7014L +private const val ENGINE_TORQUE_PID_ID = 7028L +private const val INTAKE_PRESSURE_PID_ID = 7005L + + + + class PIDsNamesRegistry { fun getTotalMisfiresPID(): Long = TOTAL_MISFIRES_PID_ID fun getOilLevelPID(): Long = OIL_LEVEL_PID_ID + fun getTorquePID(): Long = ENGINE_TORQUE_PID_ID + + fun getIntakePressurePID(): Long = INTAKE_PRESSURE_PID_ID + fun getFuelConsumptionPID(): Long = FUEL_CONSUMPTION_PID_ID fun getFuelLevelPID(): Long = FUEL_LEVEL_PID_ID diff --git a/datalogger/src/main/java/org/obd/graphs/bl/query/TripInfoQueryStrategy.kt b/datalogger/src/main/java/org/obd/graphs/bl/query/TripInfoQueryStrategy.kt index 8e0d0bd6..7584236e 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/query/TripInfoQueryStrategy.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/query/TripInfoQueryStrategy.kt @@ -35,6 +35,8 @@ internal class TripInfoQueryStrategy : QueryStrategy() { namesRegistry.getAirTempPID(), namesRegistry.getTotalMisfiresPID(), namesRegistry.getOilLevelPID(), - ) + namesRegistry.getTorquePID(), + namesRegistry.getIntakePressurePID(), + ) } 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 d4d0979a..e52ecdb2 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 @@ -23,6 +23,9 @@ import android.graphics.* import org.obd.graphs.bl.collector.Metric import org.obd.graphs.renderer.AbstractDrawer import org.obd.graphs.renderer.ScreenSettings +import org.obd.graphs.renderer.drag.MARGIN_END +import org.obd.graphs.ui.common.COLOR_WHITE + private const val CURRENT_MIN = 22f private const val CURRENT_MAX = 72f @@ -59,7 +62,133 @@ internal class TripDrawer(context: Context, settings: ScreenSettings) : Abstract drawMetric(tripInfo.totalMisfires!!, rowTop, left + 3 * x, canvas, textSizeBase) drawMetric(tripInfo.fuelConsumption!!, rowTop, left + 4 * x, canvas, textSizeBase) drawMetric(tripInfo.oilLevel!!, rowTop, left + 5 * x, canvas, textSizeBase) + drawDivider(canvas, left, area.width().toFloat(), rowTop + textSizeBase + 2, Color.DKGRAY) + + + //metrics + drawMetric(canvas,area, tripInfo.intakePressure!!,left,rowTop + 2 * textSizeBase) + drawMetric(canvas,area, tripInfo.torque!!,getAreaWidth(area) + 10,rowTop + 2 * textSizeBase) + + } + + private inline fun calculateFontSize2( + 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) + } + + private inline fun drawMetric( + canvas: Canvas, + area: Rect, + metric: Metric, + left: Float, + top: Float + ): Float { + + val (valueTextSize, textSizeBase) = calculateFontSize2(area) + + var top1 = top + var left1 = left + + drawTitle( + canvas, + metric, + left1, + top1, + textSizeBase + ) + + drawValue( + canvas, + metric, + area, + top1 + 44, + valueTextSize, + left + ) + + top1 += 54f + + drawProgressBar( + canvas, + left, + getAreaWidth(area), top1, metric, + color = settings.getColorTheme().progressColor + ) + + top1 += calculateDividerSpacing() + + drawDivider( + canvas, + left, getAreaWidth(area), top1, + color = settings.getColorTheme().dividerColor + ) + + top1 += 10f + (textSizeBase).toInt() + return top1 + } + + private inline fun calculateDividerSpacing(): Int = 14 + private inline fun getAreaWidth(area: Rect): Float = area.width().toFloat() / 2 + + private fun drawProgressBar( + canvas: Canvas, + left: Float, + width: Float, + top: Float, + it: Metric, + color: Int + ) { + paint.color = color + + val progress = valueScaler.scaleToNewRange( + it.source.value?.toFloat() ?: it.source.command.pid.min.toFloat(), + it.source.command.pid.min.toFloat(), it.source.command.pid.max.toFloat(), left, left + width - MARGIN_END + ) + + canvas.drawRect( + left - 6, + top + 4, + progress, + top + calculateProgressBarHeight(), + paint + ) + } + + private fun drawValue( + canvas: Canvas, + metric: Metric, + area: Rect, + top: Float, + textSize: Float, + left: Float + ) { + + valuePaint.color = COLOR_WHITE + val x = left + getAreaWidth(area) - 50f + + valuePaint.setShadowLayer(80f, 0f, 0f, Color.WHITE) + valuePaint.textSize = textSize + valuePaint.textAlign = Paint.Align.RIGHT + val text = metric.source.valueToString() + canvas.drawText(text, x, top, valuePaint) + + valuePaint.color = Color.LTGRAY + valuePaint.textAlign = Paint.Align.LEFT + valuePaint.textSize = (textSize * 0.4).toFloat() + canvas.drawText(metric.source.command.pid.units, (x + 2), top, valuePaint) } private fun drawText( @@ -82,6 +211,8 @@ internal class TripDrawer(context: Context, settings: ScreenSettings) : Abstract ) } + private fun calculateProgressBarHeight() = 16 + private inline fun calculateFontSize( area: Rect ): Float = (area.width() / 14f) * valueScaler.scaleToNewRange( @@ -97,8 +228,10 @@ internal class TripDrawer(context: Context, settings: ScreenSettings) : Abstract canvas: Canvas, textSizeBase: Float ) { - drawText(canvas, metrics.valueToIntString(), left, top, textSizeBase, color = Color.WHITE, typeface = - Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)) + drawText( + canvas, metrics.valueToIntString(), left, top, textSizeBase, color = Color.WHITE, typeface = + Typeface.create(Typeface.DEFAULT, Typeface.NORMAL) + ) drawTitle(canvas, metrics, left, top + 24, textSizeBase * 0.35F) } @@ -112,7 +245,7 @@ internal class TripDrawer(context: Context, settings: ScreenSettings) : Abstract var top1 = top titlePaint.textSize = textSize - titlePaint. typeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL) + titlePaint.typeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL) val description = if (metric.source.command.pid.longDescription == null || metric.source.command.pid.longDescription.isEmpty()) { metric.source.command.pid.description diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDetails.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDetails.kt index f4a14af7..651b28e2 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDetails.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDetails.kt @@ -15,4 +15,7 @@ data class TripInfoDetails( var gearboxOilTemp: Metric? = null, var gearboxEngaged: Metric? = null, var oilLevel: Metric? = null, + var intakePressure: Metric? = null, + var torque: Metric? = null, + ) \ No newline at end of file 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 6ae2a1a9..dee61ac9 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 @@ -81,6 +81,8 @@ internal class TripSurfaceRenderer( gearboxOilTemp = metricsCollector.getMetric(namesRegistry.getGearboxOilTempPID()) gearboxEngaged = metricsCollector.getMetric(namesRegistry.getGearboxEngagedPID()) oilLevel = metricsCollector.getMetric(namesRegistry.getOilLevelPID()) + torque = metricsCollector.getMetric(namesRegistry.getTorquePID()) + intakePressure = metricsCollector.getMetric(namesRegistry.getIntakePressurePID()) } ) }