Skip to content

Commit

Permalink
Add trip info screen
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski authored Jul 21, 2024
1 parent 746b363 commit eaae399
Show file tree
Hide file tree
Showing 27 changed files with 745 additions and 58 deletions.
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
<string name="pref.aa.debug_category">Debug</string>
<string name="pref.aa.general_category">General</string>

<string name="pref.aa.trip_info.category">Trip Info</string>

<string name="pref.aa.routines.category">Routines</string>
<string name="pref.aa.routines.enabled">Enable routines screen</string>
<string name="pref.aa.routines.enabled.enabled_summary">It enables routines screen which let you to execute different ECU functions. This feature is very risky, and you use it on your own risk</string>
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,24 @@

</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref.aa.trip_info.category"
app:singleLineTitle="false">

<org.obd.graphs.preferences.aa.AASeekBar
app:showSeekBarValue="true"
app:min="22"
android:max="72"
android:defaultValue="30"
android:dialogTitle="@string/pref.aa.virtual_screens.font_size.category"
android:key="pref.aa.trip_info.font_size"
android:title="@string/pref.aa.virtual_screens.font_size.category"
app:singleLineTitle="false"
app:useSimpleSummaryProvider="true" />

</PreferenceCategory>


<PreferenceCategory
android:title="@string/pref.aa.performance_meter.category"
app:singleLineTitle="false">
Expand Down
7 changes: 7 additions & 0 deletions automotive/src/main/java/org/obd/graphs/aa/CarSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CarSettings(private val carContext: CarContext) : ScreenSettings {
private val dragRacingSettings = DragRacingSettings()
private val colorTheme = ColorTheme()
private val gaugeRendererSettings = GaugeRendererSettings()
private val tripInfoSettings = TripInfoSettings()

override fun getDragRacingSettings(): DragRacingSettings = dragRacingSettings.apply {
vehicleSpeedFrequencyReadEnabled = Prefs.getBoolean("pref.aa.drag_race.debug.display_frequency", true)
Expand All @@ -77,6 +78,12 @@ class CarSettings(private val carContext: CarContext) : ScreenSettings {
fontSize = Prefs.getS("pref.aa.drag_race.font_size", "30").toInt()
}

override fun getTripInfoSettings(): TripInfoSettings = tripInfoSettings.apply {
fontSize = Prefs.getS("pref.aa.trip_info.font_size", "24").toInt()
}



override fun getColorTheme(): ColorTheme = colorTheme.apply {
progressColor = Prefs.getInt(PREF_THEME_PROGRESS_BAR_COLOR, COLOR_DYNAMIC_SELECTOR_SPORT)
dividerColor = Prefs.getInt(PREF_THEME_DIVIDER_COLOR, Color.WHITE)
Expand Down
25 changes: 15 additions & 10 deletions automotive/src/main/java/org/obd/graphs/aa/screen/CarScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import org.obd.graphs.AA_EDIT_PREF_SCREEN
import org.obd.graphs.RenderingThread
import org.obd.graphs.aa.*
import org.obd.graphs.aa.mapColor
import org.obd.graphs.aa.screen.nav.CHANGE_SCREEN_EVENT
import org.obd.graphs.aa.screen.nav.DRAG_RACING_SCREEN_ID
import org.obd.graphs.aa.screen.nav.GIULIA_SCREEN_ID
import org.obd.graphs.aa.screen.nav.ROUTINES_SCREEN_ID
import org.obd.graphs.aa.screen.nav.*
import org.obd.graphs.aa.toast
import org.obd.graphs.bl.collector.MetricsCollector
import org.obd.graphs.bl.datalogger.WorkflowStatus
Expand Down Expand Up @@ -102,13 +99,21 @@ internal abstract class CarScreen(
}
dataLogger.start(query)
}
DRAG_RACING_SCREEN_ID -> {
query.setStrategy(QueryStrategyType.DRAG_RACING_QUERY)
dataLogger.start(query)
}

DRAG_RACING_SCREEN_ID ->
dataLogger.start(query.apply{
setStrategy(QueryStrategyType.DRAG_RACING_QUERY)
})

TRIP_INFO_SCREEN_ID ->
dataLogger.start(query.apply{
setStrategy(QueryStrategyType.TRIP_INFO_QUERY)
})

ROUTINES_SCREEN_ID -> {
query.setStrategy(QueryStrategyType.ROUTINES_QUERY)
dataLogger.start(query)
dataLogger.start(query.apply{
setStrategy(QueryStrategyType.ROUTINES_QUERY)
})
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.obd.graphs.bl.datalogger.*
const val GIULIA_SCREEN_ID = 0
const val DRAG_RACING_SCREEN_ID = 1
const val ROUTINES_SCREEN_ID = 2
const val TRIP_INFO_SCREEN_ID = 3

internal class AvailableFeaturesScreen(
carContext: CarContext,
Expand Down Expand Up @@ -59,6 +60,13 @@ internal class AvailableFeaturesScreen(
val items = ItemList.Builder().apply {


addItem(
row(
TRIP_INFO_SCREEN_ID, R.drawable.action_giulia,
carContext.getString(R.string.available_features_trip_info_screen_title)
)
)

addItem(
row(
DRAG_RACING_SCREEN_ID, R.drawable.action_drag_race_screen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class NavTemplateCarScreen(
Log.d(LOG_KEY, "Selected new screen id=$it")
it?.let {
val newScreen = it.toString().toInt()
if (newScreen == GIULIA_SCREEN_ID || newScreen == DRAG_RACING_SCREEN_ID) {
if (newScreen == GIULIA_SCREEN_ID || newScreen == DRAG_RACING_SCREEN_ID || newScreen == TRIP_INFO_SCREEN_ID) {
surfaceScreen.toggleSurfaceRenderer(newScreen)
invalidate()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,19 @@ class SurfaceController(
}

DRAG_RACING_SCREEN_ID -> {
query.setStrategy(QueryStrategyType.DRAG_RACING_QUERY)
dataLogger.updateQuery(query = query)
dataLogger.updateQuery(query = query.apply {
setStrategy(QueryStrategyType.DRAG_RACING_QUERY)
})

surfaceRenderer = SurfaceRenderer.allocate(carContext, settings, metricsCollector, fps, surfaceRendererType = SurfaceRendererType.DRAG_RACING)
}

TRIP_INFO_SCREEN_ID -> {
dataLogger.updateQuery(query = query.apply {
setStrategy(QueryStrategyType.TRIP_INFO_QUERY)
})
surfaceRenderer = SurfaceRenderer.allocate(carContext, settings, metricsCollector, fps, surfaceRendererType = SurfaceRendererType.TRIP_INFO)
}
}

surfaceRenderer.applyMetricsFilter(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ internal class SurfaceScreen(
}

fun renderFrame() {
if (isAllowedFrameRendering()) {
if (isScreenAllowedForFrameRendering(screenId)) {
surfaceController.renderFrame()
}
}
Expand Down Expand Up @@ -258,6 +258,6 @@ internal class SurfaceScreen(
mapColor(settings.getColorTheme().actionsBtnVirtualScreensColor)
}

private fun isAllowedFrameRendering() = screenId == GIULIA_SCREEN_ID ||
screenId == DRAG_RACING_SCREEN_ID
private fun isScreenAllowedForFrameRendering(screenId: Int) = screenId == GIULIA_SCREEN_ID ||
screenId == DRAG_RACING_SCREEN_ID || screenId == TRIP_INFO_SCREEN_ID
}
2 changes: 2 additions & 0 deletions automotive/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
<string name="available_features.routine_screen.title">Routines</string>
<string name="available_features.drag_race_screen.title">Drag Racing</string>
<string name="available_features.giulia_screen.title">Metrics</string>
<string name="available_features.trip_info_screen.title">Trip Info</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ private const val LOG_KEY = "InMemoryCollector"
internal class InMemoryCarMetricsCollector : MetricsCollector {

private var metrics: SortedMap<Long, Metric> = TreeMap()
private val metricBuilder = MetricsBuilder()

override fun getMetrics(enabled: Boolean): List<Metric> = metrics.values.filter { it.enabled == enabled }

override fun getMetric(id: Long): Metric? = metrics[id]

override fun applyFilter(enabled: Set<Long>, order: Map<Long, Int>?) {
Log.i(LOG_KEY, "Updating visible PIDs=$enabled with order=$order")

Expand All @@ -40,7 +43,7 @@ internal class InMemoryCarMetricsCollector : MetricsCollector {
if (Log.isLoggable(LOG_KEY, Log.DEBUG)) {
Log.d(LOG_KEY, "Rebuilding metrics configuration for: $enabled != ${metrics.keys}")
}
MetricsBuilder().buildFor(enabled).forEach {
metricBuilder.buildFor(enabled).forEach {
val key = it.source.command.pid.id

if (metrics.keys.indexOf(key) ==-1) {
Expand All @@ -67,6 +70,10 @@ internal class InMemoryCarMetricsCollector : MetricsCollector {
override fun append(input: ObdMetric?) {

input?.let { metric ->
if (!metrics.containsKey(metric.command.pid.id)) {
metrics[metric.command.pid.id] = metricBuilder.buildFor(metric)
}

metrics[metric.command.pid.id]?.let {
it.source = metric

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.obd.metrics.api.model.ObdMetric
import org.obd.metrics.pid.PidDefinition
import org.obd.metrics.pid.ValueType

private const val NO_DATA = "----"

data class Metric(
var source: ObdMetric,
var value: Number?,
Expand All @@ -46,7 +48,7 @@ data class Metric(

fun valueToString(): String =
if (source.value == null) {
"----"
NO_DATA
} else {
toNumber(source.valueToDouble())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ import org.obd.metrics.command.obd.ObdCommand
import org.obd.metrics.pid.PidDefinitionRegistry

class MetricsBuilder {

fun buildFor(obdMetric: ObdMetric): Metric {
val histogramSupplier = dataLogger.getDiagnostics().histogram()
val histogram = histogramSupplier.findBy(obdMetric.command.pid)
return Metric
.newInstance(
min = histogram?.min ?: 0.0,
max = histogram?.max ?: 0.0,
mean = histogram?.mean ?: 0.0,
value = histogram?.latestValue ?: 0,
source = obdMetric
)
}

fun buildFor(ids: Set<Long>) = buildFor(ids, emptyMap())

fun buildFor(ids: Set<Long>, sortOrder: Map<Long, Int>?): MutableList<Metric> {
Expand All @@ -46,6 +60,7 @@ class MetricsBuilder {
return metrics
}


private fun buildMetrics(ids: Set<Long>): MutableList<Metric> {
val pidRegistry: PidDefinitionRegistry = dataLogger.getPidDefinitionRegistry()
val histogramSupplier = dataLogger.getDiagnostics().histogram()
Expand All @@ -55,13 +70,14 @@ class MetricsBuilder {
val histogram = histogramSupplier.findBy(pid)
Metric
.newInstance(
min = histogram?.min?:0.0,
max = histogram?.max?:0.0,
mean = histogram?.mean?:0.0,
value = histogram?.latestValue?:0,
source=ObdMetric.builder()
.command(ObdCommand(pid))
.value(histogram?.latestValue).build())
min = histogram?.min ?: 0.0,
max = histogram?.max ?: 0.0,
mean = histogram?.mean ?: 0.0,
value = histogram?.latestValue ?: 0,
source = ObdMetric.builder()
.command(ObdCommand(pid))
.value(histogram?.latestValue).build()
)
}
}.toMutableList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import org.obd.metrics.api.model.ObdMetric

interface MetricsCollector {

fun getMetric(id: Long): Metric?

fun getMetrics(enabled: Boolean = true): List<Metric>

fun applyFilter(enabled: Set<Long>, order: Map<Long, Int>? = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.obd.graphs.bl.generator

import android.os.Handler
import android.os.Looper
import android.util.Log
import org.obd.graphs.bl.datalogger.MetricsProcessor
import org.obd.graphs.bl.datalogger.dataLogger
import org.obd.graphs.bl.query.Query
Expand Down Expand Up @@ -86,19 +87,19 @@ class MetricsGenerator(private val debugBuild: Boolean) : MetricsProcessor {

private fun generateSequenceFor(pid: PidDefinition) =
mutableListOf<Number>().apply {
if (pid.type == ValueType.DOUBLE) {
var step = 1.0
if (pid.type == ValueType.DOUBLE || pid.type == null) {
var step = 1.55

if (pid.max.toInt() < 15) {
step = 0.1
}

if (pid.max.toInt() > 1000) {
step = 5.0
step = 5.22
}

if (pid.max.toInt() > 5000) {
step = 10.0
step = 10.33
}

(pid.min.toDouble()..pid.max.toDouble() step step).forEach {
Expand Down
44 changes: 43 additions & 1 deletion datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,51 @@ private const val VEHICLE_SPEED_PID_ID = 14L
private const val EXT_ENGINE_RPM_PID_ID = 7008L
private const val ENGINE_RPM_PID_ID = 13L

private const val FUEL_CONSUMPTION_PID_ID = 7035L
private const val FUEL_LEVEL_PID_ID = 7037L
private const val GEARBOX_OIL_TEMP_PID_ID = 7025L
private const val GEARBOX_ENGAGED_PID_ID = 7029L
private const val OIL_TEMP_PID_ID = 7003L
private const val COOLANT_TEMP_PID_ID = 7009L
private const val EXHAUST_TEMP_PID_ID = 7016L
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
private const val DISTANCE_PID_ID = 7076L
private const val FUEL_CONSUMED_PID_ID = 7077L



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 getDistancePID(): Long = DISTANCE_PID_ID

fun getFuelConsumedPID(): Long = FUEL_CONSUMED_PID_ID

fun getFuelConsumptionPID(): Long = FUEL_CONSUMPTION_PID_ID
fun getFuelLevelPID(): Long = FUEL_LEVEL_PID_ID
fun getGearboxOilTempPID(): Long = GEARBOX_OIL_TEMP_PID_ID

fun getGearboxEngagedPID(): Long = GEARBOX_ENGAGED_PID_ID

fun getOilTempPID(): Long = OIL_TEMP_PID_ID

fun getCoolantTempPID(): Long = COOLANT_TEMP_PID_ID

fun getExhaustTempPID(): Long = EXHAUST_TEMP_PID_ID

fun getAirTempPID(): Long = AIR_TEMP_PID_ID

fun getAtmPressurePID(): Long = EXT_ATM_PRESSURE_PID_ID
fun getAmbientTempPID(): Long = EXT_AMBIENT_TEMP_PID_ID
fun getMeasuredIntakePressurePID (): Long = EXT_MEASURED_INTAKE_PRESSURE_PID_ID
Expand All @@ -38,5 +81,4 @@ class PIDsNamesRegistry {
fun getDynamicSelectorPID(): Long = EXT_DYNAMIC_SELECTOR_PID_ID

private fun isProfileExtensionsEnabled() = Prefs.getBoolean(PREF_PROFILE_2_0_GME_EXTENSION_ENABLED, false)

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class QueryStrategyOrchestrator : java.io.Serializable, Query {
this[QueryStrategyType.DRAG_RACING_QUERY] = DragRacingQueryStrategy()
this[QueryStrategyType.INDIVIDUAL_QUERY_FOR_EACH_VIEW] = IndividualQueryStrategy()
this[QueryStrategyType.ROUTINES_QUERY] = RoutinesQueryStrategy()
this[QueryStrategyType.TRIP_INFO_QUERY] = TripInfoQueryStrategy()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.obd.graphs.bl.query
enum class QueryStrategyType {
ROUTINES_QUERY,
DRAG_RACING_QUERY,
TRIP_INFO_QUERY,
SHARED_QUERY,
INDIVIDUAL_QUERY_FOR_EACH_VIEW
}
Loading

0 comments on commit eaae399

Please sign in to comment.