mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
update for proto changes
This commit is contained in:
parent
5c586526da
commit
5382fdae49
10 changed files with 78 additions and 60 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import com.geeksville.mesh.ChannelProtos
|
||||
import com.geeksville.mesh.ConfigProtos.Config.LoRaConfig.ModemPreset
|
||||
import com.geeksville.mesh.ConfigKt.loRaConfig
|
||||
import com.geeksville.mesh.ConfigProtos
|
||||
import com.geeksville.mesh.channelSettings
|
||||
|
|
@ -28,7 +29,7 @@ data class Channel(
|
|||
// The default channel that devices ship with
|
||||
val default = Channel(
|
||||
channelSettings { psk = ByteString.copyFrom(defaultPSK) },
|
||||
loRaConfig { modemPreset = ConfigProtos.Config.LoRaConfig.ModemPreset.LongFast }
|
||||
loRaConfig { usePreset = true; modemPreset = ModemPreset.LONG_FAST }
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -39,13 +40,13 @@ data class Channel(
|
|||
if (loraConfig.bandwidth != 0)
|
||||
"Unset"
|
||||
else when (loraConfig.modemPreset) {
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.ShortFast -> "ShortFast"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.ShortSlow -> "ShortSlow"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.MedFast -> "MidFast"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.MedSlow -> "MidSlow"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.LongFast -> "LongFast"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.LongSlow -> "LongSlow"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.VLongSlow -> "VLongSlow"
|
||||
ModemPreset.SHORT_FAST -> "ShortFast"
|
||||
ModemPreset.SHORT_SLOW -> "ShortSlow"
|
||||
ModemPreset.MEDIUM_FAST -> "MidFast"
|
||||
ModemPreset.MEDIUM_SLOW -> "MidSlow"
|
||||
ModemPreset.LONG_FAST -> "LongFast"
|
||||
ModemPreset.LONG_SLOW -> "LongSlow"
|
||||
ModemPreset.VERY_LONG_SLOW -> "VLongSlow"
|
||||
else -> "Invalid"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import com.geeksville.mesh.ConfigProtos
|
||||
import com.geeksville.mesh.ConfigProtos.Config.LoRaConfig.ModemPreset
|
||||
import com.geeksville.mesh.R
|
||||
|
||||
enum class ChannelOption(
|
||||
val modemPreset: ConfigProtos.Config.LoRaConfig.ModemPreset,
|
||||
val modemPreset: ModemPreset,
|
||||
val configRes: Int,
|
||||
val minBroadcastPeriodSecs: Int
|
||||
) {
|
||||
SHORT_FAST(ConfigProtos.Config.LoRaConfig.ModemPreset.ShortFast, R.string.modem_config_short, 30),
|
||||
SHORT_SLOW(ConfigProtos.Config.LoRaConfig.ModemPreset.ShortSlow, R.string.modem_config_slow_short, 30),
|
||||
MED_FAST(ConfigProtos.Config.LoRaConfig.ModemPreset.MedFast, R.string.modem_config_medium, 60),
|
||||
MED_SLOW(ConfigProtos.Config.LoRaConfig.ModemPreset.MedSlow, R.string.modem_config_slow_medium, 60),
|
||||
LONG_FAST(ConfigProtos.Config.LoRaConfig.ModemPreset.LongFast, R.string.modem_config_long, 240),
|
||||
LONG_SLOW(ConfigProtos.Config.LoRaConfig.ModemPreset.LongSlow, R.string.modem_config_slow_long, 375),
|
||||
VERY_LONG(ConfigProtos.Config.LoRaConfig.ModemPreset.VLongSlow, R.string.modem_config_very_long, 375);
|
||||
SHORT_FAST(ModemPreset.SHORT_FAST, R.string.modem_config_short, 30),
|
||||
SHORT_SLOW(ModemPreset.SHORT_SLOW, R.string.modem_config_slow_short, 30),
|
||||
MEDIUM_FAST(ModemPreset.MEDIUM_FAST, R.string.modem_config_medium, 60),
|
||||
MEDIUM_SLOW(ModemPreset.MEDIUM_SLOW, R.string.modem_config_slow_medium, 60),
|
||||
LONG_FAST(ModemPreset.LONG_FAST, R.string.modem_config_long, 60),
|
||||
LONG_SLOW(ModemPreset.LONG_SLOW, R.string.modem_config_slow_long, 240),
|
||||
VERY_LONG_SLOW(ModemPreset.VERY_LONG_SLOW, R.string.modem_config_very_long, 375);
|
||||
|
||||
companion object {
|
||||
fun fromConfig(modemPreset: ConfigProtos.Config.LoRaConfig.ModemPreset?): ChannelOption? {
|
||||
fun fromConfig(modemPreset: ModemPreset?): ChannelOption? {
|
||||
for (option in values()) {
|
||||
if (option.modemPreset == modemPreset)
|
||||
return option
|
||||
|
|
@ -25,6 +25,6 @@ enum class ChannelOption(
|
|||
return null
|
||||
}
|
||||
|
||||
val defaultMinBroadcastPeriod = VERY_LONG.minBroadcastPeriodSecs
|
||||
val defaultMinBroadcastPeriod = VERY_LONG_SLOW.minBroadcastPeriodSecs
|
||||
}
|
||||
}
|
||||
|
|
@ -206,24 +206,30 @@ class UIViewModel @Inject constructor(
|
|||
_requestChannelUrl.value = null
|
||||
}
|
||||
|
||||
var txEnabled: Boolean
|
||||
get() = config.lora.txEnabled
|
||||
set(value) {
|
||||
updateLoraConfig { it.copy { txEnabled = value } }
|
||||
}
|
||||
|
||||
var region: Config.LoRaConfig.RegionCode
|
||||
get() = config.lora?.region ?: Config.LoRaConfig.RegionCode.Unset
|
||||
get() = config.lora.region
|
||||
set(value) {
|
||||
updateLoraConfig { it.copy { region = value } }
|
||||
}
|
||||
|
||||
fun gpsString(pos: Position): String {
|
||||
return when (_localConfig.value?.display?.gpsFormat) {
|
||||
ConfigProtos.Config.DisplayConfig.GpsCoordinateFormat.GpsFormatDec -> GPSFormat.dec(pos)
|
||||
ConfigProtos.Config.DisplayConfig.GpsCoordinateFormat.GpsFormatDMS -> GPSFormat.toDMS(pos)
|
||||
ConfigProtos.Config.DisplayConfig.GpsCoordinateFormat.GpsFormatUTM -> GPSFormat.toUTM(pos)
|
||||
ConfigProtos.Config.DisplayConfig.GpsCoordinateFormat.GpsFormatMGRS -> GPSFormat.toMGRS(pos)
|
||||
else -> GPSFormat.dec(pos)
|
||||
fun gpsString(p: Position): String {
|
||||
return when (config.display.gpsFormat) {
|
||||
Config.DisplayConfig.GpsCoordinateFormat.DEC -> GPSFormat.DEC(p)
|
||||
Config.DisplayConfig.GpsCoordinateFormat.DMS -> GPSFormat.DMS(p)
|
||||
Config.DisplayConfig.GpsCoordinateFormat.UTM -> GPSFormat.UTM(p)
|
||||
Config.DisplayConfig.GpsCoordinateFormat.MGRS -> GPSFormat.MGRS(p)
|
||||
else -> GPSFormat.DEC(p)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
val isRouter: Boolean = config.device?.role == Config.DeviceConfig.Role.Router
|
||||
val isRouter: Boolean = config.device.role == Config.DeviceConfig.Role.ROUTER
|
||||
|
||||
// We consider hasWifi = ESP32
|
||||
fun isESP32() = myNodeInfo.value?.hasWifi == true
|
||||
|
|
@ -279,9 +285,9 @@ class UIViewModel @Inject constructor(
|
|||
setDeviceConfig(config { power = data })
|
||||
}
|
||||
|
||||
inline fun updateNetworkConfig(crossinline body: (Config.WiFiConfig) -> Config.WiFiConfig) {
|
||||
val data = body(config.wifi)
|
||||
setDeviceConfig(config { wifi = data })
|
||||
inline fun updateNetworkConfig(crossinline body: (Config.NetworkConfig) -> Config.NetworkConfig) {
|
||||
val data = body(config.network)
|
||||
setDeviceConfig(config { network = data })
|
||||
}
|
||||
|
||||
inline fun updateDisplayConfig(crossinline body: (Config.DisplayConfig) -> Config.DisplayConfig) {
|
||||
|
|
@ -360,14 +366,7 @@ class UIViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun requestFactoryReset() {
|
||||
val config = _localConfig.value
|
||||
if (config != null) {
|
||||
val builder = config.device.toBuilder()
|
||||
builder.factoryReset = true
|
||||
val newConfig = ConfigProtos.Config.newBuilder()
|
||||
newConfig.device = builder.build()
|
||||
setDeviceConfig(newConfig.build())
|
||||
}
|
||||
meshService?.requestFactoryReset(DataPacket.ID_LOCAL)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue