fix: isDigit & setDistance

This commit is contained in:
Piotr Dec 2024-07-30 20:03:47 +02:00
parent 6f3643a2b4
commit 35e24dcc8e
Signed by: stawros
GPG key ID: F89F27AD8F881A91
2 changed files with 16 additions and 23 deletions

View file

@ -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()