Skip to content

Commit

Permalink
Modify some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Mar 1, 2023
1 parent ba3810e commit e656ea9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ class BluetoothManager : BleCallback {
.toByteArray()
}

private fun getServiceDataMask(isManualPairingMode: Boolean): ByteArray {
val manualPairingMask = when(isManualPairingMode) {
private fun getServiceDataMask(isShortDiscriminator: Boolean): ByteArray {
val shortDiscriminatorMask = when(isShortDiscriminator) {
true -> 0x00 false -> 0xff
}
return intArrayOf(0xff, manualPairingMask, 0xff).map { it.toByte() }.toByteArray()
return intArrayOf(0xff, shortDiscriminatorMask, 0xff).map { it.toByte() }.toByteArray()
}

suspend fun getBluetoothDevice(context: Context, discriminator: Int): BluetoothDevice? {
return getBluetoothDevice(context, discriminator, false)
}

suspend fun getBluetoothDevice(context: Context, discriminator: Int, isManualPairingMode: Boolean): BluetoothDevice? {
suspend fun getBluetoothDevice(context: Context, discriminator: Int, isShortDiscriminator: Boolean): BluetoothDevice? {
if (! bluetoothAdapter.isEnabled) {
bluetoothAdapter.enable();
}
Expand Down Expand Up @@ -85,7 +85,7 @@ class BluetoothManager : BleCallback {
}

val serviceData = getServiceData(discriminator)
val serviceDataMask = getServiceDataMask(isManualPairingMode)
val serviceDataMask = getServiceDataMask(isShortDiscriminator)

val scanFilter =
ScanFilter.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ class BarcodeFragment : Fragment() {

private fun handleInputQrCode(qrCode: String) {
lateinit var payload: SetupPayload
var isManualPairingCode = false
var isShortDiscriminator = false
try {
payload = SetupPayloadParser().parseQrCode(qrCode)
} catch (ex: SetupPayloadException) {
try {
payload = SetupPayloadParser().parseManualEntryCode(qrCode)
isManualPairingCode = true
isShortDiscriminator = true
} catch (ex: Exception) {
Log.e(TAG, "Unrecognized Manual Pairing Code", ex)
Toast.makeText(requireContext(), "Unrecognized Manual Pairing Code", Toast.LENGTH_SHORT).show()
Expand All @@ -199,7 +199,7 @@ class BarcodeFragment : Fragment() {
Toast.makeText(requireContext(), "Unrecognized QR Code", Toast.LENGTH_SHORT).show()
}
FragmentUtil.getHost(this@BarcodeFragment, Callback::class.java)
?.onCHIPDeviceInfoReceived(CHIPDeviceInfo.fromSetupPayload(payload))
?.onCHIPDeviceInfoReceived(CHIPDeviceInfo.fromSetupPayload(payload, isShortDiscriminator))
}

private fun handleScannedQrCode(barcode: Barcode) {
Expand Down

0 comments on commit e656ea9

Please sign in to comment.