improve beacon ui
This commit is contained in:
parent
2e16c81a5e
commit
e7e8823c9a
|
|
@ -185,10 +185,14 @@ fun DisplayState(
|
||||||
Text(
|
Text(
|
||||||
text = "Интервал измерений"
|
text = "Интервал измерений"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val hours = ble.thermometerState.historyInterval / 1000 / 60 / 60
|
||||||
|
val minutes = (ble.thermometerState.historyInterval - ( hours * 1000 * 60 * 60 )) / 1000 / 60
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
color = MaterialTheme.colorScheme.secondary,
|
color = MaterialTheme.colorScheme.secondary,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
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)
|
return Result.failure(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(1_000)
|
delay(2_000)
|
||||||
|
|
||||||
val dataResult = readCharacteristic(
|
val dataResult = readCharacteristic(
|
||||||
device = record.device,
|
device = record.device,
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@ import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.app.ActivityCompat
|
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.Result
|
||||||
import llc.arma.ble.domain.common.BleException
|
import llc.arma.ble.domain.common.BleException
|
||||||
import llc.arma.ble.domain.model.Ble
|
import llc.arma.ble.domain.model.Ble
|
||||||
|
|
@ -69,10 +73,10 @@ class WriteThermometerCallback(
|
||||||
|
|
||||||
if(request.tx != null || request.saveHistory != null || request.historyInterval != null) {
|
if(request.tx != null || request.saveHistory != null || request.historyInterval != null) {
|
||||||
|
|
||||||
fun UInt.to4ByteArrayInBigEndian(): ByteArray =
|
fun UInt.to4ByteArrayInLittleEndian(): ByteArray =
|
||||||
(3 downTo 0).map {
|
(3 downTo 0).map {
|
||||||
(this shr (it * Byte.SIZE_BITS)).toByte()
|
(this shr (it * Byte.SIZE_BITS)).toByte()
|
||||||
}.reversed().toByteArray()
|
}.toByteArray()
|
||||||
|
|
||||||
var uuid: Pair<UUID, ByteArray>? = null
|
var uuid: Pair<UUID, ByteArray>? = null
|
||||||
|
|
||||||
|
|
@ -85,7 +89,7 @@ class WriteThermometerCallback(
|
||||||
Pair(
|
Pair(
|
||||||
intervalWriteUUID,
|
intervalWriteUUID,
|
||||||
mutableListOf<Byte>(3).apply {
|
mutableListOf<Byte>(3).apply {
|
||||||
addAll((it).toUInt().to4ByteArrayInBigEndian().toList())
|
addAll((it).toUInt().to4ByteArrayInLittleEndian().reversed().toList())
|
||||||
}.toByteArray()
|
}.toByteArray()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -203,18 +207,20 @@ class WriteThermometerCallback(
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BluetoothGatt.writeCharacteristic(
|
private fun BluetoothGatt.writeCharacteristic(
|
||||||
characteristic: BluetoothGattCharacteristic,
|
characteristic: BluetoothGattCharacteristic,
|
||||||
data: ByteArray
|
data: ByteArray
|
||||||
): Result<Unit, BleException> {
|
): Result<Unit, BleException> {
|
||||||
|
|
||||||
return if(checkPermission()){
|
return if(checkPermission()){
|
||||||
|
|
||||||
|
Log.d("write", data.asUByteArray().joinToString(" ") { it.toString(16).padStart(2, '0') })
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
writeCharacteristic(characteristic, data, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT)
|
writeCharacteristic(characteristic, data, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT)
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
characteristic.writeType
|
characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
|
||||||
characteristic.value = data
|
characteristic.value = data
|
||||||
writeCharacteristic(characteristic)
|
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) {
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
ActivityCompat.checkSelfPermission(app, Manifest.permission.BLUETOOTH_CONNECT) ==
|
ActivityCompat.checkSelfPermission(app, Manifest.permission.BLUETOOTH_CONNECT) ==
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue