From 78845ab4240a474f51a0801d20b41d26c8ac99a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylwester=20Zieli=C5=84ski?= Date: Tue, 22 Mar 2022 13:10:22 +0100 Subject: [PATCH] Fix calculating mph on CSC profile --- .../nordicsemi/android/csc/view/CSCMappers.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCMappers.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCMappers.kt index 4295cd36..fd23c9cf 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCMappers.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCMappers.kt @@ -34,15 +34,15 @@ internal fun CSCData.displayDistance(speedUnit: SpeedUnit): String { return when (speedUnit) { SpeedUnit.M_S -> String.format("%.0f m", distance) SpeedUnit.KM_H -> String.format("%.0f m", distance) - SpeedUnit.MPH -> String.format("%.0f yd", distance) + SpeedUnit.MPH -> String.format("%.0f yd", distance.toYards()) } } internal fun CSCData.displayTotalDistance(speedUnit: SpeedUnit): String { return when (speedUnit) { - SpeedUnit.M_S -> String.format("%.2f km", totalDistance) - SpeedUnit.KM_H -> String.format("%.2f km", totalDistance) - SpeedUnit.MPH -> String.format("%.2f mile", totalDistance) + SpeedUnit.M_S -> String.format("%.2f m", totalDistance) + SpeedUnit.KM_H -> String.format("%.2f km", totalDistance.toKilometers()) + SpeedUnit.MPH -> String.format("%.2f mile", totalDistance.toMiles()) } } @@ -77,3 +77,15 @@ private fun displayTemperature(unit: SpeedUnit): String { } } +private fun Float.toYards(): Float { + return this*1.0936f +} + +private fun Float.toKilometers(): Float { + return this/1000f +} + +private fun Float.toMiles(): Float { + return this*0.0006f +} +