Skip to content

Commit

Permalink
refactor: Cleanup dynamic selector
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Jan 23, 2025
1 parent 2c621d0 commit a91852d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package org.obd.graphs.aa.screen
import android.util.Log
import org.obd.graphs.bl.datalogger.MetricsProcessor
import org.obd.graphs.bl.query.isDynamicSelector
import org.obd.graphs.valueToNumber
import org.obd.graphs.sendBroadcastEvent
import org.obd.graphs.valueToNumber
import org.obd.metrics.api.model.ObdMetric


Expand All @@ -13,32 +13,34 @@ const val EVENT_DYNAMIC_SELECTOR_MODE_ECO = "event.dynamic.selector.mode.eco"
const val EVENT_DYNAMIC_SELECTOR_MODE_SPORT = "event.dynamic.selector.mode.sport"
const val EVENT_DYNAMIC_SELECTOR_MODE_RACE = "event.dynamic.selector.mode.race"

internal val dynamicSelectorModeEventBroadcaster:MetricsProcessor = DynamicSelectorModeEventBroadcaster()
internal val dynamicSelectorModeEventBroadcaster: MetricsProcessor = DynamicSelectorModeEventBroadcaster()

private const val LOG_TAG = "DynSelectorBroadcast"

internal class DynamicSelectorModeEventBroadcaster: MetricsProcessor {
internal class DynamicSelectorModeEventBroadcaster : MetricsProcessor {
private var currentMode = -1

override fun postValue(obdMetric: ObdMetric) {
if (obdMetric.isDynamicSelector()) {

if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
Log.v(LOG_TAG, "Received=${obdMetric.valueToNumber()}, current=${currentMode} ")
}

if (currentMode != obdMetric.valueToNumber()!!) {

obdMetric.valueToNumber()?.let {
if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
Log.v(LOG_TAG, "Broadcasting Dynamic Selector Mode Change, new=${obdMetric.valueToNumber()}")
Log.v(LOG_TAG, "Received=${it}, current=${currentMode} ")
}

currentMode = obdMetric.valueToNumber()!!.toInt()
when (obdMetric.valueToNumber()!!.toInt()) {
0 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_NORMAL)
2 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_SPORT)
4 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_ECO)
else -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_RACE)
if (currentMode != it) {

if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
Log.v(LOG_TAG, "Broadcasting Dynamic Selector Mode Change, new=${it}")
}

currentMode = it.toInt()
when (it.toInt()) {
0 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_NORMAL)
2 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_SPORT)
4 -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_ECO)
else -> sendBroadcastEvent(EVENT_DYNAMIC_SELECTOR_MODE_RACE)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import org.obd.metrics.pid.PidDefinition
private const val VEHICLE_RUNNING_KEY = "vehicle.running"
private const val KEY_STATUS_KEY = "key.status"
private const val ENGINE_RUNNING_KEY = "engine.running"
class ToStringHashMap<T, V>(private val converter: ToStringConverter<T, V>) : HashMap<T, V>() {

private class ToStringHashMap<T, V>(private val converter: ToStringConverter<T, V>) : HashMap<T, V>() {
fun interface ToStringConverter<TT, VV> {
fun convert(items: Map<TT, VV>): String
}
Expand Down Expand Up @@ -92,9 +93,6 @@ internal val baseMetrics = mutableMapOf(

}),




namesRegistry.getVehicleStatusPID() to MetricGeneratorDefinition(
pid = dataLogger.getPidDefinitionRegistry().findBy(namesRegistry.getVehicleStatusPID()),
data = mutableListOf<Map<String,Boolean>>().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ internal class GaugeDrawer(
}
}
paint.shader = null
}
}
}


Expand Down Expand Up @@ -416,8 +416,8 @@ internal class GaugeDrawer(
area: RectF,
) {
if (metric.source.isNumber()) {
val pid = metric
.pid()

val pid = metric.pid()
val startValue = pid.min.toDouble()
val endValue = pid.max.toDouble()

Expand Down

0 comments on commit a91852d

Please sign in to comment.