mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: calculate default values for LoRa channel_num and frequency (#664)
This commit is contained in:
parent
f27ae8feba
commit
527d94d32a
7 changed files with 141 additions and 29 deletions
|
|
@ -258,6 +258,8 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
viewModel.clearPacketResponse()
|
||||
val parsed = AdminProtos.AdminMessage.parseFrom(data.payload)
|
||||
debug("packet for destNum ${destNum.toUInt()} received ${parsed.payloadVariantCase} from $from")
|
||||
// check destination: lora config or channel editor
|
||||
val goChannels = (packetResponseState as PacketResponseState.Loading).total > 2
|
||||
when (parsed.payloadVariantCase) {
|
||||
AdminProtos.AdminMessage.PayloadVariantCase.GET_CHANNEL_RESPONSE -> {
|
||||
val response = parsed.getChannelResponse
|
||||
|
|
@ -265,7 +267,7 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
// Stop once we get to the first disabled entry
|
||||
if (response.role != ChannelProtos.Channel.Role.DISABLED) {
|
||||
channelList.add(response.index, response.settings)
|
||||
if (response.index + 1 < maxChannels) {
|
||||
if (response.index + 1 < maxChannels && goChannels) {
|
||||
// Not done yet, request next channel
|
||||
viewModel.getChannel(destNum, response.index + 1)
|
||||
} else {
|
||||
|
|
@ -285,8 +287,6 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
}
|
||||
|
||||
AdminProtos.AdminMessage.PayloadVariantCase.GET_CONFIG_RESPONSE -> {
|
||||
// check destination: lora config or channel editor
|
||||
val goChannels = (packetResponseState as PacketResponseState.Loading).total > 1
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
val response = parsed.getConfigResponse
|
||||
radioConfig = response
|
||||
|
|
@ -370,6 +370,11 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
viewModel.requestNodedbReset(destNum)
|
||||
}
|
||||
|
||||
ConfigType.LORA_CONFIG -> {
|
||||
(packetResponseState as PacketResponseState.Loading).total = 2
|
||||
channelList.clear()
|
||||
viewModel.getChannel(destNum, 0)
|
||||
}
|
||||
is ConfigType -> {
|
||||
viewModel.getConfig(destNum, configType.number)
|
||||
}
|
||||
|
|
@ -491,6 +496,7 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
composable("lora") {
|
||||
LoRaConfigItemList(
|
||||
loraConfig = radioConfig.lora,
|
||||
primarySettings = channelList.getOrNull(0) ?: return@composable,
|
||||
enabled = connected,
|
||||
focusManager = focusManager,
|
||||
onSaveClicked = { loraInput ->
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ fun EditTextPreference(
|
|||
keyboardActions: KeyboardActions,
|
||||
onValueChanged: (Int) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
onFocusChanged: (FocusState) -> Unit = {},
|
||||
trailingIcon: (@Composable () -> Unit)? = null,
|
||||
) {
|
||||
var valueState by remember(value) { mutableStateOf(value.toUInt().toString()) }
|
||||
|
|
@ -54,7 +55,7 @@ fun EditTextPreference(
|
|||
onValueChanged(int)
|
||||
}
|
||||
},
|
||||
onFocusChanged = {},
|
||||
onFocusChanged = onFocusChanged,
|
||||
modifier = modifier,
|
||||
trailingIcon = trailingIcon
|
||||
)
|
||||
|
|
@ -68,7 +69,8 @@ fun EditTextPreference(
|
|||
keyboardActions: KeyboardActions,
|
||||
onValueChanged: (Float) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
onFocusChanged: (FocusState) -> Unit = {},
|
||||
) {
|
||||
var valueState by remember(value) { mutableStateOf(value.toString()) }
|
||||
|
||||
EditTextPreference(
|
||||
|
|
@ -87,7 +89,7 @@ fun EditTextPreference(
|
|||
onValueChanged(float)
|
||||
}
|
||||
},
|
||||
onFocusChanged = {},
|
||||
onFocusChanged = onFocusChanged,
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,11 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.focus.FocusManager
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.geeksville.mesh.ChannelProtos.ChannelSettings
|
||||
import com.geeksville.mesh.ConfigProtos.Config.LoRaConfig
|
||||
import com.geeksville.mesh.copy
|
||||
import com.geeksville.mesh.model.Channel
|
||||
import com.geeksville.mesh.model.RegionInfo
|
||||
import com.geeksville.mesh.ui.components.DropDownPreference
|
||||
import com.geeksville.mesh.ui.components.EditListPreference
|
||||
import com.geeksville.mesh.ui.components.EditTextPreference
|
||||
|
|
@ -25,11 +28,13 @@ import com.geeksville.mesh.ui.components.SwitchPreference
|
|||
@Composable
|
||||
fun LoRaConfigItemList(
|
||||
loraConfig: LoRaConfig,
|
||||
primarySettings: ChannelSettings,
|
||||
enabled: Boolean,
|
||||
focusManager: FocusManager,
|
||||
onSaveClicked: (LoRaConfig) -> Unit,
|
||||
) {
|
||||
var loraInput by remember(loraConfig) { mutableStateOf(loraConfig) }
|
||||
val primaryChannel = Channel(primarySettings, loraInput)
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
|
|
@ -125,11 +130,16 @@ fun LoRaConfigItemList(
|
|||
}
|
||||
|
||||
item {
|
||||
var isFocused by remember { mutableStateOf(false) }
|
||||
EditTextPreference(title = "Channel number",
|
||||
value = loraInput.channelNum,
|
||||
value = if (isFocused || loraInput.channelNum != 0) loraInput.channelNum else primaryChannel.channelNum,
|
||||
enabled = enabled,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { loraInput = loraInput.copy { channelNum = it } })
|
||||
onFocusChanged = { isFocused = it.isFocused },
|
||||
onValueChanged = {
|
||||
if (it <= RegionInfo.numChannels(loraInput)) // max numChannels
|
||||
loraInput = loraInput.copy { channelNum = it }
|
||||
})
|
||||
}
|
||||
|
||||
item {
|
||||
|
|
@ -163,10 +173,12 @@ fun LoRaConfigItemList(
|
|||
item { Divider() }
|
||||
|
||||
item {
|
||||
var isFocused by remember { mutableStateOf(false) }
|
||||
EditTextPreference(title = "Override frequency (MHz)",
|
||||
value = loraInput.overrideFrequency,
|
||||
value = if (isFocused || loraInput.overrideFrequency != 0f) loraInput.overrideFrequency else primaryChannel.radioFreq,
|
||||
enabled = enabled,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onFocusChanged = { isFocused = it.isFocused },
|
||||
onValueChanged = { loraInput = loraInput.copy { overrideFrequency = it } })
|
||||
}
|
||||
|
||||
|
|
@ -185,9 +197,10 @@ fun LoRaConfigItemList(
|
|||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun LoRaConfigPreview(){
|
||||
fun LoRaConfigPreview() {
|
||||
LoRaConfigItemList(
|
||||
loraConfig = LoRaConfig.getDefaultInstance(),
|
||||
loraConfig = Channel.default.loraConfig,
|
||||
primarySettings = Channel.default.settings,
|
||||
enabled = true,
|
||||
focusManager = LocalFocusManager.current,
|
||||
onSaveClicked = { },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue