From 0827bdc7b4c9cbdc40691ad8e9e24ee3cc5a3388 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sun, 14 Sep 2025 14:41:12 -0500 Subject: [PATCH] Fixed compile errors. --- .../club/clubk/ktag/konfigurator/Device.kt | 40 +++++++++---------- .../clubk/ktag/konfigurator/MainActivity.kt | 6 +-- .../konfigurator/StateMachineViewModel.kt | 38 ++++++++++++------ 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/club/clubk/ktag/konfigurator/Device.kt b/app/src/main/java/club/clubk/ktag/konfigurator/Device.kt index e715e5f..2b953fe 100644 --- a/app/src/main/java/club/clubk/ktag/konfigurator/Device.kt +++ b/app/src/main/java/club/clubk/ktag/konfigurator/Device.kt @@ -25,14 +25,14 @@ enum class DeviceParameter { data class Device(val uuid: UUID = UUID.randomUUID(), var name: String = "Unknown Device", var address: String = "00:00:00:00:00:00", - var deviceType: UInt? = null, + var deviceType: Int? = null, var deviceState: DeviceState? = null, // All configurable variables - private var _playerID: UInt? = null, - private var _team: UInt? = null, - private var _secondaryColor: UInt? = null, - private var _maxHealth: UInt? = null, - private var _specialWeapons: UInt? = null + private var _playerID: Int? = null, + private var _team: Int? = null, + private var _secondaryColor: Int? = null, + private var _maxHealth: Int? = null, + private var _specialWeapons: Int? = null ) { var deviceConfigureState: DeviceConfigureState = DeviceConfigureState.Discovered private set @@ -51,18 +51,18 @@ data class Device(val uuid: UUID = UUID.randomUUID(), var lastEditTime: Long = 0L private set - val playerID: UInt? get() = _playerID - val team: UInt? get() = _team - val secondaryColor: UInt? get() = _secondaryColor - val maxHealth: UInt? get() = _maxHealth - val specialWeapons: UInt? get() = _specialWeapons + val playerID: Int? get() = _playerID + val team: Int? get() = _team + val secondaryColor: Int? get() = _secondaryColor + val maxHealth: Int? get() = _maxHealth + val specialWeapons: Int? get() = _specialWeapons fun deviceTypeName(): String { return when(deviceType) { - 0u -> "Little Boy BLuE" - 1u -> "2020TPC" - 2u -> "Mobile App" - 3u -> "32ESPecial" + 0 -> "Little Boy BLuE" + 1 -> "2020TPC" + 2 -> "Mobile App" + 3 -> "32ESPecial" else -> "Unknown Device Type" } } @@ -84,23 +84,23 @@ data class Device(val uuid: UUID = UUID.randomUUID(), lastEditTime = System.nanoTime() when (parameter) { DeviceParameter.PLAYER_ID -> { - _playerID = value as UInt + _playerID = value as Int dirtyPlayerID = true } DeviceParameter.TEAM -> { - _team = value as UInt + _team = value as Int dirtyTeam = true } DeviceParameter.SECONDARY_COLOR -> { - _secondaryColor = value as UInt + _secondaryColor = value as Int dirtySecondaryColor = true } DeviceParameter.MAX_HEALTH -> { - _maxHealth = value as UInt + _maxHealth = value as Int dirtyMaxHealth = true } DeviceParameter.SPECIAL_WEAPONS -> { - _specialWeapons = value as UInt + _specialWeapons = value as Int dirtySpecialWeapons = true } } diff --git a/app/src/main/java/club/clubk/ktag/konfigurator/MainActivity.kt b/app/src/main/java/club/clubk/ktag/konfigurator/MainActivity.kt index b0f0519..e714f6a 100644 --- a/app/src/main/java/club/clubk/ktag/konfigurator/MainActivity.kt +++ b/app/src/main/java/club/clubk/ktag/konfigurator/MainActivity.kt @@ -476,9 +476,9 @@ fun SideBySideButtons( @Composable fun DeviceCard(stateMachine: StateMachineViewModel, device: Device) { val backgroundColor = when (device.team) { - 0u -> Color.Magenta - 1u -> Color.Red - 2u -> Color.Blue + 0 -> Color.Magenta + 1 -> Color.Red + 2 -> Color.Blue else -> MaterialTheme.colorScheme.surface // Default color } Card(modifier = Modifier diff --git a/app/src/main/java/club/clubk/ktag/konfigurator/StateMachineViewModel.kt b/app/src/main/java/club/clubk/ktag/konfigurator/StateMachineViewModel.kt index aeedd61..267dbf5 100644 --- a/app/src/main/java/club/clubk/ktag/konfigurator/StateMachineViewModel.kt +++ b/app/src/main/java/club/clubk/ktag/konfigurator/StateMachineViewModel.kt @@ -69,10 +69,12 @@ class StateMachineViewModel(context: Context) : ViewModel() { when (packet) { is HelloPacket -> { // Log.d(TAG_BLE_SCAN, "HelloPacket scanned") - scannedDevice.name = packet.deviceName - scannedDevice.deviceType = packet.deviceType - scannedDevice.team = packet.teamId - scannedDevice.deviceState = DeviceState.Configurable + val scannedDevice = Device( + name = packet.deviceName, + address = result.device.address, + deviceType = packet.deviceType, + deviceState = DeviceState.Configurable) + scannedDevice.setParameter(DeviceParameter.TEAM, packet.teamId) addOrRefreshDevice(scannedDevice) } is ConsolePacket -> { @@ -148,9 +150,13 @@ class StateMachineViewModel(context: Context) : ViewModel() { var oldDevice = currentDevices[index] newDevice.name = oldDevice.name newDevice.deviceType = oldDevice.deviceType ?: newDevice.deviceType - newDevice.team = oldDevice.team ?: newDevice.team - newDevice.playerID = oldDevice.playerID ?: newDevice.playerID newDevice.deviceState = newDevice.deviceState ?: oldDevice.deviceState + oldDevice.team?.let { teamValue -> + newDevice.setParameter(DeviceParameter.TEAM, teamValue) + } + oldDevice.playerID?.let { playerIDValue -> + newDevice.setParameter(DeviceParameter.PLAYER_ID, playerIDValue) + } currentDevices[index] = newDevice } _devices.value = currentDevices @@ -165,18 +171,26 @@ class StateMachineViewModel(context: Context) : ViewModel() { if (index == -1) { return } var oldDevice = currentDevices[index] newDevice.deviceType = newDevice.deviceType ?: oldDevice.deviceType - newDevice.team = newDevice.team ?: oldDevice.team - newDevice.playerID = newDevice.playerID ?: oldDevice.playerID + oldDevice.team?.let { teamValue -> + newDevice.setParameter(DeviceParameter.TEAM, teamValue) + } + oldDevice.playerID?.let { playerIDValue -> + newDevice.setParameter(DeviceParameter.PLAYER_ID, playerIDValue) + } currentDevices[index] = newDevice _devices.value = currentDevices _allDevicesReady.value = allDevicesReady() } - fun updateDeviceTeam(deviceAddress: String, newTeam: Int) { + fun updateDeviceTeam(deviceAddress: String, newTeam: Int?) { _devices.update { currentList -> currentList.map { device -> if (device.address == deviceAddress) { - device.copy(team = newTeam) // Creates a new Device instance + val updatedDevice = device.copy() + if (newTeam != null) { + updatedDevice.setParameter(DeviceParameter.TEAM, newTeam) + } + updatedDevice // Return the modified device } else { device } @@ -187,7 +201,7 @@ class StateMachineViewModel(context: Context) : ViewModel() { fun cycleDeviceTeam(device: Device) { Log.d("STATEMACHINE", "cycling device team") - var newTeam = device.team ?: -1 + var newTeam: Int = (device.team?.toInt() ?: -1) newTeam++ if (newTeam > 2) { newTeam = 0 @@ -244,7 +258,7 @@ class StateMachineViewModel(context: Context) : ViewModel() { parameterPacketGenerator.generatePacket( targetAddress = device.address, subtype = 2, // Request Parameter Change - key1 = 1, value1 = teamId, // Key 1 is Team ID + key1 = 1, value1 = teamId.toInt(), // Key 1 is Team ID key2 = 4, value2 = gameCfg.maxHealth // Key 2 is Max Health ) // If a device for some reason can't be configured (e.g. missing address),