Пример #1
0
		protected void Initialize()
		{
			this.Title = "Scanner";

			// configure our scan button
			this._scanButton = new ScanButton ();
			this._scanButton.TouchUpInside += (s,e) => {
				if ( !Adapter.Current.IsScanning ) {
					Adapter.Current.StartScanningForDevices ();
				} else {
					Adapter.Current.StopScanningForDevices ();
				}
			};			 
			this.NavigationItem.SetRightBarButtonItem (new UIBarButtonItem (this._scanButton), false);

			// setup the table
			this._tableSource = new BleDeviceTableSource ();
			this._tableSource.DeviceSelected += (object sender, BleDeviceTableSource.DeviceSelectedEventArgs e) => {

				// stop scanning
				new Task( () => {
					if(Adapter.Current.IsScanning) {
						Console.WriteLine ("Still scanning, stopping the scan and reseting the right button");
						Adapter.Current.StopScanningForDevices();
						this._scanButton.SetState (ScanButton.ScanButtonState.Normal);
					}
				}).Start();

				// show our connecting... overlay
				this._connectingDialog.LabelText = "Connecting to " + e.SelectedDevice.Name;
				this._connectingDialog.Show(true);

				// when the peripheral connects, load our details screen
				Adapter.Current.DeviceConnected += (object s, DeviceConnectionEventArgs connectArgs) => {

					this._connectingDialog.Hide(false);

					this._ServiceListScreen = new DeviceDetails.ServiceListScreen();

					this._ServiceListScreen.ConnectedDevice = connectArgs.Device;

					this.NavigationController.PushViewController ( this._ServiceListScreen, true);

				};

				Adapter.Current.DeviceFailedToConnect += (object s, DeviceConnectionEventArgs connectArgs) => {
					this._connectingDialog.Hide(false);

					new UIAlertView ("Device Failed to Connect", connectArgs.ErrorMessage, null, "ok. :(", null).Show();
				};

				// try and connect to the peripheral
				Adapter.Current.ConnectToDevice (e.SelectedDevice);
			};


		}
Пример #2
0
        protected void Initialize()
        {
            this.Title = "Scanner";

            // configure our scan button
            this._scanButton = new ScanButton();
            this._scanButton.TouchUpInside += (s, e) => {
                if (!Adapter.Current.IsScanning)
                {
                    Adapter.Current.StartScanningForDevices();
                }
                else
                {
                    Adapter.Current.StopScanningForDevices();
                }
            };
            this.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(this._scanButton), false);

            // setup the table
            this._tableSource = new BleDeviceTableSource();
            this._tableSource.DeviceSelected += (object sender, BleDeviceTableSource.DeviceSelectedEventArgs e) => {
                // stop scanning
                new Task(() => {
                    if (Adapter.Current.IsScanning)
                    {
                        Console.WriteLine("Still scanning, stopping the scan and reseting the right button");
                        Adapter.Current.StopScanningForDevices();
                        this._scanButton.SetState(ScanButton.ScanButtonState.Normal);
                    }
                }).Start();

                // show our connecting... overlay
                this._connectingDialog.LabelText = "Connecting to " + e.SelectedDevice.Name;
                this._connectingDialog.Show(true);

                // when the peripheral connects, load our details screen
                Adapter.Current.DeviceConnected += (object s, DeviceConnectionEventArgs connectArgs) => {
                    this._connectingDialog.Hide(false);

                    this._ServiceListScreen = new DeviceDetails.ServiceListScreen();

                    this._ServiceListScreen.ConnectedDevice = connectArgs.Device;

                    this.NavigationController.PushViewController(this._ServiceListScreen, true);
                };

                Adapter.Current.DeviceFailedToConnect += (object s, DeviceConnectionEventArgs connectArgs) => {
                    this._connectingDialog.Hide(false);

                    new UIAlertView("Device Failed to Connect", connectArgs.ErrorMessage, null, "ok. :(", null).Show();
                };

                // try and connect to the peripheral
                Adapter.Current.ConnectToDevice(e.SelectedDevice);
            };
        }
Пример #3
0
		protected void Initialize()
		{
			this.Title = "Scanner";

			// configure our scan button
			this._scanButton = new ScanButton ();
			this._scanButton.TouchUpInside += (s,e) => {
				if ( !BluetoothLEManager.Current.IsScanning ) {
					BluetoothLEManager.Current.BeginScanningForDevices ();
				} else {
					BluetoothLEManager.Current.StopScanningForDevices ();
				}
			};			 
			this.NavigationItem.SetRightBarButtonItem (new UIBarButtonItem (this._scanButton), false);

			// setup the table
			this._tableSource = new BleDeviceTableSource ();
			this._tableSource.PeripheralSelected += (object sender, BleDeviceTableSource.PeripheralSelectedEventArgs e) => {

				// stop scanning
				new Task( () => {
					if(BluetoothLEManager.Current.IsScanning) {
						Console.WriteLine ("Still scanning, stopping the scan and reseting the right button");
						BluetoothLEManager.Current.StopScanningForDevices();
						this._scanButton.SetState (ScanButton.ScanButtonState.Normal);
					}
				}).Start();

				// show our connecting... overlay
				this._connectingDialog.LabelText = "Connecting to " + e.SelectedPeripheral.Name;
				this._connectingDialog.Show(true);

				// when the peripheral connects, load our details screen
				BluetoothLEManager.Current.DeviceConnected += (object s, CBPeripheralEventArgs periphE) => {
					this._connectingDialog.Hide(false);

					this._detailsScreen = this.Storyboard.InstantiateViewController("DeviceDetailsScreen") as DeviceDetails.DeviceDetailsScreen;
					this._detailsScreen.ConnectedPeripheral = periphE.Peripheral;
					this.NavigationController.PushViewController ( this._detailsScreen, true);

				};

				// try and connect to the peripheral
				BluetoothLEManager.Current.CentralBleManager.ConnectPeripheral (e.SelectedPeripheral, new PeripheralConnectionOptions());
			};


		}
Пример #4
0
        protected void Initialize()
        {
            this.Title = "Scanner";

            // configure our scan button
            this._scanButton = new ScanButton();
            this._scanButton.TouchUpInside += (s, e) => {
                if (!BluetoothLEManager.Current.IsScanning)
                {
                    BluetoothLEManager.Current.BeginScanningForDevices();
                }
                else
                {
                    BluetoothLEManager.Current.StopScanningForDevices();
                }
            };
            this.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(this._scanButton), false);

            // setup the table
            this._tableSource = new BleDeviceTableSource();
            this._tableSource.PeripheralSelected += (object sender, BleDeviceTableSource.PeripheralSelectedEventArgs e) => {
                // stop scanning
                new Task(() => {
                    if (BluetoothLEManager.Current.IsScanning)
                    {
                        Console.WriteLine("Still scanning, stopping the scan and reseting the right button");
                        BluetoothLEManager.Current.StopScanningForDevices();
                        this._scanButton.SetState(ScanButton.ScanButtonState.Normal);
                    }
                }).Start();

                // show our connecting... overlay
                this._connectingDialog.LabelText = "Connecting to " + e.SelectedPeripheral.Name;
                this._connectingDialog.Show(true);

                // when the peripheral connects, load our details screen
                BluetoothLEManager.Current.DeviceConnected += (object s, CBPeripheralEventArgs periphE) => {
                    this._connectingDialog.Hide(false);

                    this._detailsScreen = this.Storyboard.InstantiateViewController("DeviceDetailsScreen") as DeviceDetails.DeviceDetailsScreen;
                    this._detailsScreen.ConnectedPeripheral = periphE.Peripheral;
                    this.NavigationController.PushViewController(this._detailsScreen, true);
                };

                // try and connect to the peripheral
                BluetoothLEManager.Current.CentralBleManager.ConnectPeripheral(e.SelectedPeripheral, new PeripheralConnectionOptions());
            };
        }