Esempio n. 1
0
        public DialogResult ShowDialog(MobileRemoteUI parentForm, WaitHandle waitResult, AddressSelector.BluetoothDevice device, BluetoothHidWriter hidWriter)
        {
            _statusLabel.Text = "Connecting...";
            _hidWriter = hidWriter;
            _waitResult = waitResult;
            if (device.Address > 0)
            {
                _existingMachine.Dock = DockStyle.Fill;
                _existingMachine.Visible = true;
                _newMachineLabel.Visible = false;
            }
            else
            {
                _newMachineLabel.Dock = DockStyle.Fill;
                _newMachineLabel.Visible = true;
                _existingMachine.Visible = false;
            }

            timer1.Enabled = true;

            if (waitResult.WaitOne(1000, false))
            {
                //return DialogResult.OK;
            }

            try
            {
                return base.ShowDialog(parentForm);
            }
            finally
            {
                timer1.Enabled = false;
            }
        }
Esempio n. 2
0
        public ConnectSuccess()
        {
            InitializeComponent();

            foreach (AddressSelector.BluetoothDevice device in AddressSelector.GetPreviousDevices())
            {
                _addressComboBox.Items.Add(device);
            }
            _addressComboBox.Items.Add(new AddressSelector.BluetoothDevice("Pair With New Machine", 0, false));

            _connectMacroComboBox.DisplayMember    = "Key";
            _connectMacroComboBox.ValueMember      = "Value";
            _disconnectMacroComboBox.DisplayMember = "Key";
            _disconnectMacroComboBox.ValueMember   = "Value";

            KeyValuePair <string, string> emptyMacro = new KeyValuePair <string, string>("-none-", string.Empty);

            _connectMacroComboBox.Items.Add(emptyMacro);
            _disconnectMacroComboBox.Items.Add(emptyMacro);

            foreach (string fileName in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "*.mrm"))
            {
                KeyValuePair <string, string> macro = new KeyValuePair <string, string>(Path.GetFileName(fileName), fileName);
                _connectMacroComboBox.Items.Add(macro);
                _disconnectMacroComboBox.Items.Add(macro);
            }
            _addressComboBox.SelectedIndex = 0;
        }
Esempio n. 3
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);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        void _hidWriter_Connected_Invoke()
        {
            AddressSelector.AddNewAddress(_hidWriter.BluetoothAddress, false);

            CheckConnection();

            ConnectionSettingCollection.ConnectionSetting setting = Properties.Settings.Default.ConnectionSettings[_hidWriter.BluetoothAddress];
            if (null == setting)
            {
                ShowNewConnectionSettings();
            }
            setting = Properties.Settings.Default.ConnectionSettings[_hidWriter.BluetoothAddress];

            if (null != setting)
            {
                // Execute the connect macro here
                if (!string.IsNullOrEmpty(setting.ConnectMacro))
                {
                    ExecuteMacro(setting.ConnectMacro);
                }
            }
        }
Esempio n. 5
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);
                            }
                        }
                    }
                }
            }
        }