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