mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d38d71f00 | ||
|
|
b773242b02 | ||
|
|
d94701f564 |
No files matched your search
@@ -36,6 +36,8 @@ class SteamControllerBle(private val context: Context, router: InputRouter? = nu
|
|||||||
private var lizardOffSent = false
|
private var lizardOffSent = false
|
||||||
private var reportedNone = false
|
private var reportedNone = false
|
||||||
private var discoveries = 0
|
private var discoveries = 0
|
||||||
|
private var subscribed = false
|
||||||
|
private var linkChecks = 0
|
||||||
private var outputSequence = 0L
|
private var outputSequence = 0L
|
||||||
private var outputWritePending = false
|
private var outputWritePending = false
|
||||||
private var featureRead = 0L
|
private var featureRead = 0L
|
||||||
@@ -94,7 +96,7 @@ class SteamControllerBle(private val context: Context, router: InputRouter? = nu
|
|||||||
}
|
}
|
||||||
val adapter = (context.getSystemService(Context.BLUETOOTH_SERVICE) as? BluetoothManager)?.adapter
|
val adapter = (context.getSystemService(Context.BLUETOOTH_SERVICE) as? BluetoothManager)?.adapter
|
||||||
val bonded = runCatching { adapter?.takeIf(BluetoothAdapter::isEnabled)?.bondedDevices }
|
val bonded = runCatching { adapter?.takeIf(BluetoothAdapter::isEnabled)?.bondedDevices }
|
||||||
.onFailure { Log.w(TAG, "paired devices unreadable", it) }
|
.onFailure { if (!reportedNone) Log.w(TAG, "paired devices unreadable", it) }
|
||||||
.getOrNull()
|
.getOrNull()
|
||||||
val device = bonded?.firstOrNull(::isSteamController)
|
val device = bonded?.firstOrNull(::isSteamController)
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
@@ -114,6 +116,8 @@ class SteamControllerBle(private val context: Context, router: InputRouter? = nu
|
|||||||
val g = gatt ?: return
|
val g = gatt ?: return
|
||||||
gatt = null
|
gatt = null
|
||||||
discoveries = 0
|
discoveries = 0
|
||||||
|
subscribed = false
|
||||||
|
linkChecks = 0
|
||||||
input = null
|
input = null
|
||||||
lizardOffSent = false
|
lizardOffSent = false
|
||||||
outputWritePending = false
|
outputWritePending = false
|
||||||
@@ -162,26 +166,18 @@ class SteamControllerBle(private val context: Context, router: InputRouter? = nu
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDescriptorWrite(g: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) {
|
override fun onDescriptorWrite(g: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) {
|
||||||
withSlot {
|
if (g !== gatt || descriptor.characteristic.uuid != input) return
|
||||||
if (g !== gatt || descriptor.characteristic.uuid != input) return
|
if (status == BluetoothGatt.GATT_SUCCESS) onSubscribed("status $status")
|
||||||
Log.i(TAG, "subscribed to report 0x%02x (status %d)".format(reportId, status))
|
else Log.w(TAG, "report 0x%02x subscription failed (status %d)".format(reportId, status))
|
||||||
connected = status == BluetoothGatt.GATT_SUCCESS
|
|
||||||
FakeInputWriter.setTritonConnected(SLOT, connected)
|
|
||||||
}
|
|
||||||
listener?.invoke()
|
|
||||||
if (connected) {
|
|
||||||
refreshLizardMode()
|
|
||||||
pollOutput()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCharacteristicWrite(g: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
override fun onCharacteristicWrite(g: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
||||||
if (g !== gatt) return
|
if (g !== gatt) return
|
||||||
if (characteristic.uuid == REPORT && !lizardOffSent) {
|
if (status != BluetoothGatt.GATT_SUCCESS) {
|
||||||
lizardOffSent = true
|
|
||||||
Log.i(TAG, "lizard mode off (status $status)")
|
|
||||||
} else if (status != BluetoothGatt.GATT_SUCCESS) {
|
|
||||||
Log.w(TAG, "output report write failed for ${characteristic.uuid} (status $status)")
|
Log.w(TAG, "output report write failed for ${characteristic.uuid} (status $status)")
|
||||||
|
} else if (characteristic.uuid == REPORT && !lizardOffSent) {
|
||||||
|
lizardOffSent = true
|
||||||
|
Log.i(TAG, "lizard mode off")
|
||||||
}
|
}
|
||||||
outputWritePending = false
|
outputWritePending = false
|
||||||
writeNextOutput()
|
writeNextOutput()
|
||||||
@@ -241,11 +237,40 @@ class SteamControllerBle(private val context: Context, router: InputRouter? = nu
|
|||||||
Log.i(TAG, "found Triton haptic reports: ${outputReports.keys.sorted().joinToString { "0x%02x".format(it) }}")
|
Log.i(TAG, "found Triton haptic reports: ${outputReports.keys.sorted().joinToString { "0x%02x".format(it) }}")
|
||||||
input = chr.uuid
|
input = chr.uuid
|
||||||
g.setCharacteristicNotification(chr, true)
|
g.setCharacteristicNotification(chr, true)
|
||||||
val cccd = chr.getDescriptor(CCCD) ?: return disconnect("state report cannot notify")
|
watchLink(g, chr)
|
||||||
@Suppress("DEPRECATION")
|
}
|
||||||
cccd.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
|
|
||||||
@Suppress("DEPRECATION")
|
private fun watchLink(g: BluetoothGatt, chr: BluetoothGattCharacteristic) {
|
||||||
g.writeDescriptor(cccd)
|
if (g !== gatt || lizardOffSent) return
|
||||||
|
if (linkChecks++ == LINK_CHECKS) {
|
||||||
|
disconnect(if (subscribed) "lizard mode off never acknowledged" else "report 0x%02x never subscribed".format(reportId))
|
||||||
|
if (running) handler.postDelayed(::connect, RETRY_MS)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!subscribed) {
|
||||||
|
val cccd = chr.getDescriptor(CCCD) ?: return disconnect("state report cannot notify")
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
cccd.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
if (!g.writeDescriptor(cccd)) Log.w(TAG, "report 0x%02x subscription refused (attempt %d)".format(reportId, linkChecks))
|
||||||
|
}
|
||||||
|
handler.postDelayed({ watchLink(g, chr) }, LINK_CHECK_MS)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onSubscribed(how: String) {
|
||||||
|
var fresh = false
|
||||||
|
withSlot {
|
||||||
|
if (subscribed || gatt == null) return@withSlot
|
||||||
|
subscribed = true
|
||||||
|
fresh = true
|
||||||
|
Log.i(TAG, "subscribed to report 0x%02x (%s)".format(reportId, how))
|
||||||
|
connected = true
|
||||||
|
FakeInputWriter.setTritonConnected(SLOT, true)
|
||||||
|
}
|
||||||
|
if (!fresh) return
|
||||||
|
listener?.invoke()
|
||||||
|
refreshLizardMode()
|
||||||
|
pollOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshCache(g: BluetoothGatt) {
|
private fun refreshCache(g: BluetoothGatt) {
|
||||||
@@ -261,11 +286,14 @@ class SteamControllerBle(private val context: Context, router: InputRouter? = nu
|
|||||||
handler.postDelayed(::refreshLizardMode, LIZARD_REFRESH_MS)
|
handler.postDelayed(::refreshLizardMode, LIZARD_REFRESH_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onState(data: ByteArray) = withSlot {
|
private fun onState(data: ByteArray) {
|
||||||
if (data.size < STATE_BYTES) return@withSlot
|
withSlot {
|
||||||
val timing = InputTiming.begin()
|
if (data.size < STATE_BYTES) return
|
||||||
FakeInputWriter.writeTritonState(SLOT, reportId, routedInput?.route(data) ?: data)
|
val timing = InputTiming.begin()
|
||||||
InputTiming.end(timing)
|
FakeInputWriter.writeTritonState(SLOT, reportId, routedInput?.route(data) ?: data)
|
||||||
|
InputTiming.end(timing)
|
||||||
|
}
|
||||||
|
if (!subscribed) onSubscribed("input before the subscription reply")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun release() = synchronized(inputLock) {
|
private fun release() = synchronized(inputLock) {
|
||||||
@@ -357,6 +385,8 @@ class SteamControllerBle(private val context: Context, router: InputRouter? = nu
|
|||||||
private const val SLOT = 0
|
private const val SLOT = 0
|
||||||
private const val RETRY_MS = 5_000L
|
private const val RETRY_MS = 5_000L
|
||||||
private const val LIZARD_REFRESH_MS = 3_000L
|
private const val LIZARD_REFRESH_MS = 3_000L
|
||||||
|
private const val LINK_CHECK_MS = 1_000L
|
||||||
|
private const val LINK_CHECKS = 3
|
||||||
private const val OUTPUT_POLL_MS = 4L
|
private const val OUTPUT_POLL_MS = 4L
|
||||||
private const val OUTPUT_RETRY_MS = 10L
|
private const val OUTPUT_RETRY_MS = 10L
|
||||||
private const val FEATURE_BYTES = 62
|
private const val FEATURE_BYTES = 62
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.bluetooth.BluetoothGatt
|
|||||||
import android.bluetooth.BluetoothGattCallback
|
import android.bluetooth.BluetoothGattCallback
|
||||||
import android.bluetooth.BluetoothGattCharacteristic
|
import android.bluetooth.BluetoothGattCharacteristic
|
||||||
import android.bluetooth.BluetoothGattDescriptor
|
import android.bluetooth.BluetoothGattDescriptor
|
||||||
|
import android.bluetooth.BluetoothGattService
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
@@ -18,11 +19,13 @@ import org.robolectric.annotation.Config
|
|||||||
import org.robolectric.annotation.Implementation
|
import org.robolectric.annotation.Implementation
|
||||||
import org.robolectric.annotation.Implements
|
import org.robolectric.annotation.Implements
|
||||||
import org.robolectric.util.ReflectionHelpers
|
import org.robolectric.util.ReflectionHelpers
|
||||||
|
import org.robolectric.shadow.api.Shadow
|
||||||
import org.robolectric.shadows.ShadowBluetoothGatt
|
import org.robolectric.shadows.ShadowBluetoothGatt
|
||||||
|
import java.time.Duration
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(sdk = [34], manifest = Config.NONE, shadows = [SteamControllerBleTest.Writer::class])
|
@Config(sdk = [34], manifest = Config.NONE, shadows = [SteamControllerBleTest.Writer::class, SteamControllerBleTest.BusyGatt::class])
|
||||||
class SteamControllerBleTest {
|
class SteamControllerBleTest {
|
||||||
private val keys = ArrayList<Pair<Int, Boolean>>()
|
private val keys = ArrayList<Pair<Int, Boolean>>()
|
||||||
private val router = InputRouter(object : InputOutput {
|
private val router = InputRouter(object : InputOutput {
|
||||||
@@ -153,15 +156,144 @@ class SteamControllerBleTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test fun unansweredSubscriptionDropsTheLink() {
|
||||||
|
val link = ValveLink()
|
||||||
|
link.start()
|
||||||
|
assertEquals(1, link.shadow.descriptorWrites)
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(2_500))
|
||||||
|
assertEquals(1, link.shadow.descriptorWrites)
|
||||||
|
assertEquals(2, link.shadow.refused)
|
||||||
|
assertSame(link.gatt, ReflectionHelpers.getField<Any?>(controller, "gatt"))
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(1_000))
|
||||||
|
assertNull(ReflectionHelpers.getField<Any?>(controller, "gatt"))
|
||||||
|
assertFalse(SteamControllerBle.connected)
|
||||||
|
assertEquals(0, link.shadow.lizardWrites)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun failedSubscriptionIsWrittenAgain() {
|
||||||
|
val link = ValveLink()
|
||||||
|
link.start()
|
||||||
|
link.answer(BluetoothGatt.GATT_FAILURE)
|
||||||
|
assertFalse(SteamControllerBle.connected)
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(1_500))
|
||||||
|
assertEquals(2, link.shadow.descriptorWrites)
|
||||||
|
link.answer()
|
||||||
|
assertTrue(SteamControllerBle.connected)
|
||||||
|
assertEquals(1, link.shadow.lizardWrites)
|
||||||
|
link.answer()
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(2_000))
|
||||||
|
assertEquals(2, link.shadow.descriptorWrites)
|
||||||
|
assertSame(link.gatt, ReflectionHelpers.getField<Any?>(controller, "gatt"))
|
||||||
|
assertTrue(SteamControllerBle.connected)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun inputBeforeTheSubscriptionReplyTurnsLizardModeOffOnceTheReplyArrives() {
|
||||||
|
val link = ValveLink()
|
||||||
|
link.start()
|
||||||
|
link.input()
|
||||||
|
assertTrue(SteamControllerBle.connected)
|
||||||
|
assertTrue(Writer.connections.last())
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(500))
|
||||||
|
assertEquals(0, link.shadow.lizardWrites)
|
||||||
|
link.answer()
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(20))
|
||||||
|
assertEquals(1, link.shadow.lizardWrites)
|
||||||
|
link.answer()
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(3_000))
|
||||||
|
assertEquals(1, link.shadow.descriptorWrites)
|
||||||
|
assertSame(link.gatt, ReflectionHelpers.getField<Any?>(controller, "gatt"))
|
||||||
|
assertTrue(SteamControllerBle.connected)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun inputWithoutALizardModeReplyDropsTheLink() {
|
||||||
|
val link = ValveLink()
|
||||||
|
link.start()
|
||||||
|
link.input()
|
||||||
|
assertTrue(SteamControllerBle.connected)
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(2_500))
|
||||||
|
assertEquals(1, link.shadow.descriptorWrites)
|
||||||
|
assertEquals(0, link.shadow.lizardWrites)
|
||||||
|
assertSame(link.gatt, ReflectionHelpers.getField<Any?>(controller, "gatt"))
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(1_000))
|
||||||
|
assertNull(ReflectionHelpers.getField<Any?>(controller, "gatt"))
|
||||||
|
assertFalse(SteamControllerBle.connected)
|
||||||
|
assertFalse(Writer.connections.last())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun failedLizardModeWriteDropsTheLink() {
|
||||||
|
val link = ValveLink()
|
||||||
|
link.start()
|
||||||
|
link.answer()
|
||||||
|
assertEquals(1, link.shadow.lizardWrites)
|
||||||
|
link.answer(BluetoothGatt.GATT_FAILURE)
|
||||||
|
link.input()
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(2_500))
|
||||||
|
assertSame(link.gatt, ReflectionHelpers.getField<Any?>(controller, "gatt"))
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(1_000))
|
||||||
|
assertNull(ReflectionHelpers.getField<Any?>(controller, "gatt"))
|
||||||
|
assertFalse(SteamControllerBle.connected)
|
||||||
|
assertFalse(Writer.connections.last())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun answeredSubscriptionStartsOneLizardModeRefresh() {
|
||||||
|
val link = ValveLink()
|
||||||
|
link.start()
|
||||||
|
link.answer()
|
||||||
|
assertTrue(SteamControllerBle.connected)
|
||||||
|
assertEquals(1, link.shadow.lizardWrites)
|
||||||
|
link.answer()
|
||||||
|
link.input()
|
||||||
|
assertEquals(1, link.shadow.lizardWrites)
|
||||||
|
shadowOf(handler.looper).idleFor(Duration.ofMillis(3_500))
|
||||||
|
assertEquals(1, link.shadow.descriptorWrites)
|
||||||
|
assertEquals(2, link.shadow.lizardWrites)
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class ValveLink {
|
||||||
|
val gatt: BluetoothGatt = ShadowBluetoothGatt.newInstance(
|
||||||
|
BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:11:22:33:44:66"))
|
||||||
|
val shadow = Shadow.extract<BusyGatt>(gatt)
|
||||||
|
private val characteristic = BluetoothGattCharacteristic(INPUT, BluetoothGattCharacteristic.PROPERTY_NOTIFY, 0).apply {
|
||||||
|
addDescriptor(BluetoothGattDescriptor(CCCD, 0))
|
||||||
|
}
|
||||||
|
private val callback = ReflectionHelpers.getField<BluetoothGattCallback>(controller, "callback")
|
||||||
|
|
||||||
|
init {
|
||||||
|
val service = BluetoothGattService(SERVICE, BluetoothGattService.SERVICE_TYPE_PRIMARY)
|
||||||
|
service.addCharacteristic(characteristic)
|
||||||
|
service.addCharacteristic(BluetoothGattCharacteristic(REPORT,
|
||||||
|
BluetoothGattCharacteristic.PROPERTY_WRITE or BluetoothGattCharacteristic.PROPERTY_READ, 0))
|
||||||
|
shadow.addDiscoverableService(service)
|
||||||
|
shadow.setGattCallback(object : BluetoothGattCallback() {})
|
||||||
|
gatt.discoverServices()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun start() {
|
||||||
|
ReflectionHelpers.setField(controller, "gatt", gatt)
|
||||||
|
callback.onMtuChanged(gatt, 517, BluetoothGatt.GATT_SUCCESS)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun input() = callback.onCharacteristicChanged(gatt, characteristic, ByteArray(45))
|
||||||
|
|
||||||
|
fun answer(status: Int = BluetoothGatt.GATT_SUCCESS) {
|
||||||
|
val op = shadow.pending
|
||||||
|
shadow.pending = null
|
||||||
|
when (op) {
|
||||||
|
is BluetoothGattDescriptor -> callback.onDescriptorWrite(gatt, op, status)
|
||||||
|
is BluetoothGattCharacteristic -> callback.onCharacteristicWrite(gatt, op, status)
|
||||||
|
else -> fail("no write is waiting for a reply")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun subscribe(target: SteamControllerBle) {
|
private fun subscribe(target: SteamControllerBle) {
|
||||||
val device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:11:22:33:44:55")
|
val device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:11:22:33:44:55")
|
||||||
val gatt = ShadowBluetoothGatt.newInstance(device)
|
val gatt = ShadowBluetoothGatt.newInstance(device)
|
||||||
val input = UUID.fromString("100F6C7A-1735-4313-B402-38567131E5F3")
|
val characteristic = BluetoothGattCharacteristic(INPUT, BluetoothGattCharacteristic.PROPERTY_NOTIFY, 0)
|
||||||
val characteristic = BluetoothGattCharacteristic(input, BluetoothGattCharacteristic.PROPERTY_NOTIFY, 0)
|
val descriptor = BluetoothGattDescriptor(CCCD, 0)
|
||||||
val descriptor = BluetoothGattDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"), 0)
|
|
||||||
characteristic.addDescriptor(descriptor)
|
characteristic.addDescriptor(descriptor)
|
||||||
ReflectionHelpers.setField(target, "gatt", gatt)
|
ReflectionHelpers.setField(target, "gatt", gatt)
|
||||||
ReflectionHelpers.setField(target, "input", input)
|
ReflectionHelpers.setField(target, "input", INPUT)
|
||||||
ReflectionHelpers.setField(target, "reportId", 0x45)
|
ReflectionHelpers.setField(target, "reportId", 0x45)
|
||||||
ReflectionHelpers.getField<BluetoothGattCallback>(target, "callback")
|
ReflectionHelpers.getField<BluetoothGattCallback>(target, "callback")
|
||||||
.onDescriptorWrite(gatt, descriptor, BluetoothGatt.GATT_SUCCESS)
|
.onDescriptorWrite(gatt, descriptor, BluetoothGatt.GATT_SUCCESS)
|
||||||
@@ -170,6 +302,46 @@ class SteamControllerBleTest {
|
|||||||
private fun state(bytes: ByteArray, target: SteamControllerBle = controller) = ReflectionHelpers.callInstanceMethod<Unit>(target, "onState",
|
private fun state(bytes: ByteArray, target: SteamControllerBle = controller) = ReflectionHelpers.callInstanceMethod<Unit>(target, "onState",
|
||||||
ReflectionHelpers.ClassParameter.from(ByteArray::class.java, bytes))
|
ReflectionHelpers.ClassParameter.from(ByteArray::class.java, bytes))
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
val SERVICE: UUID = UUID.fromString("100F6C32-1735-4313-B402-38567131E5F3")
|
||||||
|
val INPUT: UUID = UUID.fromString("100F6C7A-1735-4313-B402-38567131E5F3")
|
||||||
|
val REPORT: UUID = UUID.fromString("100F6C34-1735-4313-B402-38567131E5F3")
|
||||||
|
val CCCD: UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implements(BluetoothGatt::class)
|
||||||
|
class BusyGatt : ShadowBluetoothGatt() {
|
||||||
|
var pending: Any? = null
|
||||||
|
var descriptorWrites = 0
|
||||||
|
var lizardWrites = 0
|
||||||
|
var refused = 0
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
override fun writeDescriptor(descriptor: BluetoothGattDescriptor): Boolean {
|
||||||
|
if (!accept(descriptor)) return false
|
||||||
|
descriptorWrites++
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
override fun writeCharacteristic(characteristic: BluetoothGattCharacteristic): Boolean {
|
||||||
|
if (!accept(characteristic)) return false
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val value = characteristic.value
|
||||||
|
if (characteristic.uuid == REPORT && value[0] == 0x87.toByte() && value[2] == 9.toByte()) lizardWrites++
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun accept(op: Any): Boolean {
|
||||||
|
if (pending != null) {
|
||||||
|
refused++
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
pending = op
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Implements(FakeInputWriter::class)
|
@Implements(FakeInputWriter::class)
|
||||||
class Writer {
|
class Writer {
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in new issue
Block a user