//END DATE TIME___________________________________________________________________________________________________ //BLUETOOTH SCAN ________________________________________________________________________________________________ private async void ScanForBluetooth() { //Reset our BT connection stuff glob_DeviceAddress = 0; buttonStart.Content = "Scanning"; buttonStart.IsEnabled = false; //Lets look for the device textboxBluetoothDevice.Text = "Scanning..."; BluetoothDeviceControl myBluetoothDeviceControl = new BluetoothDeviceControl(); myBluetoothDeviceControl.BTDeviceHandlerEvent += BluetoothDeviceControlEventController; //await Task.Factory.StartNew(() => myBluetoothDeviceControl.Scan(), TaskCreationOptions.LongRunning); glob_BluetoothScanTask = Task.Factory.StartNew(() => myBluetoothDeviceControl.Scan(), TaskCreationOptions.LongRunning); await glob_BluetoothScanTask; //if the task finnishes and we dont have a device try again if (glob_DeviceAddress == 0) //scan for bluetooth again { ScanForBluetooth(); //NOT TESTED } else { ConnectToBlueTooth(); // streaming from BT device buttonStart.Content = "Start Recording"; buttonStart.IsEnabled = true; } }
private void ConnectToBlueTooth() { //dont like this ATM but we need to check we are paired and have the device available if (glob_DeviceAddress != 0) //do we know of an address? { BluetoothDeviceControl bluetoothDeviceControl = new BluetoothDeviceControl(); bluetoothDeviceControl.BTDeviceHandlerEvent += DeviceStillConnected; Task.Factory.StartNew(() => bluetoothDeviceControl.Pair(glob_DeviceAddress), TaskCreationOptions.LongRunning); } else // look for the device { ScanForBluetooth(); } }