예제 #1
0
        private void ShowConnectDialog(bool autoConnect)
        {
            L2CAPAPI.RadioMode radioMode = L2CAPAPI.RadioMode.Off;
            L2CAPAPI.BthGetMode(out radioMode);

            if (radioMode != L2CAPAPI.RadioMode.Discoverable)
            {
                if (autoConnect || (DialogResult.Yes == MessageBox.Show("MobileRemote requires that Bluetooth is enabled.  Would you like to enable Bluetooth on your phone?", "Bluetooth Required", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)))
                {
                    L2CAPAPI.BthSetMode(L2CAPAPI.RadioMode.Discoverable);
                }
                else
                {
                    return;
                }
            }

            using (AddressSelector selector = new AddressSelector())
            {
                bool firstConnect = autoConnect && (selector.SelectedDevice.Address != 0);
                if (firstConnect || (DialogResult.OK == selector.ShowDialog(this)))
                {
                    if (null != selector.SelectedDevice)
                    {
                        bool legacyMode = selector.LegacyMode;
                        int  oldMode    = 0;

                        if (legacyMode)
                        {
                            oldMode = Utils.SetCompatabilityMode();
                        }
                        WaitHandle result = _hidWriter.ConnectAsync(selector.SelectedDevice.Address);
                        try
                        {
                            using (WaitForConnection waitDialog = new WaitForConnection())
                            {
                                if (DialogResult.OK != waitDialog.ShowDialog(this, result, selector.SelectedDevice, _hidWriter))
                                {
                                    _hidWriter.Disconnect();
                                }
                            }
                        }
                        finally
                        {
                            if (legacyMode)
                            {
                                Utils.UnsetCompatabilityMode(oldMode);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        private void ShowConnectDialog(bool autoConnect)
        {
            L2CAPAPI.RadioMode radioMode = L2CAPAPI.RadioMode.Off;
            L2CAPAPI.BthGetMode(out radioMode);

            if (radioMode != L2CAPAPI.RadioMode.Discoverable)
            {
                if (autoConnect || (DialogResult.Yes == MessageBox.Show("MobileRemote requires that Bluetooth is enabled.  Would you like to enable Bluetooth on your phone?", "Bluetooth Required", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)))
                {
                    L2CAPAPI.BthSetMode(L2CAPAPI.RadioMode.Discoverable);
                }
                else
                {
                    return;
                }
            }

            using (AddressSelector selector = new AddressSelector())
            {
                bool firstConnect = autoConnect && (selector.SelectedDevice.Address != 0);
                if (firstConnect || (DialogResult.OK == selector.ShowDialog(this)))
                {
                    if (null != selector.SelectedDevice)
                    {
                        bool legacyMode = selector.LegacyMode;
                        int oldMode = 0;

                        if (legacyMode)
                        {
                            oldMode = Utils.SetCompatabilityMode();
                        }
                        WaitHandle result = _hidWriter.ConnectAsync(selector.SelectedDevice.Address);
                        try
                        {
                            using (WaitForConnection waitDialog = new WaitForConnection())
                            {
                                if (DialogResult.OK != waitDialog.ShowDialog(this, result, selector.SelectedDevice, _hidWriter))
                                {
                                    _hidWriter.Disconnect();
                                }
                            }
                        }
                        finally
                        {
                            if (legacyMode)
                            {
                                Utils.UnsetCompatabilityMode(oldMode);
                            }
                        }
                    }
                }
            }
        }