mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-03 19:27:24 +00:00
Added magnetic declination calculation for true north #25
This commit is contained in:
1 parent
8c221c6144
commit
dd6151a6cf
1 file changed
+26
-15
@@ -20,10 +20,7 @@
|
|||||||
package com.rtbishop.look4sat.ui.fragments
|
package com.rtbishop.look4sat.ui.fragments
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.hardware.Sensor
|
import android.hardware.*
|
||||||
import android.hardware.SensorEvent
|
|
||||||
import android.hardware.SensorEventListener
|
|
||||||
import android.hardware.SensorManager
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
@@ -59,6 +56,7 @@ class PolarViewFragment : Fragment(R.layout.fragment_polar_view), SensorEventLis
|
|||||||
private var polarView: PolarView? = null
|
private var polarView: PolarView? = null
|
||||||
private val args: PolarViewFragmentArgs by navArgs()
|
private val args: PolarViewFragmentArgs by navArgs()
|
||||||
private val transmitterAdapter = TransmitterAdapter()
|
private val transmitterAdapter = TransmitterAdapter()
|
||||||
|
private var magneticDeclination = 0f
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
@@ -72,6 +70,7 @@ class PolarViewFragment : Fragment(R.layout.fragment_polar_view), SensorEventLis
|
|||||||
adapter = transmitterAdapter
|
adapter = transmitterAdapter
|
||||||
}
|
}
|
||||||
observePasses()
|
observePasses()
|
||||||
|
observeStationPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
@@ -103,7 +102,7 @@ class PolarViewFragment : Fragment(R.layout.fragment_polar_view), SensorEventLis
|
|||||||
SensorManager.getOrientation(rotationValues, orientationValues)
|
SensorManager.getOrientation(rotationValues, orientationValues)
|
||||||
val magneticAzimuth = ((orientationValues[0] * 57.2957795f) + 360f) % 360f
|
val magneticAzimuth = ((orientationValues[0] * 57.2957795f) + 360f) % 360f
|
||||||
val roundedAzimuth = round(magneticAzimuth * 100) / 100
|
val roundedAzimuth = round(magneticAzimuth * 100) / 100
|
||||||
polarView?.rotation = -roundedAzimuth
|
polarView?.rotation = -(roundedAzimuth + magneticDeclination)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterSensorData(input: FloatArray, output: FloatArray) {
|
private fun filterSensorData(input: FloatArray, output: FloatArray) {
|
||||||
@@ -113,16 +112,14 @@ class PolarViewFragment : Fragment(R.layout.fragment_polar_view), SensorEventLis
|
|||||||
|
|
||||||
private fun observePasses() {
|
private fun observePasses() {
|
||||||
viewModel.getPassList().observe(viewLifecycleOwner, { result ->
|
viewModel.getPassList().observe(viewLifecycleOwner, { result ->
|
||||||
when (result) {
|
if (result is Result.Success) {
|
||||||
is Result.Success -> {
|
val refreshRate = viewModel.getRefreshRate()
|
||||||
val refreshRate = viewModel.getRefreshRate()
|
satPass = result.data[args.satPassIndex]
|
||||||
satPass = result.data[args.satPassIndex]
|
mainActivity.supportActionBar?.title = satPass.tle.name
|
||||||
mainActivity.supportActionBar?.title = satPass.tle.name
|
polarView = PolarView(mainActivity, satPass)
|
||||||
polarView = PolarView(mainActivity, satPass)
|
binding.framePolar.addView(polarView)
|
||||||
binding.framePolar.addView(polarView)
|
observeTransmitters()
|
||||||
observeTransmitters()
|
refreshText(refreshRate)
|
||||||
refreshText(refreshRate)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -142,6 +139,20 @@ class PolarViewFragment : Fragment(R.layout.fragment_polar_view), SensorEventLis
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun observeStationPosition() {
|
||||||
|
viewModel.getGSP().observe(viewLifecycleOwner, { result ->
|
||||||
|
if (result is Result.Success) {
|
||||||
|
val geoField = GeomagneticField(
|
||||||
|
result.data.latitude.toFloat(),
|
||||||
|
result.data.longitude.toFloat(),
|
||||||
|
result.data.heightAMSL.toFloat(),
|
||||||
|
System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
magneticDeclination = geoField.declination
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private fun refreshText(rate: Long) {
|
private fun refreshText(rate: Long) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
Reference in new issue
Block a user