feat: ETA
This commit is contained in:
parent
028f1b6082
commit
c329cffeb7
5 changed files with 77 additions and 6 deletions
|
@ -6,6 +6,7 @@ import android.bluetooth.BluetoothDevice
|
|||
import android.bluetooth.BluetoothSocket
|
||||
import android.util.Log
|
||||
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
||||
import com.mapbox.navigation.tripdata.progress.model.TripProgressUpdateValue
|
||||
import eu.ztsh.garmin.data.Arrows
|
||||
import eu.ztsh.garmin.data.DataCache
|
||||
import eu.ztsh.garmin.data.GarminMapper
|
||||
|
@ -25,9 +26,11 @@ class Garmin(
|
|||
|
||||
private lateinit var connection: ConnectThread
|
||||
private lateinit var maneuvers: ManeuverProcessingThread
|
||||
private lateinit var trips: TripProgressProcessingThread
|
||||
private val cache = DataCache()
|
||||
|
||||
private val maneuversPool = Executors.newFixedThreadPool(4)
|
||||
private val tripPool = Executors.newFixedThreadPool(4)
|
||||
|
||||
fun start() {
|
||||
connection = ConnectThread()
|
||||
|
@ -35,6 +38,9 @@ class Garmin(
|
|||
|
||||
maneuvers = ManeuverProcessingThread()
|
||||
maneuvers.start()
|
||||
|
||||
trips = TripProgressProcessingThread()
|
||||
trips.start()
|
||||
}
|
||||
|
||||
fun close() {
|
||||
|
@ -43,13 +49,42 @@ class Garmin(
|
|||
maneuvers.interrupt()
|
||||
maneuvers.join(0)
|
||||
|
||||
trips.interrupt()
|
||||
trips.join(0)
|
||||
|
||||
maneuversPool.shutdown()
|
||||
tripPool.shutdown()
|
||||
}
|
||||
|
||||
fun process(maneuver: Maneuver) {
|
||||
maneuversPool.submit{maneuvers.enqueue(maneuver)}
|
||||
}
|
||||
|
||||
fun process(tripProgressUpdateValue: TripProgressUpdateValue) {
|
||||
maneuversPool.submit{trips.enqueue(tripProgressUpdateValue)}
|
||||
}
|
||||
|
||||
private inner class TripProgressProcessingThread : ProcessingThread<TripProgressUpdateValue>() {
|
||||
|
||||
override fun mapAndSend(maybeItem: TripProgressUpdateValue?): TripProgressUpdateValue? {
|
||||
if (maybeItem != null) {
|
||||
// it is much simplier to parse and compare model object
|
||||
val value = MapboxMapper.asEta(maybeItem)
|
||||
if (cache.hasChanged(value)) {
|
||||
// TODO: traffic
|
||||
send(GarminMapper.setTime(value.hours, value.minutes))
|
||||
cache.update(value)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun updateCache(item: TripProgressUpdateValue) {
|
||||
// won't be used
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private inner class ManeuverProcessingThread : ProcessingThread<Maneuver>() {
|
||||
|
||||
override fun mapAndSend(maybeItem: Maneuver?): Maneuver? {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue