kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
rodzic
23f05c109b
commit
9cce785556
|
@ -64,29 +64,29 @@ internal fun LoRaConfig.radioFreq(channelNum: Int): Float {
|
|||
@Suppress("MagicNumber")
|
||||
enum class RegionInfo(
|
||||
val regionCode: RegionCode,
|
||||
val description: String,
|
||||
val freqStart: Float,
|
||||
val freqEnd: Float,
|
||||
) {
|
||||
US(RegionCode.US, 902.0f, 928.0f),
|
||||
EU_433(RegionCode.EU_433, 433.0f, 434.0f),
|
||||
EU_868(RegionCode.EU_868, 869.4f, 869.65f),
|
||||
CN(RegionCode.CN, 470.0f, 510.0f),
|
||||
JP(RegionCode.JP, 920.5f, 923.5f),
|
||||
ANZ(RegionCode.ANZ, 915.0f, 928.0f),
|
||||
RU(RegionCode.RU, 868.7f, 869.2f),
|
||||
KR(RegionCode.KR, 920.0f, 923.0f),
|
||||
TW(RegionCode.TW, 920.0f, 925.0f),
|
||||
IN(RegionCode.IN, 865.0f, 867.0f),
|
||||
NZ_865(RegionCode.NZ_865, 864.0f, 868.0f),
|
||||
TH(RegionCode.TH, 920.0f, 925.0f),
|
||||
UA_433(RegionCode.UA_433, 433.0f, 434.7f),
|
||||
UA_868(RegionCode.UA_868, 868.0f, 868.6f),
|
||||
MY_433(RegionCode.MY_433, 433.0f, 435.0f),
|
||||
MY_919(RegionCode.MY_919, 919.0f, 924.0f),
|
||||
SG_923(RegionCode.SG_923, 917.0f, 925.0f),
|
||||
LORA_24(RegionCode.LORA_24, 2400.0f, 2483.5f),
|
||||
UNSET(RegionCode.UNSET, 902.0f, 928.0f),
|
||||
;
|
||||
UNSET(RegionCode.UNSET, "Please set a region", 902.0f, 928.0f),
|
||||
US(RegionCode.US, "United States", 902.0f, 928.0f),
|
||||
EU_433(RegionCode.EU_433, "European Union 433MHz", 433.0f, 434.0f),
|
||||
EU_868(RegionCode.EU_868, "European Union 868MHz", 869.4f, 869.65f),
|
||||
CN(RegionCode.CN, "China", 470.0f, 510.0f),
|
||||
JP(RegionCode.JP, "Japan", 920.5f, 923.5f),
|
||||
ANZ(RegionCode.ANZ, "Australia / New Zealand", 915.0f, 928.0f),
|
||||
KR(RegionCode.KR, "Korea", 920.0f, 923.0f),
|
||||
TW(RegionCode.TW, "Taiwan", 920.0f, 925.0f),
|
||||
RU(RegionCode.RU, "Russia", 868.7f, 869.2f),
|
||||
IN(RegionCode.IN, "India", 865.0f, 867.0f),
|
||||
NZ_865(RegionCode.NZ_865, "New Zealand 865MHz", 864.0f, 868.0f),
|
||||
TH(RegionCode.TH, "Thailand", 920.0f, 925.0f),
|
||||
UA_433(RegionCode.UA_433, "Ukraine 433MHz", 433.0f, 434.7f),
|
||||
UA_868(RegionCode.UA_868, "Ukraine 868MHz", 868.0f, 868.6f),
|
||||
MY_433(RegionCode.MY_433, "Malaysia 433MHz", 433.0f, 435.0f),
|
||||
MY_919(RegionCode.MY_919, "Malaysia 919MHz", 919.0f, 924.0f),
|
||||
SG_923(RegionCode.SG_923, "Singapore 923MHz", 917.0f, 925.0f),
|
||||
LORA_24(RegionCode.LORA_24, "2.4 GHz", 2400.0f, 2483.5f),
|
||||
}
|
||||
|
||||
enum class ChannelOption(
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.view.inputmethod.EditorInfo
|
|||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.RadioButton
|
||||
import android.widget.TextView
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
|
@ -25,6 +26,7 @@ import com.geeksville.mesh.android.*
|
|||
import com.geeksville.mesh.databinding.SettingsFragmentBinding
|
||||
import com.geeksville.mesh.model.BTScanModel
|
||||
import com.geeksville.mesh.model.BluetoothViewModel
|
||||
import com.geeksville.mesh.model.RegionInfo
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.mesh.repository.location.LocationRepository
|
||||
import com.geeksville.mesh.service.MeshService
|
||||
|
@ -80,13 +82,12 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
// update the region selection from the device
|
||||
val region = model.region
|
||||
val spinner = binding.regionSpinner
|
||||
val unsetIndex = regions.indexOf(ConfigProtos.Config.LoRaConfig.RegionCode.UNSET.name)
|
||||
spinner.onItemSelectedListener = null
|
||||
|
||||
debug("current region is $region")
|
||||
var regionIndex = regions.indexOf(region.name)
|
||||
var regionIndex = regions.indexOfFirst { it.regionCode == region }
|
||||
if (regionIndex == -1) // Not found, probably because the device has a region our app doesn't yet understand. Punt and say Unset
|
||||
regionIndex = unsetIndex
|
||||
regionIndex = ConfigProtos.Config.LoRaConfig.RegionCode.UNSET_VALUE
|
||||
|
||||
// We don't want to be notified of our own changes, so turn off listener while making them
|
||||
spinner.setSelection(regionIndex, false)
|
||||
|
@ -114,8 +115,8 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
position: Int,
|
||||
id: Long
|
||||
) {
|
||||
val item = parent.getItemAtPosition(position) as String?
|
||||
val asProto = item!!.let { ConfigProtos.Config.LoRaConfig.RegionCode.valueOf(it) }
|
||||
val item = RegionInfo.entries[position]
|
||||
val asProto = item.regionCode
|
||||
exceptionToSnackbar(requireView()) {
|
||||
debug("regionSpinner onItemSelected $asProto")
|
||||
if (asProto != model.region) model.region = asProto
|
||||
|
@ -128,12 +129,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
/// the sorted list of region names like arrayOf("US", "CN", "EU488")
|
||||
private val regions = ConfigProtos.Config.LoRaConfig.RegionCode.entries.filter {
|
||||
it != ConfigProtos.Config.LoRaConfig.RegionCode.UNRECOGNIZED
|
||||
}.map {
|
||||
it.name
|
||||
}.sorted()
|
||||
private val regions = RegionInfo.entries
|
||||
|
||||
private fun initCommonUI() {
|
||||
|
||||
|
@ -151,8 +147,27 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
|
||||
// init our region spinner
|
||||
val spinner = binding.regionSpinner
|
||||
val regionAdapter =
|
||||
ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, regions)
|
||||
val regionAdapter = object : ArrayAdapter<RegionInfo>(
|
||||
requireContext(),
|
||||
android.R.layout.simple_spinner_item,
|
||||
regions
|
||||
) {
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val view = super.getView(position, convertView, parent)
|
||||
(view as? TextView)?.text = regions[position].name
|
||||
return view
|
||||
}
|
||||
|
||||
override fun getDropDownView(
|
||||
position: Int,
|
||||
convertView: View?,
|
||||
parent: ViewGroup
|
||||
): View {
|
||||
val view = super.getDropDownView(position, convertView, parent)
|
||||
(view as? TextView)?.text = regions[position].description
|
||||
return view
|
||||
}
|
||||
}
|
||||
regionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
spinner.adapter = regionAdapter
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ 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.model.numChannels
|
||||
import com.geeksville.mesh.ui.components.DropDownPreference
|
||||
import com.geeksville.mesh.ui.components.EditListPreference
|
||||
|
@ -101,9 +102,7 @@ fun LoRaConfigItemList(
|
|||
item {
|
||||
DropDownPreference(title = "Region (frequency plan)",
|
||||
enabled = enabled,
|
||||
items = LoRaConfig.RegionCode.entries
|
||||
.filter { it != LoRaConfig.RegionCode.UNRECOGNIZED }
|
||||
.map { it to it.name },
|
||||
items = RegionInfo.entries.map { it.regionCode to it.description },
|
||||
selectedItem = loraInput.region,
|
||||
onItemSelected = { loraInput = loraInput.copy { region = it } })
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue