public void ConnectTo(BluetoothPeripheralParams newPeripheralParams) { if (_peripheralParams.HasValue && newPeripheralParams.Equals(_peripheralParams.Value)) { logger.Warning("Already connected to this peripheral: " + newPeripheralParams); return; } #if UNITY_EDITOR _state = States.None; _connected = true; if (OnConnect != null) { OnConnect(); } return; #endif ResetState(() => { _peripheralParams = newPeripheralParams; BluetoothLEHardwareInterface.Initialize(true, false, () => { logger.DebugLog("Initialized bluetooth hardware interface."); SetState(States.Scan, 0.1f); }, (error) => { logger.Error("Error initializing bluetooth hardware interface: " + error); }); }); }
public void Initialize() { ButtonStartAdvertising.SetActive(false); Button1Highlight.SetActive(false); LEDHighlight.SetActive(false); Button1.SetActive(false); BluetoothLEHardwareInterface.Initialize(false, true, () => { BluetoothLEHardwareInterface.PeripheralName("Simulated RFduino"); BluetoothLEHardwareInterface.CreateCharacteristic("2221", BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyRead | BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyNotify, BluetoothLEHardwareInterface.CBAttributePermissions.CBAttributePermissionsReadable, null, 0, null); BluetoothLEHardwareInterface.CreateCharacteristic("2222", BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyWrite, BluetoothLEHardwareInterface.CBAttributePermissions.CBAttributePermissionsWriteable, null, 0, (characteristicUUID, bytes) => { if (bytes.Length > 0) { if (bytes[0] == 0x01) { LEDHighlight.SetActive(true); } else { LEDHighlight.SetActive(false); } } }); BluetoothLEHardwareInterface.CreateService("2220", true, (serviceUUID) => { ButtonStartAdvertising.SetActive(true); }); }, (error) => { }); }
private void Awake() { if (this.debugOutput) { Debug.Log("BluetoothLE.Awake called"); } if (BluetoothLE.created) { UnityEngine.Object.Destroy(base.gameObject); } else { UnityEngine.Object.DontDestroyOnLoad(this); BluetoothLE.bluetoothDeviceScript = BluetoothLEHardwareInterface.Initialize(true, false, new Action(this.Initialized), new Action <string>(this.Error)); if (null != BluetoothLE.bluetoothDeviceScript) { UnityEngine.Object.DontDestroyOnLoad(BluetoothLE.bluetoothDeviceScript); BluetoothLE.bluetoothDeviceScript.DisconnectedPeripheralAction = new Action <string>(this.disconnectedPeripheralAction); } BluetoothLE.created = true; if (this.debugOutput) { Debug.Log("BluetoothLE.Awake initialized"); } BluetoothLE.instance = this; } Array.Clear(this.status, 0, (int)this.status.Length); Array.Clear(this.config, 0, (int)this.config.Length); Array.Clear(this.mapping, 0, (int)this.mapping.Length); }
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); }
public void StartScan(Callback Success, Callback Error) { m_ScanAndConnectSuccess = Success; m_ScanAndConnectError = Error; m_ConnectCharacteristicUUID = new Dictionary <string, bool>(); for (int i = 0; i < CharacteristicUUID.Length; i++) { m_ConnectCharacteristicUUID[CharacteristicUUID[i]] = false; } //Reset(); BluetoothLEHardwareInterface.Initialize(true, false, () => { SetMode(eMode.ScanDevice); }, (error) => { BluetoothLEHardwareInterface.Log("Error during initialize: " + error); if (error == "Bluetooth LE Not Enabled") { BluetoothLEHardwareInterface.DeInitialize(() => { BluetoothLEHardwareInterface.BluetoothEnable(true); if (m_ScanAndConnectError != null) { m_ScanAndConnectError(); } }); } }); }
void Start() { DiscoveredPeripherals = new Dictionary <string, string>(); Input.location.Start(); if (!Application.isEditor) { bool initAsCentral = true; bool initAsPeripheral = false; BluetoothLEHardwareInterface.Initialize(initAsCentral, initAsPeripheral, () => { UpdateState(States.Scan); BluetoothLEHardwareInterface.BluetoothScanMode(BluetoothLEHardwareInterface.ScanMode.LowLatency); BluetoothLEHardwareInterface.BluetoothConnectionPriority(BluetoothLEHardwareInterface.ConnectionPriority.High); }, (error) => { Debug.Log(">>>>>>>>>>> [BLE ERROR] " + error); CurState = States.Error; HandleDisconnected(); }); } else { UpdateState(States.Connected); } }
/// <summary> /// Initializes the BLE service and returns it's result via callbacks. If successful, you can start scanning /// for devices /// </summary> public static void Initialize(Action onSuccess, Action <string> onError, bool asCentral = true, bool asPeripheral = false) { if (IsInitialized) { Debug.LogError("BLE Service is already initialized"); return; } IsInitialized = true; BluetoothLEHardwareInterface.Initialize(asCentral, asPeripheral, () => { IsInitialized = true; SetState(State.ReadyToScan); onSuccess?.Invoke(); }, error => { BluetoothLEHardwareInterface.Log("Error: " + error); onError?.Invoke(error); }); Observable .OnceApplicationQuit() .Subscribe(unit => { DeInitialize(); }); }
public void BLEStart(System.Action onFinished) { StateChange(States.None); BluetoothLEHardwareInterface.Initialize(true, false, () => { onFinished?.Invoke(); }, (error) => { } ); }
void Start() { #if !UNITY_EDITOR_OSX BluetoothLEHardwareInterface.Initialize(true, false, OnBluetoothInitComplete, OnError); #else OnBluetoothInitComplete(); #endif }
public void StartProcess() { Reset(); BluetoothLEHardwareInterface.Initialize(true, false, () => { SetState(States.Scan, 0.1f); }, (error) => { BluetoothLEHardwareInterface.Log("Error during initialize: " + error); }); }
public void ScanButtonClick() { //Initialize(as central, as peripheral, Action, error Action) BluetoothLEHardwareInterface.Initialize(true, false, () => { SetState(States.Scan, 0.1f); }, (error) => { BluetoothLEHardwareInterface.Log("Error during initialize: " + error); }); }
void StartProcess() { bluetoothStatus.text = "Initializing..."; Reset(); BluetoothLEHardwareInterface.Initialize(true, false, () => { bluetoothStatus.text = "Initialized"; _state = States.Scan; }, (error) => { BluetoothLEHardwareInterface.Log("Error: " + error); }); }
public IBluetoothDeviceScript Initialize( bool asCentral, bool asPeripheral, Action action, Action <string> errorAction ) { return(new BluetoothDeviceScriptWrapper(BluetoothLEHardwareInterface.Initialize(asCentral, asPeripheral, action, errorAction))); }
void BTinitialize() { if (iniStatus) { return; } BTLog = "Initialising bluetooth\n"; BluetoothLEHardwareInterface.Initialize(true, false, () => { iniStatus = true; }, (error) => { iniStatus = false; }); }
// start trying to find a connect to the robot private void StartBluetooth() { BluetoothLEHardwareInterface.Initialize(true, false, () => { }, (error) => { }); Invoke("scan", 1.0f); connecting = false; }
// Use this for initialization void Start() { btnSend.onClick.AddListener(sendData); uiPanel.SetActive(false); txtDebug.text += "\nInitialising bluetooth \n"; BluetoothLEHardwareInterface.Initialize(true, false, () => { }, (error) => { } ); Invoke("scan", 1f); }
void StartProcess() { Reset(); //Initialize(as central, as peripheral, Action, error Action) BluetoothLEHardwareInterface.Initialize(true, false, () => { SetState(States.Scan, 0.1f); }, (error) => { BluetoothLEHardwareInterface.Log("Error during initialize: " + error); }); }
void StartProcess() { Reset(); BluetoothLEHardwareInterface.Initialize(true, true, () => { }, (error) => { var message = "Error: " + error; StatusMessage = message; BluetoothLEHardwareInterface.Log(message); }); }
void Start() { BluetoothLEHardwareInterface.Initialize(asCentral: true, asPeripheral: false, action: () => { BluetoothLEHardwareInterface.Log("Initialized!"); }, errorAction: (error) => { BluetoothLEHardwareInterface.Log("ERROR: " + error + "\n"); }); Invoke("scan", 1); }
void StartProcess() { setStateText("Initializing..."); Reset(); BluetoothLEHardwareInterface.Initialize(true, false, () => { SetState(States.Scan, 0.1f); setStateText("Initialized"); }, (error) => { BluetoothLEHardwareInterface.Log("Error: " + error); }); }
public void InitializeBluetooth() { HM10_Status.text = "Initializing..."; Reset(); BluetoothLEHardwareInterface.Initialize(true, false, () => { SetState(States.Scan, 0.1f); HM10_Status.text = "Initialized"; }, (error) => { BluetoothLEHardwareInterface.Log("Error: " + error); }); }
void Bluetooth_Hazirla() { Status_Update("Bluetooth Başlatılıyor..."); BluetoothLEHardwareInterface.Initialize(true, false, () => { SetState(Bluetooth_States.Scan, 0.1f); Status_Update("Bluetooth başlatıldı."); }, (error) => { BluetoothLEHardwareInterface.Log("Error: " + error); }); }
// Use this for initialization void Start() { _scannedItems = new Dictionary <string, ScannedItemScript> (); BluetoothLEHardwareInterface.Initialize(true, false, () => { _timeout = Timeout; }, (error) => { BluetoothLEHardwareInterface.Log("Error: " + error); }); }
// Use this for initialization void Start() { _screenHeight = Camera.main.orthographicSize * 2f; _screenWidth = _screenHeight * Camera.main.aspect; //initialize itself as a central device bluetoothDeviceScript = BluetoothLEHardwareInterface.Initialize(true, false, null, null); //request the screen to not sleep Screen.sleepTimeout = SleepTimeout.NeverSleep; }
/// <summary> /// 初始化蓝牙 /// </summary> public void InitBluetooth() { BluetoothLEHardwareInterface.Initialize(true, false, delegate { Show("蓝牙初始化成功"); ScanBluetooth(); }, delegate(string errorInfo) { Show("蓝牙初始化失败"); }); }
// Use this for initialization public void Init(IErgDataCallbacks ergCallbacks) { this.ergCallbacks = ergCallbacks; // output.text = "Initializing bluetooth"; // byte[] data = new byte[] {69,9}; // output1.text = String.Format("{0}{1}",data[0],data[1]); bluetoothDeviceScript = BluetoothLEHardwareInterface.Initialize(true, false, () => { // output.text = "Diente azul inicializado"; ScanForPM5Ergs(); }, null); // initActions (); }
// Use this for initialization void Start() { averagingScript = GameObject.FindObjectOfType <AveragingScript>(); btnSend.onClick.AddListener(sendData); //uiPanel.SetActive(false); txtDebug.text = "Please wait.\nConnecting to sensors.\n"; BluetoothLEHardwareInterface.Initialize(true, false, () => { }, (error) => { } ); Invoke("scan", 1f); }
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); }); }
void StartProcess() { reset(); // Init as Central BLE device BlueScript = BluetoothLEHardwareInterface.Initialize(true, false, () => { SetState(machineState.Scan, 0.1f); state = State.Scanning; }, (error) => { state = State.Error; BluetoothLEHardwareInterface.Log("Error during initialize: " + error); }); BlueScript.DisconnectedPeripheralAction += Disconnected; }
void StartProcess() { Alert.Show("Bluetooth initialization will fail if Bluetooth settings are not initialized", null, false); BluetoothLEHardwareInterface.Initialize(true, false, () => { SetState(States.Scan, 0.2f); }, (error) => { // Console.Write ("蓝牙初始化失败: " + error + ",等待重试"); Alert.Show("Initialize Faild, Please open the Bluetooth", (_value) => { BluetoothLEHardwareInterface.DeInitialize(null); SetState(States.Init, 0.2f); }); }); }