mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Simplified data output code, aligned with HamLib defaults
This commit is contained in:
1 parent
3f981c09d5
commit
868155c532
5 files changed
+66
-36
No files matched your search
+2
-2
@@ -55,8 +55,8 @@ class BluetoothReporter(
|
||||
if (!rotatorConnected) return@launch
|
||||
val el = if (elevation > 0.0) elevation else 0.0
|
||||
val command = format
|
||||
.replace($$"$AZ", "%03d".format(azimuth.toInt()))
|
||||
.replace($$"$EL", "%03d".format(el.toInt()))
|
||||
.replace($$"$AZ", azimuth.toString())
|
||||
.replace($$"$EL", el.toString())
|
||||
.unescapeControlChars()
|
||||
write(rotatorStream, command) { rotatorConnected = false }
|
||||
}
|
||||
|
||||
+7
-1
@@ -52,6 +52,7 @@ class NetworkReporter(
|
||||
val command = format
|
||||
.replace($$"$AZ", azimuth.toString())
|
||||
.replace($$"$EL", el.toString())
|
||||
.unescapeControlChars()
|
||||
write(rotatorSocket, command) { rotatorConnected = false }
|
||||
}
|
||||
}
|
||||
@@ -60,7 +61,9 @@ class NetworkReporter(
|
||||
reporterScope.launch {
|
||||
ensureFrequencyConnected()
|
||||
if (!frequencyConnected) return@launch
|
||||
val command = format.replace($$"$FREQ", frequency.toString())
|
||||
val command = format
|
||||
.replace($$"$FREQ", frequency.toString())
|
||||
.unescapeControlChars()
|
||||
write(frequencySocket, command) { frequencyConnected = false }
|
||||
}
|
||||
}
|
||||
@@ -110,4 +113,7 @@ class NetworkReporter(
|
||||
onError()
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.unescapeControlChars(): String =
|
||||
replace("\\r", "\r").replace("\\n", "\n").replace("\\t", "\t")
|
||||
}
|
||||
@@ -246,6 +246,29 @@ class SettingsRepo(
|
||||
//endregion
|
||||
|
||||
//region # RC settings
|
||||
init {
|
||||
migrateRCFormats()
|
||||
}
|
||||
|
||||
// TODO: Remove after a few releases (added in v4.2.0)
|
||||
private val keyRCFormatsMigrated = "rcFormatsMigrated"
|
||||
|
||||
private fun migrateRCFormats() {
|
||||
if (preferences.getBoolean(keyRCFormatsMigrated, false)) return
|
||||
val formatKeys = listOf(
|
||||
keyRotatorFormat, keyFrequencyFormat, keyBluetoothRotatorFormat, keyBluetoothFrequencyFormat
|
||||
)
|
||||
preferences.edit {
|
||||
for (key in formatKeys) {
|
||||
val value = preferences.getString(key, null) ?: continue
|
||||
if (value.contains("_") && !value.startsWith("\\")) {
|
||||
putString(key, "\\$value")
|
||||
}
|
||||
}
|
||||
putBoolean(keyRCFormatsMigrated, true)
|
||||
}
|
||||
}
|
||||
|
||||
private val _rcSettings = MutableStateFlow(getRCSettings())
|
||||
override val rcSettings: StateFlow<RCSettings> = _rcSettings
|
||||
|
||||
@@ -280,12 +303,12 @@ class SettingsRepo(
|
||||
frequencyPort = preferences.getString(keyFrequencyPort, null) ?: "4532",
|
||||
frequencyFormat = preferences.getString(keyFrequencyFormat, null) ?: $$"F $FREQ",
|
||||
bluetoothRotatorState = preferences.getBoolean(keyBluetoothRotatorState, false),
|
||||
bluetoothRotatorFormat = preferences.getString(keyBluetoothRotatorFormat, null) ?: $$"W$AZ $EL",
|
||||
bluetoothRotatorFormat = preferences.getString(keyBluetoothRotatorFormat, null) ?: $$"P $AZ $EL",
|
||||
bluetoothRotatorName = preferences.getString(keyBluetoothRotatorName, null) ?: "Default",
|
||||
bluetoothRotatorAddress = preferences.getString(keyBluetoothRotatorAddress, null) ?: "00:0C:BF:13:80:5D",
|
||||
bluetoothFrequencyState = preferences.getBoolean(keyBluetoothFrequencyState, false),
|
||||
bluetoothFrequencyAddress = preferences.getString(keyBluetoothFrequencyAddress, null) ?: "00:0C:BF:13:80:5D",
|
||||
bluetoothFrequencyFormat = preferences.getString(keyBluetoothFrequencyFormat, null) ?: $$"FA$FREQ"
|
||||
bluetoothFrequencyFormat = preferences.getString(keyBluetoothFrequencyFormat, null) ?: $$"F $FREQ"
|
||||
)
|
||||
//endregion
|
||||
|
||||
|
||||
@@ -129,7 +129,6 @@ class RadarViewModel(
|
||||
}
|
||||
processRadios(transmitters, satPass.orbitalObject, timeNow)
|
||||
sendPassData(pos)
|
||||
sendPassDataBT(pos)
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
@@ -149,33 +148,35 @@ class RadarViewModel(
|
||||
}
|
||||
|
||||
private fun sendPassData(orbitalPos: OrbitalPos) {
|
||||
viewModelScope.launch {
|
||||
val rc = settingsRepo.rcSettings.value
|
||||
if (rc.rotatorState) {
|
||||
val azimuth = orbitalPos.azimuth.toDegrees().round(2)
|
||||
val elevation = orbitalPos.elevation.toDegrees().round(2)
|
||||
networkReporter.reportRotation(rc.rotatorFormat, azimuth, elevation)
|
||||
}
|
||||
if (rc.frequencyState) {
|
||||
_uiState.value.selectedFrequency?.let { freq ->
|
||||
networkReporter.reportFrequency(rc.frequencyFormat, freq)
|
||||
}
|
||||
}
|
||||
}
|
||||
val rc = settingsRepo.rcSettings.value
|
||||
sendReporterData(
|
||||
networkReporter, orbitalPos,
|
||||
rc.rotatorState, rc.rotatorFormat,
|
||||
rc.frequencyState, rc.frequencyFormat
|
||||
)
|
||||
sendReporterData(
|
||||
bluetoothReporter, orbitalPos,
|
||||
rc.bluetoothRotatorState, rc.bluetoothRotatorFormat,
|
||||
rc.bluetoothFrequencyState, rc.bluetoothFrequencyFormat
|
||||
)
|
||||
}
|
||||
|
||||
private fun sendPassDataBT(orbitalPos: OrbitalPos) {
|
||||
viewModelScope.launch {
|
||||
val rc = settingsRepo.rcSettings.value
|
||||
if (rc.bluetoothRotatorState) {
|
||||
val azimuth = orbitalPos.azimuth.toDegrees().round(0)
|
||||
val elevation = orbitalPos.elevation.toDegrees().round(0)
|
||||
bluetoothReporter.reportRotation(rc.bluetoothRotatorFormat, azimuth, elevation)
|
||||
}
|
||||
if (rc.bluetoothFrequencyState) {
|
||||
_uiState.value.selectedFrequency?.let { freq ->
|
||||
bluetoothReporter.reportFrequency(rc.bluetoothFrequencyFormat, freq)
|
||||
}
|
||||
private fun sendReporterData(
|
||||
reporter: IReporter,
|
||||
orbitalPos: OrbitalPos,
|
||||
rotatorEnabled: Boolean,
|
||||
rotatorFormat: String,
|
||||
frequencyEnabled: Boolean,
|
||||
frequencyFormat: String
|
||||
) {
|
||||
if (rotatorEnabled) {
|
||||
val azimuth = orbitalPos.azimuth.toDegrees().round(2)
|
||||
val elevation = orbitalPos.elevation.toDegrees().round(2)
|
||||
reporter.reportRotation(rotatorFormat, azimuth, elevation)
|
||||
}
|
||||
if (frequencyEnabled) {
|
||||
_uiState.value.selectedFrequency?.let { freq ->
|
||||
reporter.reportFrequency(frequencyFormat, freq)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -216,12 +216,12 @@ fun PreviewNetworkOutputDialog() {
|
||||
frequencyPort = "4532",
|
||||
frequencyFormat = $$"F $FREQ",
|
||||
bluetoothRotatorState = false,
|
||||
bluetoothRotatorFormat = $$"W$AZ $EL",
|
||||
bluetoothRotatorFormat = $$"P $AZ $EL",
|
||||
bluetoothRotatorName = "Default",
|
||||
bluetoothRotatorAddress = "00:0C:BF:13:80:5D",
|
||||
bluetoothFrequencyState = false,
|
||||
bluetoothFrequencyAddress = "00:0C:BF:13:80:5D",
|
||||
bluetoothFrequencyFormat = $$"FA$FREQ"
|
||||
bluetoothFrequencyFormat = $$"F $FREQ"
|
||||
),
|
||||
onDismiss = {},
|
||||
onSave = { _, _, _, _, _, _, _, _ -> }
|
||||
@@ -361,14 +361,14 @@ fun PreviewBluetoothOutputDialog() {
|
||||
frequencyState = false,
|
||||
frequencyAddress = "127.0.0.1",
|
||||
frequencyPort = "4532",
|
||||
frequencyFormat = $$"set_freq $FREQ",
|
||||
frequencyFormat = $$"F $FREQ",
|
||||
bluetoothRotatorState = false,
|
||||
bluetoothRotatorFormat = $$"W$AZ $EL",
|
||||
bluetoothRotatorFormat = $$"P $AZ $EL",
|
||||
bluetoothRotatorName = "Default",
|
||||
bluetoothRotatorAddress = "00:0C:BF:13:80:5D",
|
||||
bluetoothFrequencyState = false,
|
||||
bluetoothFrequencyAddress = "00:0C:BF:13:80:5D",
|
||||
bluetoothFrequencyFormat = $$"FA$FREQ"
|
||||
bluetoothFrequencyFormat = $$"F $FREQ"
|
||||
),
|
||||
onDismiss = {},
|
||||
onSave = { _, _, _, _, _, _ -> }
|
||||
|
||||
Reference in new issue
Block a user