private bool FilterDevices(VDevice device) { if (String.IsNullOrEmpty(device.Device.Name)) { return(false); } foreach (string type in DeviceType) { if (device.Device.Name.Contains(type)) { return(true); } } return(false); }
private double CalculateDistance(VDevice device) { int RSSI = device.Device.Rssi; double MeasuredPower = -65; double N = 2.4; double one = MeasuredPower - RSSI; double two = 10 * N; double resutltPartOne = one / two; double distance = Math.Pow(10, resutltPartOne); distance = Math.Round(distance, 2); if (distance <= 1.50) { SendNotification(device.Device.NativeDevice + ", dis:" + distance); SendVibrateAlert(); Console.WriteLine("--------Alert--------------------#" + RSSI + "#: " + distance + "-----------------------------------\n"); } return(distance); }
private async void ScanAndCheckAsync() { StatusActivityIndicator.IsRunning = true; StatusActivityIndicator.IsVisible = true; devices.Clear(); LbStatus.Text = "devices cleard"; Console.WriteLine("----------------------------devices cleard------------------------------------\n"); adapter.DeviceDiscovered += (s, a) => { IDevice device = a.Device; VDevice vDevice = new VDevice() { Device = device, Distance = 0 }; if (!devices.Contains(vDevice) && !FilterDevices(vDevice)) { vDevice.Distance = CalculateDistance(vDevice); devices.Add(vDevice); Console.WriteLine("----------------------------Device Added------------------------------------\n"); } }; if (!ble.Adapter.IsScanning) { Console.WriteLine("----------------------------Scan started------------------------------------\n"); adapter.ScanMode = ScanMode.Balanced; LbStatus.Text = "Scaning"; adapter.ScanTimeout = 10000; await adapter.StartScanningForDevicesAsync(); } DevicesListView.ItemsSource = devices; StatusActivityIndicator.IsRunning = false; StatusActivityIndicator.IsVisible = false; LbStatus.Text = "Rescaning in 10s"; }