Skip to content

Commit

Permalink
feat: Change interface of TripInfoDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Jul 16, 2024
1 parent 9256b3c commit 4d94d75
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.obd.graphs.renderer.trip

import android.content.Context
import android.graphics.*
import org.obd.graphs.bl.collector.Metric
import org.obd.graphs.renderer.AbstractDrawer
import org.obd.graphs.renderer.ScreenSettings

Expand All @@ -42,22 +43,20 @@ internal class TripDrawer(context: Context, settings: ScreenSettings) : Abstract
val textSizeBase = calculateFontSize(area)

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)


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)

var rowTop = top + 12f
drawMetric(tripInfo.airTemp!!, rowTop, left, canvas, textSizeBase)
drawMetric(tripInfo.ambientTemp!!, rowTop, left + x, canvas, textSizeBase)
drawMetric(tripInfo.coolantTemp!!, rowTop, left + 2 * x, canvas, textSizeBase)
drawMetric(tripInfo.oilTemp!!, rowTop, left + 3 * x, canvas, textSizeBase)
drawMetric(tripInfo.exhaustTemp!!, rowTop, left + 4 * x, canvas, textSizeBase)
drawMetric(tripInfo.gearboxOilTemp!!, rowTop, left + 5 * x, canvas, textSizeBase)
//second row
rowTop = top + (textSizeBase) + 46f
drawMetric(tripInfo.fuellevel!!, rowTop, left, canvas, textSizeBase)
drawMetric(tripInfo.gearboxEngaged!!, rowTop, left + x, canvas, textSizeBase)
drawMetric(tripInfo.atmPressure!!, rowTop, left + 2 * x, canvas, textSizeBase)
drawMetric(tripInfo.vehicleSpeed!!, rowTop, left + 3 * x, canvas, textSizeBase)
drawMetric(tripInfo.fuelConsumption!!, rowTop, left + 4 * x, canvas, textSizeBase)
}


Expand All @@ -83,23 +82,78 @@ internal class TripDrawer(context: Context, settings: ScreenSettings) : Abstract

private inline fun calculateFontSize(
area: Rect
): Float = (area.width() / 12f) * valueScaler.scaleToNewRange(
): Float = (area.width() / 11f) * valueScaler.scaleToNewRange(
settings.getDragRacingSettings().fontSize.toFloat(),
CURRENT_MIN, CURRENT_MAX, NEW_MIN, NEW_MAX
)


private inline fun drawMetric(
value: Number?,
label: String,
metrics: Metric,
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)
drawText(canvas, metrics.valueToString(), left, top, textSizeBase, color = Color.WHITE, typeface =
Typeface.create(Typeface.DEFAULT, Typeface.BOLD))
drawTitle(canvas, metrics, left, top + 24, textSizeBase * 0.30F)
}

private inline fun timeToString(value: Number?): String = value?.toString() ?: "---"
private fun drawTitle(
canvas: Canvas,
metric: Metric,
left: Float,
top: Float,
textSize: Float
) {

var top1 = top
titlePaint.textSize = textSize
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
} else {
metric.source.command.pid.longDescription
}

if (settings.isBreakLabelTextEnabled()) {

val text = description.split("\n")
if (text.size == 1) {
canvas.drawText(
text[0],
left,
top,
titlePaint
)

} else {
titlePaint.textSize = textSize
var vPos = top
text.forEach {
canvas.drawText(
it,
left,
vPos,
titlePaint
)
vPos += titlePaint.textSize

}
top1 += titlePaint.textSize

}

} else {
val text = description.replace("\n", " ")
canvas.drawText(
text,
left,
top,
titlePaint
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@ import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Rect
import org.obd.graphs.bl.collector.Metric
import org.obd.graphs.bl.collector.MetricsCollector
import org.obd.graphs.bl.query.*
import org.obd.graphs.renderer.*


data class TripInfoDetails(
var ambientTemp: Number? = null,
var atmPressure: Number? = null,
var vehicleSpeed: Number? = null,
var fuellevel: Number? = null,
var fuelConsumption: Number? = null,
var oilTemp: Number? = null,
var coolantTemp: Number? = null,
var airTemp: Number? = null,
var exhaustTemp: Number? = null,
var gearboxOilTemp: Number? = null,
var gearboxEngaged: Number? = null,
var ambientTemp: Metric? = null,
var atmPressure: Metric? = null,
var vehicleSpeed: Metric? = null,
var fuellevel: Metric? = null,
var fuelConsumption: Metric? = null,
var oilTemp: Metric? = null,
var coolantTemp: Metric? = null,
var airTemp: Metric? = null,
var exhaustTemp: Metric? = null,
var gearboxOilTemp: Metric? = null,
var gearboxEngaged: Metric? = null,
)


Expand Down Expand Up @@ -83,57 +84,24 @@ internal class TripSurfaceRenderer(
area = area,
left = left,
top = top,
tripInfo = getTripInfo()
tripInfo = tripInfo.apply {
airTemp = metricsCollector.getMetric(namesRegistry.getAirTempPID())
vehicleSpeed = metricsCollector.getMetric(namesRegistry.getVehicleSpeedPID())
ambientTemp = metricsCollector.getMetric(namesRegistry.getAmbientTempPID())
atmPressure = metricsCollector.getMetric(namesRegistry.getAtmPressurePID())
fuellevel = metricsCollector.getMetric(namesRegistry.getFuelLevelPID())
fuelConsumption = metricsCollector.getMetric(namesRegistry.getFuelConsumptionPID())
coolantTemp = metricsCollector.getMetric(namesRegistry.getCoolantTempPID())
exhaustTemp = metricsCollector.getMetric(namesRegistry.getExhaustTempPID())
oilTemp = metricsCollector.getMetric(namesRegistry.getOilTempPID())
gearboxOilTemp = metricsCollector.getMetric(namesRegistry.getGearboxOilTempPID())
gearboxEngaged = metricsCollector.getMetric(namesRegistry.getGearboxEngagedPID())

}
)
}
}

private fun getTripInfo(): TripInfoDetails {
metricsCollector.getMetric(namesRegistry.getVehicleSpeedPID())?.let {
tripInfo.apply { vehicleSpeed = it.value }
}

metricsCollector.getMetric(namesRegistry.getAmbientTempPID())?.let {
tripInfo.apply { ambientTemp = it.value }
}

metricsCollector.getMetric(namesRegistry.getAtmPressurePID())?.let {
tripInfo.apply { atmPressure = it.value }
}

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 }
}

metricsCollector.getMetric(namesRegistry.getExhaustTempPID())?.let {
tripInfo.apply { exhaustTemp = it.value }
}

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

0 comments on commit 4d94d75

Please sign in to comment.