Data tranfering improvement
This commit is contained in:
@@ -9,4 +9,5 @@ data class BluetoothUiState(
|
||||
val errorMessage: String? = null,
|
||||
val scannedBluetoothDevices: List<BluetoothDevice> = emptyList(),
|
||||
val pairedBluetoothDevices: List<BluetoothDevice> = emptyList(),
|
||||
val deviceState: DeviceState? = null
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.helible.pilot.dataclasses
|
||||
|
||||
|
||||
data class ChangedDeviceStatus(
|
||||
val status: DeviceStatus
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.helible.pilot.dataclasses
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class DeviceState(
|
||||
val status: DeviceStatus = DeviceStatus.ChargeRequired,
|
||||
@Json(name = "charge") val batteryCharge: Int = 10,
|
||||
val flightHeight: Float = 0f,
|
||||
@Json(name = "y") val yaw: Float = 0f,
|
||||
@Json(name = "p") val pitch: Float = 0f,
|
||||
@Json(name = "r") val roll: Float = 0f,
|
||||
@Json(name = "zIn") val zInertial: Float = 0f,
|
||||
)
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.helible.pilot.dataclasses
|
||||
|
||||
enum class DeviceStatus {
|
||||
Idle,
|
||||
IsPreparingForTakeoff,
|
||||
IsFlying,
|
||||
IsBoarding,
|
||||
IsImuCalibration,
|
||||
ChargeRequired;
|
||||
|
||||
fun description(): String {
|
||||
return when (this) {
|
||||
Idle -> "Готово к работе"
|
||||
IsPreparingForTakeoff -> "Подготовка к полёту"
|
||||
IsFlying -> "В полёте"
|
||||
IsBoarding -> "Посадка"
|
||||
IsImuCalibration -> "Калибровка..."
|
||||
ChargeRequired -> "Аккумулятор разряжен"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.helible.pilot.dataclasses
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.JsonDataException
|
||||
import com.squareup.moshi.ToJson
|
||||
|
||||
class DeviceStatusJsonAdapter {
|
||||
@FromJson
|
||||
fun fromJson(deviceStatus: String): DeviceStatus {
|
||||
try {
|
||||
val index: UInt = deviceStatus.toUInt()
|
||||
return DeviceStatus.values()[index.toInt()]
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
throw JsonDataException("Impossible conversation from String to DeviceStatus")
|
||||
}
|
||||
}
|
||||
|
||||
@ToJson
|
||||
fun toJson(deviceStatus: DeviceStatus): String {
|
||||
return DeviceStatus.values().indexOf(deviceStatus).toString()
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.helible.pilot.dataclasses
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class RotorsSpeedMessage(val r1: Short, val r2: Short, val r3: Short)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class EmergStopMessage(val emergStop: Boolean)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class AlarmStateMessage(val isAlarmOn: Boolean)
|
||||
Reference in New Issue
Block a user