fix: isDigit & setDistance
This commit is contained in:
parent
6f3643a2b4
commit
35e24dcc8e
2 changed files with 16 additions and 23 deletions
|
@ -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