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()); }; }
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()); }; }