feat: speed
This commit is contained in:
parent
c329cffeb7
commit
a015ab2c5f
3 changed files with 38 additions and 7 deletions
|
@ -5,6 +5,7 @@ import android.bluetooth.BluetoothAdapter
|
||||||
import android.bluetooth.BluetoothDevice
|
import android.bluetooth.BluetoothDevice
|
||||||
import android.bluetooth.BluetoothSocket
|
import android.bluetooth.BluetoothSocket
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
|
||||||
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
||||||
import com.mapbox.navigation.tripdata.progress.model.TripProgressUpdateValue
|
import com.mapbox.navigation.tripdata.progress.model.TripProgressUpdateValue
|
||||||
import eu.ztsh.garmin.data.Arrows
|
import eu.ztsh.garmin.data.Arrows
|
||||||
|
@ -27,10 +28,10 @@ class Garmin(
|
||||||
private lateinit var connection: ConnectThread
|
private lateinit var connection: ConnectThread
|
||||||
private lateinit var maneuvers: ManeuverProcessingThread
|
private lateinit var maneuvers: ManeuverProcessingThread
|
||||||
private lateinit var trips: TripProgressProcessingThread
|
private lateinit var trips: TripProgressProcessingThread
|
||||||
|
private lateinit var locations: LocationMatcherProcessingThread
|
||||||
private val cache = DataCache()
|
private val cache = DataCache()
|
||||||
|
|
||||||
private val maneuversPool = Executors.newFixedThreadPool(4)
|
private val processingPool = Executors.newFixedThreadPool(8)
|
||||||
private val tripPool = Executors.newFixedThreadPool(4)
|
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
connection = ConnectThread()
|
connection = ConnectThread()
|
||||||
|
@ -41,6 +42,9 @@ class Garmin(
|
||||||
|
|
||||||
trips = TripProgressProcessingThread()
|
trips = TripProgressProcessingThread()
|
||||||
trips.start()
|
trips.start()
|
||||||
|
|
||||||
|
locations = LocationMatcherProcessingThread()
|
||||||
|
locations.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun close() {
|
fun close() {
|
||||||
|
@ -52,16 +56,38 @@ class Garmin(
|
||||||
trips.interrupt()
|
trips.interrupt()
|
||||||
trips.join(0)
|
trips.join(0)
|
||||||
|
|
||||||
maneuversPool.shutdown()
|
locations.interrupt()
|
||||||
tripPool.shutdown()
|
locations.join(0)
|
||||||
|
|
||||||
|
processingPool.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun process(maneuver: Maneuver) {
|
fun process(maneuver: Maneuver) {
|
||||||
maneuversPool.submit{maneuvers.enqueue(maneuver)}
|
processingPool.submit{maneuvers.enqueue(maneuver)}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun process(tripProgressUpdateValue: TripProgressUpdateValue) {
|
fun process(tripProgressUpdateValue: TripProgressUpdateValue) {
|
||||||
maneuversPool.submit{trips.enqueue(tripProgressUpdateValue)}
|
processingPool.submit{trips.enqueue(tripProgressUpdateValue)}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun process(locationMatcherResult: LocationMatcherResult) {
|
||||||
|
processingPool.submit{locations.enqueue(locationMatcherResult)}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class LocationMatcherProcessingThread: ProcessingThread<LocationMatcherResult>() {
|
||||||
|
|
||||||
|
override fun mapAndSend(maybeItem: LocationMatcherResult?): LocationMatcherResult? {
|
||||||
|
if (maybeItem != null && cache.hasChanged(maybeItem)) {
|
||||||
|
send(GarminMapper.map(MapboxMapper.asSpeed(maybeItem)))
|
||||||
|
return maybeItem
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateCache(item: LocationMatcherResult) {
|
||||||
|
cache.update(item)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class TripProgressProcessingThread : ProcessingThread<TripProgressUpdateValue>() {
|
private inner class TripProgressProcessingThread : ProcessingThread<TripProgressUpdateValue>() {
|
||||||
|
|
|
@ -42,7 +42,9 @@ class DataCache {
|
||||||
|
|
||||||
// location
|
// location
|
||||||
fun hasChanged(locationMatcherResult: LocationMatcherResult): Boolean {
|
fun hasChanged(locationMatcherResult: LocationMatcherResult): Boolean {
|
||||||
return locationCache == null || locationCache!! != locationMatcherResult
|
return locationCache.let { it == null
|
||||||
|
|| it.enhancedLocation.speed != locationMatcherResult.enhancedLocation.speed
|
||||||
|
|| it.speedLimitInfo.speed != locationMatcherResult.speedLimitInfo.speed }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update(locationMatcherResult: LocationMatcherResult) {
|
fun update(locationMatcherResult: LocationMatcherResult) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.mapbox.common.location.Location
|
||||||
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
|
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
|
||||||
import com.mapbox.navigation.core.trip.session.LocationObserver
|
import com.mapbox.navigation.core.trip.session.LocationObserver
|
||||||
import com.mapbox.navigation.ui.maps.camera.transition.NavigationCameraTransitionOptions
|
import com.mapbox.navigation.ui.maps.camera.transition.NavigationCameraTransitionOptions
|
||||||
|
import eu.ztsh.garmin.Garmin
|
||||||
|
|
||||||
class LocationObserver(private val mapControl: MapControl) : LocationObserver {
|
class LocationObserver(private val mapControl: MapControl) : LocationObserver {
|
||||||
|
|
||||||
|
@ -31,6 +32,8 @@ class LocationObserver(private val mapControl: MapControl) : LocationObserver {
|
||||||
mapControl.viewportDataSource.onLocationChanged(enhancedLocation)
|
mapControl.viewportDataSource.onLocationChanged(enhancedLocation)
|
||||||
mapControl.viewportDataSource.evaluate()
|
mapControl.viewportDataSource.evaluate()
|
||||||
|
|
||||||
|
Garmin.instance.process(locationMatcherResult)
|
||||||
|
|
||||||
// if this is the first location update the activity has received,
|
// if this is the first location update the activity has received,
|
||||||
// it's best to immediately move the camera to the current user location
|
// it's best to immediately move the camera to the current user location
|
||||||
if (!firstLocationUpdateReceived) {
|
if (!firstLocationUpdateReceived) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue