Skip to content

Commit

Permalink
feat: Display torque and intake pressure
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Jul 17, 2024
1 parent ff213db commit d0d4b50
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 4 deletions.
10 changes: 10 additions & 0 deletions datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ internal class TripInfoQueryStrategy : QueryStrategy() {
namesRegistry.getAirTempPID(),
namesRegistry.getTotalMisfiresPID(),
namesRegistry.getOilLevelPID(),
)
namesRegistry.getTorquePID(),
namesRegistry.getIntakePressurePID(),
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Float, Float> {

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(
Expand All @@ -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(
Expand All @@ -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)
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,

)
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
)
}
Expand Down

0 comments on commit d0d4b50

Please sign in to comment.