Skip to content

Commit

Permalink
feat:TripInfo Apply single precision value to fuel level
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Jul 26, 2024
1 parent afc39c4 commit d79fb9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package org.obd.graphs.bl.query

import org.obd.graphs.preferences.Prefs
import org.obd.graphs.round
import org.obd.metrics.api.model.ObdMetric


fun ObdMetric.valueToString(precision: Int = 2): String =
if (this.value == null) {
"No data"
} else {
if (this.value is Double) this.valueToDouble(precision).toString() else this.value.toString()
}

fun ObdMetric.valueToDouble(precision: Int = 2): Double =
if (this.value == null) Double.NaN else value.toDouble().round(precision)

fun ObdMetric.isAtmPressure(): Boolean = command.pid.id == namesRegistry.getAtmPressurePID()
fun ObdMetric.isAmbientTemp(): Boolean = command.pid.id == namesRegistry.getAmbientTempPID()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.valueToString
import org.obd.graphs.renderer.AbstractDrawer
import org.obd.graphs.renderer.ScreenSettings
import org.obd.graphs.renderer.drag.MARGIN_END
Expand Down Expand Up @@ -58,7 +59,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst

//second row
rowTop = top + (textSizeBase) + 52f
drawMetric(tripInfo.fuellevel!!, rowTop, left, canvas, textSizeBase, statsEnabled = true, area=area, statsDoublePrecision = 1)
drawMetric(tripInfo.fuellevel!!, rowTop, left, canvas, textSizeBase, statsEnabled = true, area=area, statsDoublePrecision = 1, valueDoublePrecision = 1)
drawMetric(tripInfo.fuelConsumption!!, rowTop, left + 1 * x, canvas, textSizeBase, statsEnabled = true, unitEnabled = false, area=area, statsDoublePrecision = 1)
drawMetric(tripInfo.batteryVoltage!!, rowTop, left + 2 * x, canvas, textSizeBase, statsEnabled = true, area=area)
drawMetric(tripInfo.ibs!!, rowTop, left + 3 * x, canvas, textSizeBase, area=area)
Expand Down Expand Up @@ -267,6 +268,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst
statsEnabled: Boolean,
unitEnabled: Boolean,
area: Rect,
valueDoublePrecision: Int = 2,
statsDoublePrecision: Int = 2
) {

Expand All @@ -275,7 +277,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst

valuePaint.setShadowLayer(80f, 0f, 0f, Color.WHITE)
valuePaint.textSize = textSize
val text = metric.source.valueToString()
val text = metric.source.valueToString(valueDoublePrecision)
canvas.drawText(text, left, top, valuePaint)
var textWidth = getTextWidth(text, valuePaint) + 2

Expand Down Expand Up @@ -312,6 +314,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst
statsEnabled: Boolean = false,
unitEnabled: Boolean = true,
area: Rect,
valueDoublePrecision: Int = 2,
statsDoublePrecision: Int = 2
) {

Expand All @@ -326,6 +329,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst
statsEnabled = statsEnabled,
unitEnabled = unitEnabled,
area = area,
valueDoublePrecision = valueDoublePrecision,
statsDoublePrecision = statsDoublePrecision
)

Expand Down

0 comments on commit d79fb9a

Please sign in to comment.