Fixed compile errors.
This commit is contained in:
parent
527ad08c28
commit
0827bdc7b4
3 changed files with 49 additions and 35 deletions
|
|
@ -25,14 +25,14 @@ enum class DeviceParameter {
|
||||||
data class Device(val uuid: UUID = UUID.randomUUID(),
|
data class Device(val uuid: UUID = UUID.randomUUID(),
|
||||||
var name: String = "Unknown Device",
|
var name: String = "Unknown Device",
|
||||||
var address: String = "00:00:00:00:00:00",
|
var address: String = "00:00:00:00:00:00",
|
||||||
var deviceType: UInt? = null,
|
var deviceType: Int? = null,
|
||||||
var deviceState: DeviceState? = null,
|
var deviceState: DeviceState? = null,
|
||||||
// All configurable variables
|
// All configurable variables
|
||||||
private var _playerID: UInt? = null,
|
private var _playerID: Int? = null,
|
||||||
private var _team: UInt? = null,
|
private var _team: Int? = null,
|
||||||
private var _secondaryColor: UInt? = null,
|
private var _secondaryColor: Int? = null,
|
||||||
private var _maxHealth: UInt? = null,
|
private var _maxHealth: Int? = null,
|
||||||
private var _specialWeapons: UInt? = null
|
private var _specialWeapons: Int? = null
|
||||||
) {
|
) {
|
||||||
var deviceConfigureState: DeviceConfigureState = DeviceConfigureState.Discovered
|
var deviceConfigureState: DeviceConfigureState = DeviceConfigureState.Discovered
|
||||||
private set
|
private set
|
||||||
|
|
@ -51,18 +51,18 @@ data class Device(val uuid: UUID = UUID.randomUUID(),
|
||||||
var lastEditTime: Long = 0L
|
var lastEditTime: Long = 0L
|
||||||
private set
|
private set
|
||||||
|
|
||||||
val playerID: UInt? get() = _playerID
|
val playerID: Int? get() = _playerID
|
||||||
val team: UInt? get() = _team
|
val team: Int? get() = _team
|
||||||
val secondaryColor: UInt? get() = _secondaryColor
|
val secondaryColor: Int? get() = _secondaryColor
|
||||||
val maxHealth: UInt? get() = _maxHealth
|
val maxHealth: Int? get() = _maxHealth
|
||||||
val specialWeapons: UInt? get() = _specialWeapons
|
val specialWeapons: Int? get() = _specialWeapons
|
||||||
|
|
||||||
fun deviceTypeName(): String {
|
fun deviceTypeName(): String {
|
||||||
return when(deviceType) {
|
return when(deviceType) {
|
||||||
0u -> "Little Boy BLuE"
|
0 -> "Little Boy BLuE"
|
||||||
1u -> "2020TPC"
|
1 -> "2020TPC"
|
||||||
2u -> "Mobile App"
|
2 -> "Mobile App"
|
||||||
3u -> "32ESPecial"
|
3 -> "32ESPecial"
|
||||||
else -> "Unknown Device Type"
|
else -> "Unknown Device Type"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,23 +84,23 @@ data class Device(val uuid: UUID = UUID.randomUUID(),
|
||||||
lastEditTime = System.nanoTime()
|
lastEditTime = System.nanoTime()
|
||||||
when (parameter) {
|
when (parameter) {
|
||||||
DeviceParameter.PLAYER_ID -> {
|
DeviceParameter.PLAYER_ID -> {
|
||||||
_playerID = value as UInt
|
_playerID = value as Int
|
||||||
dirtyPlayerID = true
|
dirtyPlayerID = true
|
||||||
}
|
}
|
||||||
DeviceParameter.TEAM -> {
|
DeviceParameter.TEAM -> {
|
||||||
_team = value as UInt
|
_team = value as Int
|
||||||
dirtyTeam = true
|
dirtyTeam = true
|
||||||
}
|
}
|
||||||
DeviceParameter.SECONDARY_COLOR -> {
|
DeviceParameter.SECONDARY_COLOR -> {
|
||||||
_secondaryColor = value as UInt
|
_secondaryColor = value as Int
|
||||||
dirtySecondaryColor = true
|
dirtySecondaryColor = true
|
||||||
}
|
}
|
||||||
DeviceParameter.MAX_HEALTH -> {
|
DeviceParameter.MAX_HEALTH -> {
|
||||||
_maxHealth = value as UInt
|
_maxHealth = value as Int
|
||||||
dirtyMaxHealth = true
|
dirtyMaxHealth = true
|
||||||
}
|
}
|
||||||
DeviceParameter.SPECIAL_WEAPONS -> {
|
DeviceParameter.SPECIAL_WEAPONS -> {
|
||||||
_specialWeapons = value as UInt
|
_specialWeapons = value as Int
|
||||||
dirtySpecialWeapons = true
|
dirtySpecialWeapons = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,9 +476,9 @@ fun SideBySideButtons(
|
||||||
@Composable
|
@Composable
|
||||||
fun DeviceCard(stateMachine: StateMachineViewModel, device: Device) {
|
fun DeviceCard(stateMachine: StateMachineViewModel, device: Device) {
|
||||||
val backgroundColor = when (device.team) {
|
val backgroundColor = when (device.team) {
|
||||||
0u -> Color.Magenta
|
0 -> Color.Magenta
|
||||||
1u -> Color.Red
|
1 -> Color.Red
|
||||||
2u -> Color.Blue
|
2 -> Color.Blue
|
||||||
else -> MaterialTheme.colorScheme.surface // Default color
|
else -> MaterialTheme.colorScheme.surface // Default color
|
||||||
}
|
}
|
||||||
Card(modifier = Modifier
|
Card(modifier = Modifier
|
||||||
|
|
|
||||||
|
|
@ -69,10 +69,12 @@ class StateMachineViewModel(context: Context) : ViewModel() {
|
||||||
when (packet) {
|
when (packet) {
|
||||||
is HelloPacket -> {
|
is HelloPacket -> {
|
||||||
// Log.d(TAG_BLE_SCAN, "HelloPacket scanned")
|
// Log.d(TAG_BLE_SCAN, "HelloPacket scanned")
|
||||||
scannedDevice.name = packet.deviceName
|
val scannedDevice = Device(
|
||||||
scannedDevice.deviceType = packet.deviceType
|
name = packet.deviceName,
|
||||||
scannedDevice.team = packet.teamId
|
address = result.device.address,
|
||||||
scannedDevice.deviceState = DeviceState.Configurable
|
deviceType = packet.deviceType,
|
||||||
|
deviceState = DeviceState.Configurable)
|
||||||
|
scannedDevice.setParameter(DeviceParameter.TEAM, packet.teamId)
|
||||||
addOrRefreshDevice(scannedDevice)
|
addOrRefreshDevice(scannedDevice)
|
||||||
}
|
}
|
||||||
is ConsolePacket -> {
|
is ConsolePacket -> {
|
||||||
|
|
@ -148,9 +150,13 @@ class StateMachineViewModel(context: Context) : ViewModel() {
|
||||||
var oldDevice = currentDevices[index]
|
var oldDevice = currentDevices[index]
|
||||||
newDevice.name = oldDevice.name
|
newDevice.name = oldDevice.name
|
||||||
newDevice.deviceType = oldDevice.deviceType ?: newDevice.deviceType
|
newDevice.deviceType = oldDevice.deviceType ?: newDevice.deviceType
|
||||||
newDevice.team = oldDevice.team ?: newDevice.team
|
|
||||||
newDevice.playerID = oldDevice.playerID ?: newDevice.playerID
|
|
||||||
newDevice.deviceState = newDevice.deviceState ?: oldDevice.deviceState
|
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
|
currentDevices[index] = newDevice
|
||||||
}
|
}
|
||||||
_devices.value = currentDevices
|
_devices.value = currentDevices
|
||||||
|
|
@ -165,18 +171,26 @@ class StateMachineViewModel(context: Context) : ViewModel() {
|
||||||
if (index == -1) { return }
|
if (index == -1) { return }
|
||||||
var oldDevice = currentDevices[index]
|
var oldDevice = currentDevices[index]
|
||||||
newDevice.deviceType = newDevice.deviceType ?: oldDevice.deviceType
|
newDevice.deviceType = newDevice.deviceType ?: oldDevice.deviceType
|
||||||
newDevice.team = newDevice.team ?: oldDevice.team
|
oldDevice.team?.let { teamValue ->
|
||||||
newDevice.playerID = newDevice.playerID ?: oldDevice.playerID
|
newDevice.setParameter(DeviceParameter.TEAM, teamValue)
|
||||||
|
}
|
||||||
|
oldDevice.playerID?.let { playerIDValue ->
|
||||||
|
newDevice.setParameter(DeviceParameter.PLAYER_ID, playerIDValue)
|
||||||
|
}
|
||||||
currentDevices[index] = newDevice
|
currentDevices[index] = newDevice
|
||||||
_devices.value = currentDevices
|
_devices.value = currentDevices
|
||||||
_allDevicesReady.value = allDevicesReady()
|
_allDevicesReady.value = allDevicesReady()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateDeviceTeam(deviceAddress: String, newTeam: Int) {
|
fun updateDeviceTeam(deviceAddress: String, newTeam: Int?) {
|
||||||
_devices.update { currentList ->
|
_devices.update { currentList ->
|
||||||
currentList.map { device ->
|
currentList.map { device ->
|
||||||
if (device.address == deviceAddress) {
|
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 {
|
} else {
|
||||||
device
|
device
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +201,7 @@ class StateMachineViewModel(context: Context) : ViewModel() {
|
||||||
|
|
||||||
fun cycleDeviceTeam(device: Device) {
|
fun cycleDeviceTeam(device: Device) {
|
||||||
Log.d("STATEMACHINE", "cycling device team")
|
Log.d("STATEMACHINE", "cycling device team")
|
||||||
var newTeam = device.team ?: -1
|
var newTeam: Int = (device.team?.toInt() ?: -1)
|
||||||
newTeam++
|
newTeam++
|
||||||
if (newTeam > 2) {
|
if (newTeam > 2) {
|
||||||
newTeam = 0
|
newTeam = 0
|
||||||
|
|
@ -244,7 +258,7 @@ class StateMachineViewModel(context: Context) : ViewModel() {
|
||||||
parameterPacketGenerator.generatePacket(
|
parameterPacketGenerator.generatePacket(
|
||||||
targetAddress = device.address,
|
targetAddress = device.address,
|
||||||
subtype = 2, // Request Parameter Change
|
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
|
key2 = 4, value2 = gameCfg.maxHealth // Key 2 is Max Health
|
||||||
)
|
)
|
||||||
// If a device for some reason can't be configured (e.g. missing address),
|
// If a device for some reason can't be configured (e.g. missing address),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue