// ===========================================================================================================================================
        // ================================ Functions invoked when after a specific interaction with GUI elements ====================================
        // ===========================================================================================================================================
        // Function invoked during the onClick event of "ScanButton".
        public void ScanButtonFunction()
        {
            try
            {
                // List of available Devices.
                List <string> listOfDomains = new List <string>();
                if (BTHToggle.isOn)
                {
                    listOfDomains.Add("BTH");
                }
                if (BLEToggle.isOn)
                {
                    listOfDomains.Add("BLE");
                }

                PluxDevManager.GetDetectableDevicesUnity(listOfDomains);

                // Disable scan button.
                ScanButton.interactable = false;
            }
            catch (Exception e)
            {
                // Show info message.
                BluetoothInfoPanel.SetActive(true);

                // Hide object after 5 seconds.
                StartCoroutine(RemoveAfterSeconds(5, BluetoothInfoPanel));

                // Disable Drop-down.
                DeviceDropdown.interactable = false;
            }
        }
Example #2
0
        public void OneTimeSetup()
        {
            pluxManager = new PluxDeviceManager(ScanResults, ConnectionDone);

            if (string.IsNullOrEmpty(deviceMacAddr))
            {
                pluxManager.GetDetectableDevicesUnity(new List <string> {
                    "BTH", "BLE"
                });
            }
        }
        // ===========================================================================================================================================
        // ================================ Functions invoked when after a specific interaction with GUI elements ====================================
        // ===========================================================================================================================================
        // Function invoked during the onClick event of "ScanButton".
        public void ScanButtonFunction()
        {
            try
            {
                // List of available Devices.
                this.ListDevices = PluxDevManager.GetDetectableDevicesUnity("BTH");

                // Enable Dropdown if the list of devices is not empty.
                if (this.ListDevices.Count != 0)
                {
                    // Add the new options to the drop-down box included in our GUI.
                    //Create a List of new Dropdown options
                    List <string> dropDevices = new List <string>();

                    // Convert array to list format.
                    dropDevices.AddRange(this.ListDevices);

                    // A check into the list of devices.
                    dropDevices = dropDevices.GetRange(0, dropDevices.Count - 1);
                    for (int i = dropDevices.Count - 1; i >= 0; i--)
                    {
                        // Accept only strings containing "BTH" or "BLE" substrings "flagging" a PLUX Bluetooth device.
                        if (!dropDevices[i].Contains("BTH") && !dropDevices[i].Contains("BLE"))
                        {
                            dropDevices.RemoveAt(i);
                        }
                    }

                    // Raise an exception if none device was detected.
                    if (dropDevices.Count == 0)
                    {
                        throw new ArgumentException();
                    }

                    //Clear the old options of the Dropdown menu
                    DeviceDropdown.ClearOptions();

                    //Add the options created in the List above
                    DeviceDropdown.AddOptions(dropDevices);

                    // Enable drop-down and Connect button if a PLUX Device was detected .
                    DeviceDropdown.interactable = true;
                    ConnectButton.interactable  = true;

                    // Hide info message.
                    ConnectInfoPanel.SetActive(false);
                }
            }
            catch (Exception e)
            {
                if (e is ExecutionEngineException || e is ArgumentException)
                {
                    // Show info message.
                    ConnectInfoPanel.SetActive(true);

                    // Hide object after 5 seconds.
                    StartCoroutine(RemoveAfterSeconds(5, ConnectInfoPanel));

                    // Disable Drop-down.
                    DeviceDropdown.interactable = false;
                }
            }
        }