androidbikekit
掃描電控

掃描

開始掃描

  • 如三秒以上未掃描到的裝置,則會自動移除,不會出現於掃描結果中
  • 當未停止掃描,再次呼叫此方法,則會捕獲例外 BluetoothThrowableScan("Scanning already in progress")

掃描接果型態:List<BluetoothPeripheral>

FarmlandBikeKit
    .sleipnir()
    .startScanDevices(context)
    .subscribe(
        { bluetoothPeripheralsList ->
            // 取得掃描結果
        },
        {
            // Observable Error
        }
    )

停止掃描

FarmLandBikeKit.sleipnir().stopScanDevices()

BluetoothPeripheral 結構定義

class BluetoothPeripheral(val bluetoothDevice: BluetoothDevice) {
    var deviceName: String?
    var localName: String = ""
    var uuid: String?
    val address: String
    val services: List<BluetoothService>
    var rssi: Float? = null
    var sharedAdvertisementData: Map<AdvertisementDataRetrievalKeys, Any>? = null
    var deviceService: List<BluetoothService> = listOf()
}

與電控連線時,必須使用 BluetoothPeripheral 的實例。所以在 UI 介面中,選擇欲連線的電控時,應將其暫存起來。