Unified with python var names

This commit is contained in:
Piotr Dec 2023-08-21 16:57:48 +02:00
parent 385234bfd9
commit 379dd7118a
No known key found for this signature in database
GPG key ID: ABD6CB83D6110D27
3 changed files with 22 additions and 28 deletions

View file

@ -41,6 +41,7 @@ class Garmin(
private inner class ProcessingThread(val maneuver: Maneuver) : Thread() { private inner class ProcessingThread(val maneuver: Maneuver) : Thread() {
override fun run() { override fun run() {
// TODO: check for equality before mapping!
send(ManeuverMapper.apply(maneuver)) send(ManeuverMapper.apply(maneuver))
} }
@ -57,23 +58,23 @@ class Garmin(
private fun setDistance(state: eu.ztsh.garmin.State) { private fun setDistance(state: eu.ztsh.garmin.State) {
connection.enqueue(intArrayOf( connection.enqueue(intArrayOf(
0x03, asDigit(state.distance / 1000), asDigit(state.distance / 100), asDigit(state.distance / 10), 0x03, asDigit(state.distance / 1000), asDigit(state.distance / 100), asDigit(state.distance / 10),
0x00, asDigit(state.distance), state.unit.data 0x00, asDigit(state.distance), state.unit.value
)) ))
} }
private fun setDirection(direction: Direction) { private fun setDirection(direction: Direction) {
val param1 = when (direction.outAngle) { val param1: Int = when (direction.angle) {
OutAngle.LeftDown -> 0x10 OutAngle.LeftDown -> 0x10
OutAngle.RightDown -> 0x20 OutAngle.RightDown -> 0x20
else -> direction.outType.data else -> direction.out.value
} }
val param2: Int = if (direction.outType == OutType.RightRoundabout val param2: Int = if (direction.out == OutType.RightRoundabout
|| direction.outType == OutType.LeftRoundabout) { || direction.out == OutType.LeftRoundabout) {
if (direction.roundabout == OutAngle.AsDirection) direction.outAngle.data else direction.roundabout.data if (direction.roundabout == OutAngle.AsDirection) direction.angle.value else direction.roundabout.value
} else { } else {
0x00 0x00
} }
val param3: Int = if (direction.outAngle == OutAngle.LeftDown || direction.outAngle == OutAngle.RightDown) 0x00 else direction.outAngle.data val param3: Int = if (direction.angle == OutAngle.LeftDown || direction.angle == OutAngle.RightDown) 0x00 else direction.angle.value
connection.enqueue(intArrayOf(0x01, param1, param2, param3)) connection.enqueue(intArrayOf(0x01, param1, param2, param3))
} }

View file

@ -10,17 +10,10 @@ class ManeuverMapper {
val state = State() val state = State()
maneuver.apply { maneuver.apply {
this.primary.apply { this.primary.apply {
state.direction = Direction()
when (this.type) { when (this.type) {
"turn" -> {
state.direction.outType = OutType.Lane
state.direction.roundabout = OutAngle.AsDirection
}
"roundabout" -> { "roundabout" -> {
state.direction.outType = OutType.RightRoundabout state.direction.out = OutType.RightRoundabout
} }
"arrive" -> { "arrive" -> {
state.flag = true state.flag = true
} }
@ -28,17 +21,17 @@ class ManeuverMapper {
when (this.modifier) { when (this.modifier) {
"right" -> { "right" -> {
when (this.type) { when (this.type) {
"turn" -> state.direction.outAngle = OutAngle.Right "turn" -> state.direction.angle = OutAngle.Right
"roundabout" -> { "roundabout" -> {
when (this.degrees) { when (this.degrees) {
137.0 -> state.direction.outAngle = OutAngle.EasyRight 137.0 -> state.direction.angle = OutAngle.EasyRight
} }
} }
} }
} }
"left" -> { "left" -> {
when (this.type) { when (this.type) {
"turn" -> state.direction.outAngle = OutAngle.Left "turn" -> state.direction.angle = OutAngle.Left
} }
} }
} }

View file

@ -1,6 +1,6 @@
package eu.ztsh.garmin package eu.ztsh.garmin
enum class OutType(val data: Int) { enum class OutType(val value: Int) {
Off(0x00), Off(0x00),
Lane(0x01), Lane(0x01),
@ -13,7 +13,7 @@ enum class OutType(val data: Int) {
} }
enum class OutAngle(val data: Int) { enum class OutAngle(val value: Int) {
Down(0x01), Down(0x01),
SharpRight(0x02), SharpRight(0x02),
@ -29,7 +29,7 @@ enum class OutAngle(val data: Int) {
} }
enum class Unit(val data: Int) { enum class Unit(val value: Int) {
Any(0), Any(0),
Metres(1), Metres(1),
@ -39,7 +39,7 @@ enum class Unit(val data: Int) {
} }
enum class Lane(val data: Int) { enum class Lane(val value: Int) {
DotsRight(0x01), DotsRight(0x01),
OuterRight(0x02), OuterRight(0x02),
@ -70,8 +70,8 @@ class State {
} }
class Direction { class Direction {
var outAngle: OutAngle = OutAngle.AsDirection var angle: OutAngle = OutAngle.AsDirection
var outType: OutType = OutType.Lane var out: OutType = OutType.Lane
var roundabout: OutAngle = OutAngle.AsDirection var roundabout: OutAngle = OutAngle.AsDirection
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
@ -79,16 +79,16 @@ class Direction {
other as Direction other as Direction
if (outAngle != other.outAngle) return false if (angle != other.angle) return false
if (outType != other.outType) return false if (out != other.out) return false
if (roundabout != other.roundabout) return false if (roundabout != other.roundabout) return false
return true return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = outAngle.hashCode() var result = angle.hashCode()
result = 31 * result + outType.hashCode() result = 31 * result + out.hashCode()
result = 31 * result + roundabout.hashCode() result = 31 * result + roundabout.hashCode()
return result return result
} }