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.util.Log
|
||||
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.GarminMapper
|
||||
import eu.ztsh.garmin.data.Lanes
|
||||
import eu.ztsh.garmin.data.MapboxMapper
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
@ -54,6 +56,14 @@ class Garmin(
|
|||
if (maybeItem != null) {
|
||||
Log.d(TAG, "mapAndSend (${currentThread().name}): got new")
|
||||
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)) {
|
||||
changed = true
|
||||
Log.d(TAG, "mapAndSend: lanes")
|
||||
|
@ -64,11 +74,6 @@ class Garmin(
|
|||
Log.d(TAG, "mapAndSend: stepDistance")
|
||||
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) {
|
||||
return maybeItem
|
||||
}
|
||||
|
|
|
@ -71,13 +71,25 @@ class MapboxMapper {
|
|||
}
|
||||
|
||||
fun asLanes(maneuver: Maneuver): Lanes {
|
||||
// TODO: implement
|
||||
val laneIterator = Lane.iterator()
|
||||
val outlines = mutableSetOf<Lane>()
|
||||
val lanes = mutableSetOf<Lane>()
|
||||
maneuver.laneGuidance?.apply {
|
||||
this.allLanes.apply {
|
||||
println()
|
||||
this.allLanes.reversed().let {
|
||||
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 {
|
||||
|
|
|
@ -47,11 +47,15 @@ enum class Lane(val value: Int) {
|
|||
InnerLeft(0x10),
|
||||
MiddleLeft(0x20),
|
||||
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 {
|
||||
if (this === other) return true
|
||||
|
@ -151,7 +155,7 @@ class GarminManeuver : GarminModelItem {
|
|||
|
||||
val empty: () -> 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.distance = Distance(0.0, Unit.Any)
|
||||
manouver
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue