Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Fixed sensor error when user holds the phone upright
Arty Bishop995953b823d8
diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarFragment.ktindex 1ff37b5b..545a2cf3 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarFragment.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarFragment.kt@@ -23,6 +23,7 @@ import android.hardware.SensorEventimport android.hardware.SensorEventListenerimport android.hardware.SensorManagerimport android.os.Bundle+import android.view.Surfaceimport android.view.Viewimport androidx.fragment.app.Fragmentimport androidx.fragment.app.viewModels@@ -37,6 +38,7 @@ import com.rtbishop.look4sat.utility.formatForTimerimport dagger.hilt.android.AndroidEntryPointimport kotlinx.coroutines.FlowPreviewimport java.util.*+import kotlin.math.atan2import kotlin.math.round@FlowPreview@@ -84,10 +86,33 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {}private fun calculateAzimuth(event: SensorEvent) {+// if (event.sensor.type == Sensor.TYPE_ROTATION_VECTOR) {+// SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values)+// SensorManager.getOrientation(rotationMatrix, orientationValues)+// val magneticAzimuth = (Math.toDegrees(orientationValues[0].toDouble()) + 360f) % 360f+// val roundedAzimuth = (round(magneticAzimuth * 10) / 10).toFloat()+// polarView?.rotation = -(roundedAzimuth + magneticDeclination)+// }+if (event.sensor.type == Sensor.TYPE_ROTATION_VECTOR) {SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values)- SensorManager.getOrientation(rotationMatrix, orientationValues)- val magneticAzimuth = (Math.toDegrees(orientationValues[0].toDouble()) + 360f) % 360f+ val (matrixColumn, sense) = when (val rotation =+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {+ requireContext().display?.rotation+ } else {+ @Suppress("DEPRECATION")+ requireActivity().windowManager.defaultDisplay.rotation+ }+ ) {+ Surface.ROTATION_0 -> Pair(0, 1)+ Surface.ROTATION_90 -> Pair(1, -1)+ Surface.ROTATION_180 -> Pair(0, -1)+ Surface.ROTATION_270 -> Pair(1, 1)+ else -> error("Invalid screen rotation value: $rotation")+ }+ val x = sense * rotationMatrix[matrixColumn]+ val y = sense * rotationMatrix[matrixColumn + 3]+ val magneticAzimuth = (Math.toDegrees(-atan2(y, x).toDouble()) + 360f) % 360fval roundedAzimuth = (round(magneticAzimuth * 10) / 10).toFloat()polarView?.rotation = -(roundedAzimuth + magneticDeclination)}