fix: position handling when `fixed_position` is enabled

closes #1265
pull/1274/head
andrekir 2024-09-28 08:09:42 -03:00
rodzic 3c22272d23
commit 96a69b7398
3 zmienionych plików z 30 dodań i 19 usunięć

Wyświetl plik

@ -13,13 +13,12 @@ import com.geeksville.mesh.IMeshService
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.ModuleConfigProtos
import com.geeksville.mesh.MyNodeInfo
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Portnums
import com.geeksville.mesh.Position
import com.geeksville.mesh.R
import com.geeksville.mesh.android.Logging
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.moduleConfig
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
@ -70,12 +69,12 @@ class RadioConfigViewModel @Inject constructor(
val connectionState get() = radioConfigRepository.connectionState
private val _destNum = MutableStateFlow<Int?>(null)
private val _destNode = MutableStateFlow<NodeInfo?>(null)
val destNode: StateFlow<NodeInfo?> get() = _destNode
private val _destNode = MutableStateFlow<NodeEntity?>(null)
val destNode: StateFlow<NodeEntity?> get() = _destNode
/**
* Sets the destination [NodeInfo] used in Radio Configuration.
* @param num Destination nodeNum (or null for our local [NodeInfo]).
* Sets the destination [NodeEntity] used in Radio Configuration.
* @param num Destination nodeNum (or null for our local [NodeEntity]).
*/
fun setDestNum(num: Int?) {
_destNum.value = num
@ -91,7 +90,7 @@ class RadioConfigViewModel @Inject constructor(
init {
combine(_destNum, radioConfigRepository.nodeDBbyNum) { destNum, nodes ->
nodes[destNum] ?: nodes.values.firstOrNull()
}.onEach { _destNode.value = it?.toNodeInfo() }.launchIn(viewModelScope)
}.onEach { _destNode.value = it }.launchIn(viewModelScope)
radioConfigRepository.deviceProfileFlow.onEach {
_currentDeviceProfile.value = it
@ -110,6 +109,7 @@ class RadioConfigViewModel @Inject constructor(
val hasPaFan: Boolean
get() = destNode.value?.user?.hwModel in setOf(
null,
MeshProtos.HardwareModel.UNRECOGNIZED,
MeshProtos.HardwareModel.UNSET,
MeshProtos.HardwareModel.BETAFPV_2400_TX,
MeshProtos.HardwareModel.RADIOMASTER_900_BANDIT_NANO,
@ -367,12 +367,12 @@ class RadioConfigViewModel @Inject constructor(
_deviceProfile.value = null
meshService?.beginEditSettings()
if (hasLongName() || hasShortName()) destNode.value?.user?.let {
val user = it.copy(
longName = if (hasLongName()) longName else it.longName,
shortName = if (hasShortName()) shortName else it.shortName,
hwModel = MeshProtos.HardwareModel.UNSET,
)
if (it != user) setOwner(user.toProto())
val user = MeshProtos.User.newBuilder()
.setLongName(if (hasLongName()) longName else it.longName)
.setShortName(if (hasShortName()) shortName else it.shortName)
.setIsLicensed(it.isLicensed)
.build()
if (it != user) setOwner(user)
}
if (hasChannelUrl()) try {
setChannels(channelUrl)

Wyświetl plik

@ -1647,7 +1647,9 @@ class MeshService : Service(), Logging {
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
handleReceivedPosition(mi.myNodeNum, position)
if (!localConfig.position.fixedPosition) {
handleReceivedPosition(mi.myNodeNum, position)
}
sendToRadio(newMeshPacketTo(idNum).buildMeshPacket(
channel = if (destNum == null) 0 else nodeDBbyNodeNum[destNum]?.channel ?: 0,
@ -1952,7 +1954,9 @@ class MeshService : Service(), Logging {
removeFixedPosition = true
}
})
handleReceivedPosition(destNum, pos)
updateNodeInfo(destNum) {
it.setPosition(pos, currentSecond())
}
}
override fun requestTraceroute(requestId: Int, destNum: Int) = toRemoteExceptions {

Wyświetl plik

@ -56,11 +56,11 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Position
import com.geeksville.mesh.R
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.config
import com.geeksville.mesh.database.entity.NodeEntity
import com.geeksville.mesh.model.Channel
import com.geeksville.mesh.model.RadioConfigViewModel
import com.geeksville.mesh.moduleConfig
@ -246,9 +246,10 @@ private fun MeshAppBar(
)
}
@Suppress("LongMethod", "CyclomaticComplexMethod")
@Composable
fun RadioConfigNavHost(
node: NodeInfo?,
node: NodeEntity?,
viewModel: RadioConfigViewModel = hiltViewModel(),
navController: NavHostController = rememberNavController(),
modifier: Modifier,
@ -413,13 +414,19 @@ fun RadioConfigNavHost(
)
}
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(
location = node?.position ?: Position(0.0, 0.0, 0),
location = currentPosition,
positionConfig = radioConfigState.radioConfig.position,
enabled = connected,
onSaveClicked = { locationInput, positionInput ->
if (positionInput.fixedPosition) {
if (locationInput != node?.position) {
if (locationInput != currentPosition) {
viewModel.setFixedPosition(destNum, locationInput)
}
} else {