Exemplo n.º 1
0
    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();
                    }
                });
            }
        });
    }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        _scannedItems = new Dictionary <string, ScannedItemScript> ();

        BluetoothLEHardwareInterface.Initialize(true, false, () => {
            _timeout = Timeout;
        },
                                                (error) => {
            BluetoothLEHardwareInterface.Log("Error: " + error);

            if (error.Contains("Bluetooth LE Not Enabled"))
            {
                BluetoothLEHardwareInterface.BluetoothEnable(true);
            }
        });
    }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        _iBeaconItems = new Dictionary <string, iBeaconItemScript> ();

        BluetoothLEHardwareInterface.Initialize(true, false, () => {
            _timeout = _startScanDelay;

            BluetoothLEHardwareInterface.BluetoothScanMode(BluetoothLEHardwareInterface.ScanMode.LowLatency);
            BluetoothLEHardwareInterface.BluetoothConnectionPriority(BluetoothLEHardwareInterface.ConnectionPriority.High);
        },
                                                (error) => {
            BluetoothLEHardwareInterface.Log("Error: " + error);

            if (error.Contains("Bluetooth LE Not Enabled"))
            {
                BluetoothLEHardwareInterface.BluetoothEnable(true);
            }
        });
    }
    void Start()
    {
        BluetoothLEHardwareInterface.BluetoothEnable(true);
        id = GuiFrameID.BluetoothFrame;
        Init();
        delta                    = 0;
        scaning                  = false;
        curPatternID             = PatternID.Number;
        curOperandID             = OperandID.TwoNumbers;
        peripheralDict           = new Dictionary <string, string> ();
        digitDropdownOptionsList = new List <Dropdown.OptionData>(digitDropdown.options);

#if UNITY_ANDROID
        bluetoothPeripheralBtn.SetActive(false);
        bluetoothAndroidTip.SetActive(true);
#elif UNITY_IOS
        bluetoothPeripheralBtn.SetActive(true);
        bluetoothAndroidTip.SetActive(false);
#endif
    }
Exemplo n.º 5
0
    public void OnBluetoothFightFinish()
    {
        MyDebug.LogGreen("OnBluetoothFightFinish");
        if (isCentral)
        {
            MyDebug.LogGreen("OnBluetoothFightFinish:Central");
            BluetoothLEHardwareInterface.UnSubscribeCharacteristic(CurPeripheralInstance.address,
                                                                   ServiceUUID,
                                                                   ReadUUID,
                                                                   (characteristic) =>
            {
                MyDebug.LogGreen("UnSubscribeCharacteristic Success :" + characteristic);
            });

            BluetoothLEHardwareInterface.DisconnectPeripheral(CurPeripheralInstance.address,
                                                              (disconnectAddress) =>
            {
                MyDebug.LogGreen("DisconnectPeripheral Success:" + disconnectAddress);
            });
        }
        else
        {
            MyDebug.LogGreen("OnBluetoothFightFinish:Peripheral");
            BluetoothLEHardwareInterface.StopAdvertising(() =>
            {
                MyDebug.LogGreen("Stop Advertising!");
            });
        }

        BluetoothLEHardwareInterface.RemoveCharacteristics();
        BluetoothLEHardwareInterface.RemoveServices();

        BluetoothLEHardwareInterface.DeInitialize(() =>
        {
            MyDebug.LogGreen("DeInitialize Success!");
        });
        BluetoothLEHardwareInterface.BluetoothEnable(false);
    }