Commit 8a3c18a0 authored by Andreas Schildbach's avatar Andreas Schildbach
Browse files

MoodFragment: Communicate to paired card10 rather than a hardcoded Bluetooth MAC.

parent eb035d0d
......@@ -31,6 +31,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import de.ccc.events.badge.card10.CARD10_SERVICE_UUID
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.ROCKETS_CHARACTERISTIC_UUID
......@@ -39,9 +40,7 @@ import java.util.concurrent.CountDownLatch
class MoodFragment : Fragment() {
// TODO pick from list of paired card10s, possibly present selection
private val REMOTE_DEVICE_BLUETOOTH_MAC = "CA:4D:10:44:02:03"
private val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
private lateinit var gatt: BluetoothGatt
private var rocketsCharacteristic: BluetoothGattCharacteristic? = null
private var writeLatch: CountDownLatch? = null
......@@ -72,8 +71,11 @@ class MoodFragment : Fragment() {
}
}
val remoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_BLUETOOTH_MAC)
gatt = remoteDevice.connectGatt(activity, false, callback)
val remoteDevices =
bluetoothAdapter.bondedDevices.filter { it.address.startsWith(CARD10_BLUETOOTH_MAC_PREFIX, true) }
if (remoteDevices.isEmpty())
activity!!.finish()
gatt = remoteDevices.get(0).connectGatt(activity, false, callback)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment