State to IntArray mapper
This commit is contained in:
parent
2b0746f6c4
commit
ff2e163983
4 changed files with 173 additions and 32 deletions
|
@ -6,6 +6,12 @@ import android.bluetooth.BluetoothDevice
|
|||
import android.bluetooth.BluetoothSocket
|
||||
import android.util.Log
|
||||
import com.mapbox.navigation.ui.maneuver.model.Maneuver
|
||||
import eu.ztsh.garmin.data.Direction
|
||||
import eu.ztsh.garmin.data.GarminMapper
|
||||
import eu.ztsh.garmin.data.ManeuverMapper
|
||||
import eu.ztsh.garmin.data.OutAngle
|
||||
import eu.ztsh.garmin.data.OutType
|
||||
import eu.ztsh.garmin.data.State
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.concurrent.SynchronousQueue
|
||||
|
@ -45,46 +51,29 @@ class Garmin(
|
|||
send(ManeuverMapper.apply(maneuver))
|
||||
}
|
||||
|
||||
fun send(incoming: eu.ztsh.garmin.State) {
|
||||
fun send(incoming: eu.ztsh.garmin.data.State) {
|
||||
if (stateCache.distance != incoming.distance) {
|
||||
setDistance(incoming)
|
||||
}
|
||||
if (stateCache.direction != incoming.direction) {
|
||||
setDirection(stateCache.direction)
|
||||
setDirection(stateCache)
|
||||
}
|
||||
stateCache = incoming
|
||||
}
|
||||
|
||||
private fun setDistance(state: eu.ztsh.garmin.State) {
|
||||
connection.enqueue(intArrayOf(
|
||||
0x03, asDigit(state.distance / 1000), asDigit(state.distance / 100), asDigit(state.distance / 10),
|
||||
0x00, asDigit(state.distance), state.unit.value
|
||||
))
|
||||
|
||||
private fun setLines(state: eu.ztsh.garmin.data.State) {
|
||||
|
||||
}
|
||||
|
||||
private fun setDirection(direction: Direction) {
|
||||
val param1: Int = when (direction.angle) {
|
||||
OutAngle.LeftDown -> 0x10
|
||||
OutAngle.RightDown -> 0x20
|
||||
else -> direction.out.value
|
||||
}
|
||||
val param2: Int = if (direction.out == OutType.RightRoundabout
|
||||
|| direction.out == OutType.LeftRoundabout) {
|
||||
if (direction.roundabout == OutAngle.AsDirection) direction.angle.value else direction.roundabout.value
|
||||
} else {
|
||||
0x00
|
||||
}
|
||||
val param3: Int = if (direction.angle == OutAngle.LeftDown || direction.angle == OutAngle.RightDown) 0x00 else direction.angle.value
|
||||
connection.enqueue(intArrayOf(0x01, param1, param2, param3))
|
||||
private fun setDistance(state: eu.ztsh.garmin.data.State) {
|
||||
connection.enqueue(GarminMapper.setDistance(state))
|
||||
}
|
||||
|
||||
private fun asDigit(n: Int): Int {
|
||||
if (n == 0) {
|
||||
return 0
|
||||
}
|
||||
val m = n % 10
|
||||
return if (m == 0) 10 else m
|
||||
private fun setDirection(direction: eu.ztsh.garmin.data.State) {
|
||||
connection.enqueue(GarminMapper.setDirection(direction))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private inner class ConnectThread : Thread() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue