fix: isDigit & setDistance
This commit is contained in:
parent
6f3643a2b4
commit
35e24dcc8e
2 changed files with 16 additions and 23 deletions
|
@ -5,9 +5,9 @@ import android.bluetooth.BluetoothAdapter
|
|||
import android.bluetooth.BluetoothDevice
|
||||
import android.bluetooth.BluetoothSocket
|
||||
import android.util.Log
|
||||
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
||||
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
|
||||
import com.mapbox.navigation.core.trip.session.NavigationSessionState
|
||||
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
||||
import eu.ztsh.garmin.data.DataCache
|
||||
import eu.ztsh.garmin.data.GarminMapper
|
||||
import eu.ztsh.garmin.data.MapboxMapper
|
||||
|
@ -72,17 +72,6 @@ class Garmin(
|
|||
}
|
||||
|
||||
}
|
||||
private fun setDistance(state: eu.ztsh.garmin.State) {
|
||||
connection.enqueue(intArrayOf(
|
||||
0x03,
|
||||
asDigit(state.distance / 1000), // position 1
|
||||
asDigit(state.distance / 100), // position 2
|
||||
asDigit(state.distance / 10), // position 3
|
||||
if ((state.distance * 10).toInt() == (state.distance.toInt() * 10)) 0x00 else 0xff, // comma
|
||||
asDigit(state.distance), // position 4
|
||||
state.unit.data // unit
|
||||
))
|
||||
}
|
||||
|
||||
private open inner class ProcessingThread : Thread() {
|
||||
|
||||
|
@ -96,14 +85,6 @@ class Garmin(
|
|||
cache.update(incoming)
|
||||
}
|
||||
|
||||
private fun asDigit(input: Double): Int {
|
||||
val number = input.toInt()
|
||||
if (number == 0) {
|
||||
return 0
|
||||
}
|
||||
val m = number % 10
|
||||
return if (m == 0) 10 else m
|
||||
}
|
||||
}
|
||||
|
||||
private inner class ConnectThread : Thread() {
|
||||
|
@ -183,6 +164,7 @@ class Garmin(
|
|||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun prepareData(input: IntArray): IntArray {
|
||||
val n = input.size
|
||||
var crc = (0xeb + n + n).toUInt()
|
||||
|
|
|
@ -89,10 +89,17 @@ class GarminMapper {
|
|||
return intArrayOf(0x01, param1, param2, param3)
|
||||
}
|
||||
|
||||
private fun setDistance(distance: Int, unit: Unit = Unit.Any): IntArray {
|
||||
private fun setDistance(distance: Double, unit: Unit = Unit.Any): IntArray {
|
||||
val isDecimal = (distance * 10).toInt() == (distance.toInt() * 10)
|
||||
val distanceValue = if (isDecimal) distance * 10 else distance
|
||||
return intArrayOf(
|
||||
0x03, asDigit(distance / 1000), asDigit(distance / 100), asDigit(distance / 10),
|
||||
0x00, asDigit(distance), unit.value
|
||||
0x03,
|
||||
asDigit(distanceValue / 1000), // position 1
|
||||
asDigit(distanceValue / 100), // position 2
|
||||
asDigit(distanceValue / 10), // position 3
|
||||
if (isDecimal) 0x00 else 0xff, // comma
|
||||
asDigit(distanceValue), // position 4
|
||||
unit.value // unit
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -134,6 +141,10 @@ class GarminMapper {
|
|||
}
|
||||
}
|
||||
|
||||
private fun asDigit(n: Double): Int {
|
||||
return asDigit(n.toInt())
|
||||
}
|
||||
|
||||
private fun asDigit(n: Int): Int {
|
||||
if (n == 0) {
|
||||
return 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue