/// <summary> /// Initiates a bluetooth scan /// </summary> public bool BeginScanForDice(System.Action <IDie> onDieDiscovered, System.Action <IDie, int, byte[]> onCustomAdvertisingData) { if (_state != State.Idle) { Debug.LogError("Central not ready to start scanning, state: " + _state); return(false); } Debug.Log("start scan"); // Begin scanning _state = State.Scanning; // Notify of all the already known advertising dice foreach (var die in _dice.Values) { if (die.state == Die.State.Advertising) { die.onCustomAdvertisingData = onCustomAdvertisingData; onDieDiscovered?.Invoke(die); } } BluetoothLEHardwareInterface.ScanForPeripheralsWithServices( new string[] { serviceGUID }, (a, n) => OnDeviceDiscovered(a, n, onDieDiscovered, onCustomAdvertisingData), OnDeviceAdvertisingInfo, false, false); return(true); }
/// <summary> /// Initiates a bluetooth scan /// </summary> public void BeginScanForDice() { if (_state != State.Idle) { Debug.LogError("Die Manager not ready to start scanning"); return; } if (dieCreationFunc == null) { Debug.LogError("Die Manager - No die creation factory registered"); return; } // Begin scanning _state = State.Scanning; // Notify of all the already known advertising dice foreach (var die in _dice.Values) { if (die.state == Die.State.Advertising) { onDieDiscovered?.Invoke(die.die); } } BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(new string[] { serviceGUID }, OnDeviceDiscovered, null, false, true); }
public void OnScan() { if (_scanning) { BluetoothLEHardwareInterface.StopScan(); TextScanButton.text = "Start Scan"; _scanning = false; } else { RemovePeripherals(); // the first callback will only get called the first time this device is seen // this is because it gets added to a list in the BluetoothDeviceScript // after that only the second callback will get called and only if there is // advertising data available BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { AddPeripheral(name, address); }, (address, name, rssi, advertisingInfo) => { if (advertisingInfo != null) { BluetoothLEHardwareInterface.Log(string.Format("Device: {0} RSSI: {1} Data Length: {2} Bytes: {3}", name, rssi, advertisingInfo.Length, BytesToString(advertisingInfo))); } }); TextScanButton.text = "Stop Scan"; _scanning = true; } }
public void StartDeviceScan() { if (_scanning) { BluetoothLEHardwareInterface.Log("Stop scanning for peripherals"); BluetoothLEHardwareInterface.StopScan(); _scanning = false; } if (Connected) { BluetoothLEHardwareInterface.Log("Disconnect current peripheral"); DisconnectDevice(_connectedDevice); } // the first callback will only get called the first time this device is seen // this is because it gets added to a list in the BluetoothDeviceScript // after that only the second callback will get called and only if there is // advertising data available BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(serviceIds, (address, name) => { BluetoothLEHardwareInterface.Log("Found Device"); AddPeripheral(name, address); StopDeviceScan(); ConnectToDevice(new HRMDevice(name, address)); }, (address, name, rssi, advertisingInfo) => { }); _scanning = true; }
void scanForDevices() { char bar = ' '; switch (_scanCount % 4) { case 0: bar = '|'; break; case 1: bar = '/'; break; case 2: bar = '-'; break; case 3: bar = '\\'; break; } bluetoothStatus.text = "Scanning... [" + bar + "]"; _scanCount++; BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { if (name.Contains(DeviceName)) { BluetoothLEHardwareInterface.StopScan(); bluetoothStatus.text = "Found device!"; _state = States.Connect; _JDY16 = address; _found = true; } }, null, false, false); }
public void ScanForPeripheralsWithServices( string[] serviceUUIDs, Action <string, string> action ) { BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(serviceUUIDs, action); }
void StartScan() { EventDispatcher.SendEvent(eBT_CONNECTION_STATUS, "Ищем устройство."); int tryCount = 0; BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, null, (address, deviceName, rssi, bytes) => { tryCount++; if (deviceName.Contains(DeviceName)) { BluetoothLEHardwareInterface.StopScan(); deviceAddress = address; SetState(BtStates.Connect, 0.5f); } else if (tryCount == 20) { EventDispatcher.SendEvent(eBT_CONNECTION_STATUS, "Ищем устройство. \n Возможно контроллер зеркал отключил свой модуль bluetoth по истечению таймера — выключите и включите зажигание."); } else if (tryCount > 50) { BluetoothLEHardwareInterface.StopScan(); Debug.Log("Scan failed. Service Does not found"); SetState(BtStates.ConnectingError, 0.3f); } }, false); }
void Scan(DeviceName[] _supportedDevices) { Debug.Log("Start scanning..."); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, null, (deviceID, name, rssi, adInfo) => { for (int i = 0; i < _supportedDevices.Length; ++i) { for (int j = 0; j < m_deviceNames[_supportedDevices[i]].Length; ++j) { string targetName = m_deviceNames[_supportedDevices[i]][j]; // deviceID: 安卓上是 MAC 地址,iOS 上是某一串不明代码 // adInfo: 广播数据,第 2-7 字节是 MAC 地址 if (name.Equals(targetName)) { Debug.Log("Found: " + targetName); BluetoothLEHardwareInterface.StopScan(); m_device = GetDeviceScript(_supportedDevices[i]); m_device.SetAppInfo(m_userID, m_appID, m_appName, m_appDescription); m_device.m_deviceID = deviceID; #if UNITY_IPHONE m_device.m_MAC = GeekplayCommon.BytesToHexString(adInfo, "").Substring(4, 12); #elif UNITY_ANDROID m_device.m_MAC = deviceID.Replace(":", ""); #endif return; } } } }); }
public void scan() { BTLog = "Starting scan \n"; BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { addPeripheral(address, name); }, (address, name, rssi, advertisingInfo) => {; }); }
void Start() { Debug.Log("Bluetooth Initializing..."); BluetoothDeviceScript receiver = BluetoothLEHardwareInterface.Initialize(true, false, () => { Debug.Log("Bluetooth Initialized."); Debug.Log("Start scanning..."); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, null, (deviceID, name, rssi, adInfo) => { // deviceID: 安卓上是 MAC 地址,iOS 上是某一串不明代码 // adInfo: 广播数据,第 2-7 字节是 MAC 地址 if (("R-ARCHER" == name) || ("GU-ARCHER" == name)) { Debug.Log("Found: " + name); //BluetoothLEHardwareInterface.StopScan(); GeekplayDevice device = GetDeviceScript(name); device.SetAppInfo("", "", "", ""); device.m_deviceID = deviceID; device.m_MAC = deviceID.Replace(":", ""); deviceList.Add(device); if (typeof(GeekplayHunter) == device.GetType()) { ((GeekplayHunter)device).Initialize(BowDraw, BowShoot); } else if (typeof(GeekplayDragonbone) == device.GetType()) { ((GeekplayDragonbone)device).Initialize(BowDraw, BowShoot); } } }); }, null); }
/// <summary> /// 搜索蓝牙设备 /// </summary> public void ScanBluetooth() { Show("开始搜索蓝牙设备... ..."); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (bleAddress, name) => { AddPeripheral(name, bleAddress); }, (address, name, rssi, advertisingInfo) => { }); }
void scan() { // the first callback will only get called the first time this device is seen // this is because it gets added to a list in the BluetoothDeviceScript // after that only the second callback will get called and only if there is // advertising data available txtDebug.text += ("Starting scan \r\n"); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { AddPeripheral(name, address); }, (address, name, rssi, advertisingInfo) => { }); }
public void OnScanClick() { BluetoothLEHardwareInterface.Initialize(true, false, () => { FoundDeviceListScript.DeviceAddressList = new List <DeviceObject> (); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { FoundDeviceListScript.DeviceAddressList.Add(new DeviceObject(address, name)); }, null); }, (error) => { BluetoothLEHardwareInterface.Log("BLE Error: " + error); }); }
// Update is called once per frame void Update() { if (_timeout > 0f) { _timeout -= Time.deltaTime; if (_timeout <= 0f) { if (_startScan) { _startScan = false; _timeout = _startScanTimeout; BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, null, (address, name, rssi, bytes) => { BluetoothLEHardwareInterface.Log("item scanned: " + address); if (_scannedItems.ContainsKey(address)) { var scannedItem = _scannedItems[address]; scannedItem.TextRSSIValue.text = rssi.ToString(); BluetoothLEHardwareInterface.Log("already in list " + rssi.ToString()); } else { BluetoothLEHardwareInterface.Log("item new: " + address); var newItem = Instantiate(ScannedItemPrefab); if (newItem != null) { BluetoothLEHardwareInterface.Log("item created: " + address); newItem.transform.parent = transform; newItem.transform.localScale = Vector3.one; var scannedItem = newItem.GetComponent <ScannedItemScript> (); if (scannedItem != null) { BluetoothLEHardwareInterface.Log("item set: " + address); scannedItem.TextAddressValue.text = address; scannedItem.TextNameValue.text = name; scannedItem.TextRSSIValue.text = rssi.ToString(); _scannedItems[address] = scannedItem; } } } }, true); } else { BluetoothLEHardwareInterface.StopScan(); _startScan = true; _timeout = _startScanDelay; } } } }
public void OnScanClick() { num_devices = 0; FoundDeviceListScript.DeviceAddressList = new List <DeviceObject>(); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { if (name == "SmartInsole") { FoundDeviceListScript.DeviceAddressList.Add(new DeviceObject(address, name)); num_devices++; } }, null); }
/// <summary> /// 蓝牙初始化成功,开始扫描蓝牙设备, /// 第一个参数表示是否根据UUID来搜索指定蓝牙设备,null表示搜索所有蓝牙设备 /// </summary> public void ScanBluetooth() { //第一次回调只会在第一次看到此设备时被调用 //这是因为它被添加到BluetoothDeviceScript中的列表 //之后只有第二次回调才会被调用,并且只有在 //广告数据时才会被调用 Debug.Log("Starting scan \r\n"); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { AddPeripheral(name, address); }, (address, name, rssi, advertisingInfo) => { }); }
public void Scan() { if (!BluetoothLE.scanning) { this.Clear(); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, new Action <string, string>(this.Found), null, false); BluetoothLE.scanning = true; if (this.debugOutput) { Debug.Log("BluetoothLE Scan called"); } } }
void Update() { if (CurState == States.Error) { return; } if (CurState == States.Scan) { UpdateState(States.Scanning); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { DiscoverPeripheral(name, address); }, (address, name, rssi, bytes) => { DiscoverPeripheral(name, address); }, false); } else if (CurState == States.Scanning) { // Just wait, the scan callbacks will keep finding new peripherals. } else if (CurState == States.Connected) { // We have a 2seconds time for the device to get ready: ConnectTimer += Time.deltaTime; if (ConnectTimer > 2.0f) { float throttle = Mathf.Max(LeftJoystick.Vertical * 255.0f, 0.0f); float yaw = Mathf.Clamp(LeftJoystick.Horizontal * 127.0f, -127.0f, 127.0f); float pitch = Mathf.Clamp((RightJoystick.Vertical * 127.0f) + PitchTrimUI.value, -127.0f, 127.0f); float roll = Mathf.Clamp((RightJoystick.Horizontal * 127.0f) + RollTrimUI.value, -127.0f, 127.0f); SendTimer += Time.deltaTime; if (SendTimer > SendCommandsDelay) { SendTimer = 0.0f; UInt32 packedCommands = PackCommands((int)throttle, (int)yaw, (int)pitch, (int)roll); SendValue(packedCommands, CommandsServiceUID, PackedCharacteristicUID); } //RetrieveTelemetry(); //QuadViewer.eulerAngles = new Vector3(CurRoll * Mathf.Rad2Deg, 0.0f, CurPitch * Mathf.Rad2Deg); } } else { } }
private void SearchForTargetDevice() { BluetoothLEHardwareInterface.Log("Scanning for " + DeviceName); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { if (name.Contains(DeviceName)) { BluetoothLEHardwareInterface.StopScan(); deviceAddress = address; SetState(States.Connect, 0.5f); } }); }
private void ReScan() { if (isCentral) { BluetoothLEHardwareInterface.StopScan(); RemovePeripherals(); MyDebug.LogGreen("Start ReScaning!"); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(new string[] { BluetoothController.Instance.ServiceUUID }, (address, name) => { AddPeripheral(address, name); }); } }
public void ScanStart(System.Action onFinished) { // the first callback will only get called the first time this device is seen // this is because it gets added to a list in the BluetoothDeviceScript // after that only the second callback will get called and only if there is // advertising data available BluetoothLEHardwareInterface.Log("M-BLE: Scan Start"); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { AddPeripheral(name, address); }, (address, name, rssi, advertisingInfo) => { }); StateChange(States.Scan); connectWait = onFinished; }
/// <summary> /// /// </summary> /// <param name="serviceUUID"></param> /// <param name="action"></param> /// <param name="actionAdvertisingInfo"></param> public static void InitBluetooth_IOS(string[] serviceUUID, Action <string, string> action, Action <string, string, int, byte[]> actionAdvertisingInfo = null) { //初始化蓝牙 BluetoothLEHardwareInterface.Initialize(true, false, delegate { Debug.Log("蓝牙初始化成功!"); //当蓝牙初始化成功后,开始搜索蓝牙设备 BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(serviceUUID, action, actionAdvertisingInfo); }, delegate(string errorInfo) { Debug.Log("蓝牙初始化失败:" + errorInfo); //todo:执行打开手机蓝牙的操作 }); }
public void OnScan() { // the first callback will only get called the first time this device is seen // this is because it gets added to a list in the BluetoothDeviceScript // after that only the second callback will get called and only if there is // advertising data available BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { // Detect only urband devices if (name.Contains("Urband")) { AddPeripheral(name, address); } }, (address, name, rssi, advertisingInfo) => { }); }
private void Start() { BluetoothLEHardwareInterface.Initialize(true, false, () => { FoundDeviceListScript.DeviceAddressList = new List <DeviceObject>(); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { if (name == "SmartInsole") { FoundDeviceListScript.DeviceAddressList.Add(new DeviceObject(address, name)); num_devices++; } }, null); }, (error) => { BluetoothLEHardwareInterface.Log("BLE Error: " + error); }); }
void ExecScanDevice() { /*if (m_ScanDeviceList != null) * { * * } * else*/ { m_ScanDeviceList = new List <string>(); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { // if your device does not advertise the rssi and manufacturer specific data // then you must use this callback because the next callback only gets called // if you have manufacturer specific data //DebugLog("ScanDevice:" + name); if (name.Contains(DeviceName)) { if (m_ScanDeviceList.IndexOf(address) < 0) { DebugLog("AddDevice:" + name + "," + address); m_ScanDeviceList.Add(address); } // BluetoothLEHardwareInterface.StopScan(); // found a device with the name we want // this example does not deal with finding more than one //m_DeviceAddress = address; //SetMode(eMode.Connect); } }, (address, name, rssi, advertisingInfo) => { if (advertisingInfo != null) { BluetoothLEHardwareInterface.Log(string.Format("Device: {0} RSSI: {1} Data Length: {2} Bytes: {3}", name, rssi, advertisingInfo.Length, BytesToString(advertisingInfo))); } }, false); } }
public void BeginScanForDice(System.Action <Die> foundDieCallback) { if (_state == CentralState.Idle) { // Destroy any die that is not currently connected! foreach (var die in GetComponentsInChildren <Die>()) { if (!die.connected) { DestroyDie(die); } } System.Action <string, string> dieDiscovered = (address, name) => { if (!diceList.Any(dc => dc.address == address)) { var die = CreateDie(name, address); if (foundDieCallback != null) { foundDieCallback(die); } if (onDieDiscovered != null) { onDieDiscovered(die); } } }; _state = CentralState.Scanning; var services = new string[] { serviceGUID }; BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(services, dieDiscovered, null, false, false); // Also notify virtual dice that we're trying to connect if (virtualBluetooth != null) { virtualBluetooth.ScanForPeripheralsWithServices(services, dieDiscovered, null, false, false); } } else { Debug.LogError("Central is not ready to scan, current state is " + _state); } }
//This function is used to scan and find possible sensors to connect to public void ToScanPeripherals() { Sup.text = "Scanning..."; BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(UUIDs, (address, name) => //Start scanning for sensors { if (name.Contains(nameHelp)) //Looking for if the found name has the word 'Premius' in it { //Sensor1Button.SetActive(true); nameCount++; if (nameCount >= maxDevices) //If the amount of devices is equal to maximum specified, { ToStopScanning(); //stop scanning for more } } }, (address, name, rssi, advertisingInfo) => { }); }
//handles the scan button click public void OnScan() { if (_scanning) {//only scan once BluetoothLEHardwareInterface.StopScan(); ScanButton.GetComponentInChildren <Text>().text = "Scan"; _scanning = false; } else { if (_connectedAddress != null) {//disconnect from a connected device if there is any (only meant to connect to one device?) BluetoothLEHardwareInterface.DisconnectPeripheral(_connectedAddress, null); _connectedName = null; _connectedAddress = null; } theCircle.GetComponent <Renderer>().enabled = false; PanelScrollContents.gameObject.SetActive(true);// GetComponent<Renderer>().enabled = true; SendButton.interactable = false; RemovePeripherals(); DeviceServices.text = "scanning..."; // the first callback will only get called the first time this device is seen // this is because it gets added to a list in the BluetoothDeviceScript // after that only the second callback will get called and only if there is // advertising data available BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { AddPeripheral(name, address); }, (address, name, rssi, advertisingInfo) => { if (advertisingInfo != null) { BluetoothLEHardwareInterface.Log(string.Format("Device: {0} RSSI: {1} Data Length: {2} Bytes: {3}", name, rssi, advertisingInfo.Length, BytesToString(advertisingInfo))); } }); ScanButton.GetComponentInChildren <Text>().text = "Stop"; _scanning = true; } }
public void scan() { if (_scanning == true) { BluetoothLEHardwareInterface.StopScan(); _scanning = false; } else { BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { if (name.Contains(DeviceName)) { _deviceAddress = address; connectTo(_deviceAddress); } }, (address, name, rssi, advertisingInfo) => { }); _scanning = true; } }
public override void ConnectDevice() { BluetoothLEHardwareInterface.Initialize(true, false, () => { }, (error) => { } ); BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, (address, name) => { if (name.Trim().ToLower() == deviceToConnectTo.Trim().ToLower() || name.Trim().ToLower() == deviceToConnectTo2.Trim().ToLower()) { if (String.IsNullOrEmpty(PlayerPrefs.GetString("adress"))) { PlayerPrefs.SetString("adress", address); } } if (PlayerPrefs.GetString("adress") == address) { PlayerPrefs.SetString("adress", address); AddPeripheral(name, address); } }, (address, name, rssi, advertisingInfo) => { }); }