From 379dd7118ab22202e6c019a9fd71b81285514e9e Mon Sep 17 00:00:00 2001 From: Piotr Dec Date: Mon, 21 Aug 2023 16:57:48 +0200 Subject: [PATCH] Unified with python var names --- app/src/main/java/eu/ztsh/garmin/Garmin.kt | 15 +++++++------- .../java/eu/ztsh/garmin/ManeuverMapper.kt | 15 ++++---------- app/src/main/java/eu/ztsh/garmin/Model.kt | 20 +++++++++---------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/eu/ztsh/garmin/Garmin.kt b/app/src/main/java/eu/ztsh/garmin/Garmin.kt index f71221f..702a123 100644 --- a/app/src/main/java/eu/ztsh/garmin/Garmin.kt +++ b/app/src/main/java/eu/ztsh/garmin/Garmin.kt @@ -41,6 +41,7 @@ class Garmin( private inner class ProcessingThread(val maneuver: Maneuver) : Thread() { override fun run() { + // TODO: check for equality before mapping! send(ManeuverMapper.apply(maneuver)) } @@ -57,23 +58,23 @@ 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 + 0x00, asDigit(state.distance), state.unit.value )) } private fun setDirection(direction: Direction) { - val param1 = when (direction.outAngle) { + val param1: Int = when (direction.angle) { OutAngle.LeftDown -> 0x10 OutAngle.RightDown -> 0x20 - else -> direction.outType.data + else -> direction.out.value } - val param2: Int = if (direction.outType == OutType.RightRoundabout - || direction.outType == OutType.LeftRoundabout) { - if (direction.roundabout == OutAngle.AsDirection) direction.outAngle.data else direction.roundabout.data + val param2: Int = if (direction.out == OutType.RightRoundabout + || direction.out == OutType.LeftRoundabout) { + if (direction.roundabout == OutAngle.AsDirection) direction.angle.value else direction.roundabout.value } else { 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)) } diff --git a/app/src/main/java/eu/ztsh/garmin/ManeuverMapper.kt b/app/src/main/java/eu/ztsh/garmin/ManeuverMapper.kt index 3b8b54f..11c7fc3 100644 --- a/app/src/main/java/eu/ztsh/garmin/ManeuverMapper.kt +++ b/app/src/main/java/eu/ztsh/garmin/ManeuverMapper.kt @@ -10,17 +10,10 @@ class ManeuverMapper { val state = State() maneuver.apply { this.primary.apply { - state.direction = Direction() when (this.type) { - "turn" -> { - state.direction.outType = OutType.Lane - state.direction.roundabout = OutAngle.AsDirection - } - "roundabout" -> { - state.direction.outType = OutType.RightRoundabout + state.direction.out = OutType.RightRoundabout } - "arrive" -> { state.flag = true } @@ -28,17 +21,17 @@ class ManeuverMapper { when (this.modifier) { "right" -> { when (this.type) { - "turn" -> state.direction.outAngle = OutAngle.Right + "turn" -> state.direction.angle = OutAngle.Right "roundabout" -> { when (this.degrees) { - 137.0 -> state.direction.outAngle = OutAngle.EasyRight + 137.0 -> state.direction.angle = OutAngle.EasyRight } } } } "left" -> { when (this.type) { - "turn" -> state.direction.outAngle = OutAngle.Left + "turn" -> state.direction.angle = OutAngle.Left } } } diff --git a/app/src/main/java/eu/ztsh/garmin/Model.kt b/app/src/main/java/eu/ztsh/garmin/Model.kt index 15e77bf..27a46f6 100644 --- a/app/src/main/java/eu/ztsh/garmin/Model.kt +++ b/app/src/main/java/eu/ztsh/garmin/Model.kt @@ -1,6 +1,6 @@ package eu.ztsh.garmin -enum class OutType(val data: Int) { +enum class OutType(val value: Int) { Off(0x00), 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), 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), 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), OuterRight(0x02), @@ -70,8 +70,8 @@ class State { } class Direction { - var outAngle: OutAngle = OutAngle.AsDirection - var outType: OutType = OutType.Lane + var angle: OutAngle = OutAngle.AsDirection + var out: OutType = OutType.Lane var roundabout: OutAngle = OutAngle.AsDirection override fun equals(other: Any?): Boolean { if (this === other) return true @@ -79,16 +79,16 @@ class Direction { other as Direction - if (outAngle != other.outAngle) return false - if (outType != other.outType) return false + if (angle != other.angle) return false + if (out != other.out) return false if (roundabout != other.roundabout) return false return true } override fun hashCode(): Int { - var result = outAngle.hashCode() - result = 31 * result + outType.hashCode() + var result = angle.hashCode() + result = 31 * result + out.hashCode() result = 31 * result + roundabout.hashCode() return result }