kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
rodzic
3c22272d23
commit
96a69b7398
|
@ -13,13 +13,12 @@ import com.geeksville.mesh.IMeshService
|
||||||
import com.geeksville.mesh.MeshProtos
|
import com.geeksville.mesh.MeshProtos
|
||||||
import com.geeksville.mesh.ModuleConfigProtos
|
import com.geeksville.mesh.ModuleConfigProtos
|
||||||
import com.geeksville.mesh.MyNodeInfo
|
import com.geeksville.mesh.MyNodeInfo
|
||||||
import com.geeksville.mesh.NodeInfo
|
|
||||||
import com.geeksville.mesh.Portnums
|
import com.geeksville.mesh.Portnums
|
||||||
import com.geeksville.mesh.Position
|
import com.geeksville.mesh.Position
|
||||||
import com.geeksville.mesh.R
|
import com.geeksville.mesh.R
|
||||||
import com.geeksville.mesh.android.Logging
|
import com.geeksville.mesh.android.Logging
|
||||||
import com.geeksville.mesh.config
|
import com.geeksville.mesh.config
|
||||||
import com.geeksville.mesh.database.entity.toNodeInfo
|
import com.geeksville.mesh.database.entity.NodeEntity
|
||||||
import com.geeksville.mesh.deviceProfile
|
import com.geeksville.mesh.deviceProfile
|
||||||
import com.geeksville.mesh.moduleConfig
|
import com.geeksville.mesh.moduleConfig
|
||||||
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
|
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
|
||||||
|
@ -70,12 +69,12 @@ class RadioConfigViewModel @Inject constructor(
|
||||||
val connectionState get() = radioConfigRepository.connectionState
|
val connectionState get() = radioConfigRepository.connectionState
|
||||||
|
|
||||||
private val _destNum = MutableStateFlow<Int?>(null)
|
private val _destNum = MutableStateFlow<Int?>(null)
|
||||||
private val _destNode = MutableStateFlow<NodeInfo?>(null)
|
private val _destNode = MutableStateFlow<NodeEntity?>(null)
|
||||||
val destNode: StateFlow<NodeInfo?> get() = _destNode
|
val destNode: StateFlow<NodeEntity?> get() = _destNode
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the destination [NodeInfo] used in Radio Configuration.
|
* Sets the destination [NodeEntity] used in Radio Configuration.
|
||||||
* @param num Destination nodeNum (or null for our local [NodeInfo]).
|
* @param num Destination nodeNum (or null for our local [NodeEntity]).
|
||||||
*/
|
*/
|
||||||
fun setDestNum(num: Int?) {
|
fun setDestNum(num: Int?) {
|
||||||
_destNum.value = num
|
_destNum.value = num
|
||||||
|
@ -91,7 +90,7 @@ class RadioConfigViewModel @Inject constructor(
|
||||||
init {
|
init {
|
||||||
combine(_destNum, radioConfigRepository.nodeDBbyNum) { destNum, nodes ->
|
combine(_destNum, radioConfigRepository.nodeDBbyNum) { destNum, nodes ->
|
||||||
nodes[destNum] ?: nodes.values.firstOrNull()
|
nodes[destNum] ?: nodes.values.firstOrNull()
|
||||||
}.onEach { _destNode.value = it?.toNodeInfo() }.launchIn(viewModelScope)
|
}.onEach { _destNode.value = it }.launchIn(viewModelScope)
|
||||||
|
|
||||||
radioConfigRepository.deviceProfileFlow.onEach {
|
radioConfigRepository.deviceProfileFlow.onEach {
|
||||||
_currentDeviceProfile.value = it
|
_currentDeviceProfile.value = it
|
||||||
|
@ -110,6 +109,7 @@ class RadioConfigViewModel @Inject constructor(
|
||||||
val hasPaFan: Boolean
|
val hasPaFan: Boolean
|
||||||
get() = destNode.value?.user?.hwModel in setOf(
|
get() = destNode.value?.user?.hwModel in setOf(
|
||||||
null,
|
null,
|
||||||
|
MeshProtos.HardwareModel.UNRECOGNIZED,
|
||||||
MeshProtos.HardwareModel.UNSET,
|
MeshProtos.HardwareModel.UNSET,
|
||||||
MeshProtos.HardwareModel.BETAFPV_2400_TX,
|
MeshProtos.HardwareModel.BETAFPV_2400_TX,
|
||||||
MeshProtos.HardwareModel.RADIOMASTER_900_BANDIT_NANO,
|
MeshProtos.HardwareModel.RADIOMASTER_900_BANDIT_NANO,
|
||||||
|
@ -367,12 +367,12 @@ class RadioConfigViewModel @Inject constructor(
|
||||||
_deviceProfile.value = null
|
_deviceProfile.value = null
|
||||||
meshService?.beginEditSettings()
|
meshService?.beginEditSettings()
|
||||||
if (hasLongName() || hasShortName()) destNode.value?.user?.let {
|
if (hasLongName() || hasShortName()) destNode.value?.user?.let {
|
||||||
val user = it.copy(
|
val user = MeshProtos.User.newBuilder()
|
||||||
longName = if (hasLongName()) longName else it.longName,
|
.setLongName(if (hasLongName()) longName else it.longName)
|
||||||
shortName = if (hasShortName()) shortName else it.shortName,
|
.setShortName(if (hasShortName()) shortName else it.shortName)
|
||||||
hwModel = MeshProtos.HardwareModel.UNSET,
|
.setIsLicensed(it.isLicensed)
|
||||||
)
|
.build()
|
||||||
if (it != user) setOwner(user.toProto())
|
if (it != user) setOwner(user)
|
||||||
}
|
}
|
||||||
if (hasChannelUrl()) try {
|
if (hasChannelUrl()) try {
|
||||||
setChannels(channelUrl)
|
setChannels(channelUrl)
|
||||||
|
|
|
@ -1647,7 +1647,9 @@ class MeshService : Service(), Logging {
|
||||||
debug("Sending our position/time to=$idNum ${Position(position)}")
|
debug("Sending our position/time to=$idNum ${Position(position)}")
|
||||||
|
|
||||||
// Also update our own map for our nodeNum, by handling the packet just like packets from other users
|
// Also update our own map for our nodeNum, by handling the packet just like packets from other users
|
||||||
|
if (!localConfig.position.fixedPosition) {
|
||||||
handleReceivedPosition(mi.myNodeNum, position)
|
handleReceivedPosition(mi.myNodeNum, position)
|
||||||
|
}
|
||||||
|
|
||||||
sendToRadio(newMeshPacketTo(idNum).buildMeshPacket(
|
sendToRadio(newMeshPacketTo(idNum).buildMeshPacket(
|
||||||
channel = if (destNum == null) 0 else nodeDBbyNodeNum[destNum]?.channel ?: 0,
|
channel = if (destNum == null) 0 else nodeDBbyNodeNum[destNum]?.channel ?: 0,
|
||||||
|
@ -1952,7 +1954,9 @@ class MeshService : Service(), Logging {
|
||||||
removeFixedPosition = true
|
removeFixedPosition = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
handleReceivedPosition(destNum, pos)
|
updateNodeInfo(destNum) {
|
||||||
|
it.setPosition(pos, currentSecond())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun requestTraceroute(requestId: Int, destNum: Int) = toRemoteExceptions {
|
override fun requestTraceroute(requestId: Int, destNum: Int) = toRemoteExceptions {
|
||||||
|
|
|
@ -56,11 +56,11 @@ import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import com.geeksville.mesh.NodeInfo
|
|
||||||
import com.geeksville.mesh.Position
|
import com.geeksville.mesh.Position
|
||||||
import com.geeksville.mesh.R
|
import com.geeksville.mesh.R
|
||||||
import com.geeksville.mesh.android.Logging
|
import com.geeksville.mesh.android.Logging
|
||||||
import com.geeksville.mesh.config
|
import com.geeksville.mesh.config
|
||||||
|
import com.geeksville.mesh.database.entity.NodeEntity
|
||||||
import com.geeksville.mesh.model.Channel
|
import com.geeksville.mesh.model.Channel
|
||||||
import com.geeksville.mesh.model.RadioConfigViewModel
|
import com.geeksville.mesh.model.RadioConfigViewModel
|
||||||
import com.geeksville.mesh.moduleConfig
|
import com.geeksville.mesh.moduleConfig
|
||||||
|
@ -246,9 +246,10 @@ private fun MeshAppBar(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||||
@Composable
|
@Composable
|
||||||
fun RadioConfigNavHost(
|
fun RadioConfigNavHost(
|
||||||
node: NodeInfo?,
|
node: NodeEntity?,
|
||||||
viewModel: RadioConfigViewModel = hiltViewModel(),
|
viewModel: RadioConfigViewModel = hiltViewModel(),
|
||||||
navController: NavHostController = rememberNavController(),
|
navController: NavHostController = rememberNavController(),
|
||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
|
@ -413,13 +414,19 @@ fun RadioConfigNavHost(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(ConfigRoute.POSITION.name) {
|
composable(ConfigRoute.POSITION.name) {
|
||||||
|
val currentPosition = Position(
|
||||||
|
latitude = node?.latitude ?: 0.0,
|
||||||
|
longitude = node?.longitude ?: 0.0,
|
||||||
|
altitude = node?.position?.altitude ?: 0,
|
||||||
|
time = 1, // ignore time for fixed_position
|
||||||
|
)
|
||||||
PositionConfigItemList(
|
PositionConfigItemList(
|
||||||
location = node?.position ?: Position(0.0, 0.0, 0),
|
location = currentPosition,
|
||||||
positionConfig = radioConfigState.radioConfig.position,
|
positionConfig = radioConfigState.radioConfig.position,
|
||||||
enabled = connected,
|
enabled = connected,
|
||||||
onSaveClicked = { locationInput, positionInput ->
|
onSaveClicked = { locationInput, positionInput ->
|
||||||
if (positionInput.fixedPosition) {
|
if (positionInput.fixedPosition) {
|
||||||
if (locationInput != node?.position) {
|
if (locationInput != currentPosition) {
|
||||||
viewModel.setFixedPosition(destNum, locationInput)
|
viewModel.setFixedPosition(destNum, locationInput)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Ładowanie…
Reference in New Issue