fix: Distance changed to Double

This commit is contained in:
Piotr Dec 2024-07-26 00:58:55 +02:00
parent 73a57cb742
commit 7e9b2dbc34
Signed by: stawros
GPG key ID: F89F27AD8F881A91
3 changed files with 13 additions and 8 deletions

View file

@ -55,8 +55,13 @@ class Garmin(
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.data
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
))
}
@ -76,11 +81,12 @@ class Garmin(
connection.enqueue(intArrayOf(0x01, param1, param2, param3))
}
private fun asDigit(n: Int): Int {
if (n == 0) {
private fun asDigit(input: Double): Int {
val number = input.toInt()
if (number == 0) {
return 0
}
val m = n % 10
val m = number % 10
return if (m == 0) 10 else m
}
}

View file

@ -48,8 +48,7 @@ class ManeuverMapper {
this.stepDistance.apply {
this.distanceRemaining?.apply {
distanceFormatter.formatDistance(distanceRemaining!!).split(" ").apply {
// TODO: Send double
state.distance = this[0].replace(',', '.').toDouble().toInt()
state.distance = this[0].replace(',', '.').toDouble()
state.unit = when (this[1]) {
"m" -> Unit.Metres
"km" -> Unit.Kilometres

View file

@ -57,7 +57,7 @@ class State {
var lineArrows: Int = 0
var lineOutlines: Int = 0
var direction = Direction()
var distance: Int = 0
var distance: Double = 0.0
var unit: Unit = Unit.Any
var speed: Int = 0
var limit: Int = 0