feat: Lane assist
This commit is contained in:
parent
f5ec500343
commit
386bb50621
3 changed files with 33 additions and 12 deletions
|
@ -6,8 +6,10 @@ import android.bluetooth.BluetoothDevice
|
||||||
import android.bluetooth.BluetoothSocket
|
import android.bluetooth.BluetoothSocket
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
||||||
|
import eu.ztsh.garmin.data.Arrows
|
||||||
import eu.ztsh.garmin.data.DataCache
|
import eu.ztsh.garmin.data.DataCache
|
||||||
import eu.ztsh.garmin.data.GarminMapper
|
import eu.ztsh.garmin.data.GarminMapper
|
||||||
|
import eu.ztsh.garmin.data.Lanes
|
||||||
import eu.ztsh.garmin.data.MapboxMapper
|
import eu.ztsh.garmin.data.MapboxMapper
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -54,6 +56,14 @@ class Garmin(
|
||||||
if (maybeItem != null) {
|
if (maybeItem != null) {
|
||||||
Log.d(TAG, "mapAndSend (${currentThread().name}): got new")
|
Log.d(TAG, "mapAndSend (${currentThread().name}): got new")
|
||||||
var changed = false
|
var changed = false
|
||||||
|
if (cache.hasChanged(maybeItem.primary)) {
|
||||||
|
changed = true
|
||||||
|
Log.d(TAG, "mapAndSend: primary")
|
||||||
|
send(GarminMapper.map(MapboxMapper.asDirection(maybeItem)))
|
||||||
|
if (maybeItem.laneGuidance == null) {
|
||||||
|
send(GarminMapper.map(Lanes(Arrows(setOf()), Arrows(setOf()))))
|
||||||
|
}
|
||||||
|
}
|
||||||
if (cache.hasChanged(maybeItem.laneGuidance)) {
|
if (cache.hasChanged(maybeItem.laneGuidance)) {
|
||||||
changed = true
|
changed = true
|
||||||
Log.d(TAG, "mapAndSend: lanes")
|
Log.d(TAG, "mapAndSend: lanes")
|
||||||
|
@ -64,11 +74,6 @@ class Garmin(
|
||||||
Log.d(TAG, "mapAndSend: stepDistance")
|
Log.d(TAG, "mapAndSend: stepDistance")
|
||||||
send(GarminMapper.map(MapboxMapper.asDistance(maybeItem)))
|
send(GarminMapper.map(MapboxMapper.asDistance(maybeItem)))
|
||||||
}
|
}
|
||||||
if (cache.hasChanged(maybeItem.primary)) {
|
|
||||||
changed = true
|
|
||||||
Log.d(TAG, "mapAndSend: primary")
|
|
||||||
send(GarminMapper.map(MapboxMapper.asDirection(maybeItem)))
|
|
||||||
}
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
return maybeItem
|
return maybeItem
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,13 +71,25 @@ class MapboxMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun asLanes(maneuver: Maneuver): Lanes {
|
fun asLanes(maneuver: Maneuver): Lanes {
|
||||||
// TODO: implement
|
val laneIterator = Lane.iterator()
|
||||||
|
val outlines = mutableSetOf<Lane>()
|
||||||
|
val lanes = mutableSetOf<Lane>()
|
||||||
maneuver.laneGuidance?.apply {
|
maneuver.laneGuidance?.apply {
|
||||||
this.allLanes.apply {
|
this.allLanes.reversed().let {
|
||||||
println()
|
it.forEach{ indicator ->
|
||||||
|
val lane = if (laneIterator.hasNext()) laneIterator.next() else Lane.DotsLeft
|
||||||
|
if (lane == Lane.DotsLeft) {
|
||||||
|
outlines.add(Lane.DotsLeft)
|
||||||
|
} else {
|
||||||
|
outlines.add(lane)
|
||||||
|
if (indicator.isActive) {
|
||||||
|
lanes.add(lane)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Lanes(Arrows(listOf()), Arrows(listOf()))
|
return Lanes(Arrows(lanes), Arrows(outlines))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun map(locationMatcherResult: LocationMatcherResult): GarminLocation {
|
fun map(locationMatcherResult: LocationMatcherResult): GarminLocation {
|
||||||
|
|
|
@ -47,11 +47,15 @@ enum class Lane(val value: Int) {
|
||||||
InnerLeft(0x10),
|
InnerLeft(0x10),
|
||||||
MiddleLeft(0x20),
|
MiddleLeft(0x20),
|
||||||
OuterLeft(0x40),
|
OuterLeft(0x40),
|
||||||
DotsLeft(0x80)
|
DotsLeft(0x80);
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val iterator = {sortedSetOf(OuterRight, MiddleRight, InnerRight, InnerLeft, MiddleLeft, OuterLeft).iterator()}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Arrows(val lanes: List<Lane>) {
|
class Arrows(val lanes: Set<Lane>) {
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
|
@ -151,7 +155,7 @@ class GarminManeuver : GarminModelItem {
|
||||||
|
|
||||||
val empty: () -> GarminManeuver = {
|
val empty: () -> GarminManeuver = {
|
||||||
val manouver = GarminManeuver()
|
val manouver = GarminManeuver()
|
||||||
manouver.lanes = Lanes(Arrows(listOf()), Arrows(listOf()))
|
manouver.lanes = Lanes(Arrows(setOf()), Arrows(setOf()))
|
||||||
manouver.direction = Direction(out = OutType.Off)
|
manouver.direction = Direction(out = OutType.Off)
|
||||||
manouver.distance = Distance(0.0, Unit.Any)
|
manouver.distance = Distance(0.0, Unit.Any)
|
||||||
manouver
|
manouver
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue