improve beacon ui
This commit is contained in:
parent
2e16c81a5e
commit
e7e8823c9a
|
|
@ -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 мин."
|
||||
)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -365,7 +365,7 @@ class BleRepositoryImpl @Inject constructor(
|
|||
return Result.failure(it)
|
||||
}
|
||||
|
||||
delay(1_000)
|
||||
delay(2_000)
|
||||
|
||||
val dataResult = readCharacteristic(
|
||||
device = record.device,
|
||||
|
|
|
|||
|
|
@ -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) ==
|
||||
|
|
|
|||
Loading…
Reference in New Issue