mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Fixed recalculating Radar track on station position change (#235)
Co-authored-by: atsunatsu <atsunatsu@users.noreply.github.com> Co-authored-by: wty2019wty <74123961+wty2019wty@users.noreply.github.com>
This commit is contained in:
3 files changed
+28
-7
No files matched your search
@@ -65,8 +65,8 @@ class RadarViewModel(
|
||||
private val showToast: IShowToast
|
||||
) : ViewModel() {
|
||||
|
||||
private val stationPos = settingsRepo.stationPosition.value
|
||||
private val magDeclination = sensorsRepo.getMagDeclination(stationPos)
|
||||
private var stationPos = settingsRepo.stationPosition.value
|
||||
private var magDeclination = sensorsRepo.getMagDeclination(stationPos)
|
||||
private var compassOffset = settingsRepo.otherSettings.value.radarCompassOffset
|
||||
private var compassOffsetElev = settingsRepo.otherSettings.value.radarCompassOffsetElev
|
||||
private var transponders: List<SatRadio> = emptyList()
|
||||
@@ -92,6 +92,7 @@ class RadarViewModel(
|
||||
|
||||
init {
|
||||
collectSettingsChanges() // also handles initial sensor subscription
|
||||
collectStationPositionChanges()
|
||||
collectPassAndStartTickLoop()
|
||||
collectRadioTrackingState()
|
||||
}
|
||||
@@ -138,6 +139,23 @@ class RadarViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
private fun collectStationPositionChanges() {
|
||||
viewModelScope.launch {
|
||||
settingsRepo.stationPosition.collect { newPos ->
|
||||
if (stationPos != newPos) {
|
||||
stationPos = newPos
|
||||
magDeclination = sensorsRepo.getMagDeclination(stationPos)
|
||||
lastCelestialUpdateMs = 0L // force celestial recompute on next tick
|
||||
val pass = _uiState.value.currentPass ?: return@collect
|
||||
if (!pass.isDeepSpace) {
|
||||
val track = satelliteRepo.getTrack(pass.orbitalObject, stationPos, pass.aosTime, pass.losTime)
|
||||
_uiState.update { it.copy(satTrack = track) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Pass loading split into focused functions ---
|
||||
|
||||
private fun collectPassAndStartTickLoop() {
|
||||
|
||||
Reference in new issue
Block a user