improve beacon ui

This commit is contained in:
Vineyro 2023-05-12 16:04:10 +07:00
parent 2e16c81a5e
commit e7e8823c9a
3 changed files with 18 additions and 8 deletions

View File

@ -185,10 +185,14 @@ fun DisplayState(
Text(
text = "Интервал измерений"
)
val hours = ble.thermometerState.historyInterval / 1000 / 60 / 60
val minutes = (ble.thermometerState.historyInterval - ( hours * 1000 * 60 * 60 )) / 1000 / 60
Text(
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.bodyMedium,
text = "${ble.thermometerState.historyInterval / 1000 / 60 / 60} ч."
text = "$hours ч. $minutes мин."
)
}

View File

@ -365,7 +365,7 @@ class BleRepositoryImpl @Inject constructor(
return Result.failure(it)
}
delay(1_000)
delay(2_000)
val dataResult = readCharacteristic(
device = record.device,

View File

@ -10,6 +10,10 @@ import android.content.pm.PackageManager
import android.os.Build
import android.util.Log
import androidx.core.app.ActivityCompat
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import llc.arma.ble.domain.Result
import llc.arma.ble.domain.common.BleException
import llc.arma.ble.domain.model.Ble
@ -69,10 +73,10 @@ class WriteThermometerCallback(
if(request.tx != null || request.saveHistory != null || request.historyInterval != null) {
fun UInt.to4ByteArrayInBigEndian(): ByteArray =
fun UInt.to4ByteArrayInLittleEndian(): ByteArray =
(3 downTo 0).map {
(this shr (it * Byte.SIZE_BITS)).toByte()
}.reversed().toByteArray()
}.toByteArray()
var uuid: Pair<UUID, ByteArray>? = null
@ -85,7 +89,7 @@ class WriteThermometerCallback(
Pair(
intervalWriteUUID,
mutableListOf<Byte>(3).apply {
addAll((it).toUInt().to4ByteArrayInBigEndian().toList())
addAll((it).toUInt().to4ByteArrayInLittleEndian().reversed().toList())
}.toByteArray()
)
}
@ -203,18 +207,20 @@ class WriteThermometerCallback(
}
fun BluetoothGatt.writeCharacteristic(
private fun BluetoothGatt.writeCharacteristic(
characteristic: BluetoothGattCharacteristic,
data: ByteArray
): Result<Unit, BleException> {
return if(checkPermission()){
Log.d("write", data.asUByteArray().joinToString(" ") { it.toString(16).padStart(2, '0') })
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
writeCharacteristic(characteristic, data, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT)
}else{
characteristic.writeType
characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
characteristic.value = data
writeCharacteristic(characteristic)
}
@ -227,7 +233,7 @@ class WriteThermometerCallback(
}
fun checkPermission(): Boolean {
private fun checkPermission(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
ActivityCompat.checkSelfPermission(app, Manifest.permission.BLUETOOTH_CONNECT) ==