Exemplo n.º 1
0
 public void Disconnect()
 {
     Debug.Log("Disconnect");
     _peripheralList = null;
     BluetoothLEHardwareInterface.DisconnectAll();
     StateChange(States.Disconnect);
 }
Exemplo n.º 2
0
 private void OnApplicationQuit()
 {
     BluetoothLEHardwareInterface.StopScan();
     BluetoothLEHardwareInterface.DisconnectAll();
     BluetoothLEHardwareInterface.DeInitialize(() =>
     {
         Debug.Log("Bluetooth has shut down on application quit.");
     });
 }
Exemplo n.º 3
0
 public override void DisconnectDevice()
 {
     //need to disconnect and deinitialize and then finish it otherwise it won't be disconnected the right way.
     BluetoothLEHardwareInterface.DisconnectAll();
     ConnectDevice(adressFinal);
     BluetoothLEHardwareInterface.DeInitialize(() => { });
     BluetoothLEHardwareInterface.FinishDeInitialize();
     isConnected = false;
 }
Exemplo n.º 4
0
    IEnumerator disConnectProcess()
    {
        BluetoothLEHardwareInterface.StopScan();
        yield return(new WaitForSeconds(0.2f));

        BluetoothLEHardwareInterface.DisconnectAll();
        yield return(new WaitForSeconds(0.2f));

        BluetoothLEHardwareInterface.DeInitialize(() => {
            SetState(BtStates.None);
        });
    }
Exemplo n.º 5
0
 public void DisconnectAllDice()
 {
     foreach (var die in GetComponentsInChildren <Die>())
     {
         die.Disconnect();
     }
     BluetoothLEHardwareInterface.DisconnectAll();
     if (virtualBluetooth != null)
     {
         virtualBluetooth.DisconnectAll();
     }
 }
Exemplo n.º 6
0
    private void ConnectDevice(string addr)
    {
        BluetoothLEHardwareInterface.ConnectToPeripheral(addr, (address) =>
        {
        },
                                                         (address, serviceUUID) =>
        {
        },
                                                         (address, serviceUUID, characteristicUUID) =>
        {
            if (IsEqual(serviceUUID, _serviceUUID))
            {
                _connectedID = address;
                isConnected  = true;

                if (IsEqual(characteristicUUID, _readCharacteristicUUID))
                {
                    _readFound = true;
                }
                if (IsEqual(characteristicUUID, _writeCharacteristicUUID))
                {
                    _writeFound = true;
                }
                adressFinal = addr;
                Debug.Log("BLE Spiro Connected");
                BluetoothLEHardwareInterface.StopScan();
            }
        }, (address) =>
        {
            // this will get called when the device disconnects
            // be aware that this will also get called when the disconnect
            // is called above. both methods get call for the same action
            // this is for backwards compatibility
            Debug.Log("Connection Lost");
            isConnected = false;
            //we first need to disconnect and deinitialize before we can connect again to the Air next otherwise we can't reconnect.
            BluetoothLEHardwareInterface.DisconnectAll();
            BluetoothLEHardwareInterface.DeInitialize(() => { });
            BluetoothLEHardwareInterface.FinishDeInitialize();
            DeviceManager.Instance.MakeSpiroControllerNull();
        });
    }
Exemplo n.º 7
0
    private void OnDestroy()
    {
        Debug.Log("BluetoothManager - OnDestroy()");

        if (Instance == this)
        {
            try
            {
                BluetoothLEHardwareInterface.StopScan();
                BluetoothLEHardwareInterface.DisconnectAll();
                BluetoothLEHardwareInterface.DeInitialize(() => {
                    Debug.Log("Bluetooth has shut down on destroy.");
                });
            }
            catch (Exception e)
            {
                Debug.Log("Bluetooth has already shut down: " + e.Message);
            }
        }
    }