private async void OnBleAdvertisementUpdated(BleAdvertisementWatcher sender, DeviceWatchEvent eventCode, BLEAdvertisementInfo bleAdvertisementInfo)
        {
            DeviceInformation btDeviceInformation = await BluetoothDevices.CreateDeviceInformation(bleAdvertisementInfo.ToBtAddressString(), AddressType.Bluetooth);

            DeviceInformation bleDeviceInformation = await BluetoothDevices.CreateDeviceInformation(bleAdvertisementInfo.ToBtAddressString(), AddressType.BLE);

            if (!App.sUserManager.IsSingnIn())
            {
                // FIXME: SERVICE CODE to configuration
                if (bleAdvertisementInfo.Advertisement.ManufacturerData[0].Data.Length > 5)
                {
                    // ignore, because it has user Key.
                    Log.D(string.Format($"Other User's Device Found: {bleAdvertisementInfo.Advertisement.ManufacturerData[0].Data}"));
                    return;
                }
            }

            if (eventCode == DeviceWatchEvent.Added)
            {
                Log.D(string.Format($"New BLE Advertisement Found: {bleAdvertisementInfo.ToBtAddressString()}"));

                AddNearByEarbuds(bleDeviceInformation.Id);
                AddNearByBtDevice(bleDeviceInformation.Id, btDeviceInformation.Name);
            }
            else if (eventCode == DeviceWatchEvent.Removed)
            {
                Log.D(string.Format($"BLE Advertisement Removed: {bleAdvertisementInfo.ToBtAddressString()}"));

                Earbuds removeEarBuds = RemoveNearByEarbuds(bleDeviceInformation.Id);
                if (removeEarBuds != null)
                {
                    RemoveNearByBtDevice(bleDeviceInformation.Id, btDeviceInformation.Name);
                }
            }
        }
Exemplo n.º 2
0
        private void RaiseDeviceChanged(DeviceWatcher sender, DeviceWatchEvent eventCode, DeviceInformation deviceInformation)
        {
            if (DEBUG)
            {
                // Display a default status message.
                string message = string.Empty;
                switch (sender.Status)
                {
                case DeviceWatcherStatus.Started:
                    message = $"{resultCollection.Count} devices found.";
                    break;

                case DeviceWatcherStatus.EnumerationCompleted:
                    message = $"{resultCollection.Count} devices found. Enumeration completed. Watching for updates...";
                    break;

                case DeviceWatcherStatus.Stopped:
                    message = $"{resultCollection.Count} devices found. Watcher stopped.";
                    break;

                case DeviceWatcherStatus.Aborted:
                    message = $"{resultCollection.Count} devices found. Watcher aborted.";
                    break;
                }

                if (!string.IsNullOrEmpty(message))
                {
                    Debug.WriteLine(message);
                }
            }

            DeviceChanged?.Invoke(sender, eventCode, deviceInformation);
        }
        private async void OnBluetoothDeviceUpdated(BluetoothWatcher sender, DeviceWatchEvent eventCode, DeviceInformation deviceInformation)
        {
            string deviceId = deviceInformation == null ? string.Empty : deviceInformation.Id;

            Log.D($"OnBluetoothDeviceUpdated: {eventCode} {deviceId}");

            switch (eventCode)
            {
            case DeviceWatchEvent.Added:
                EarbudsMenuItem newEarbudsMenuItem = new EarbudsMenuItem(deviceInformation, systrayApplicationServiceConnection);
                bool            result             = await newEarbudsMenuItem.Start();

                Log.D($"Starting {newEarbudsMenuItem.Text}, result = {result}");
                PairedDeviceMenuItems.Add(newEarbudsMenuItem);
                break;

            case DeviceWatchEvent.Removed:
                foreach (EarbudsMenuItem earbudsMenuItem in PairedDeviceMenuItems)
                {
                    if (deviceId.Equals(earbudsMenuItem.BtID))
                    {
                        PairedDeviceMenuItems.Remove(earbudsMenuItem);
                        earbudsMenuItem.Stop();
                        break;
                    }
                }
                break;
            }

            InitMenuItems();
        }
Exemplo n.º 4
0
 private async void OnBleDeviceUpdated(DeviceManager bluetoothWatcher, DeviceWatchEvent eventCode, DeviceInformation bleDeviceInformation)
 {
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         BleDeviceCollection.Clear();
         foreach (DeviceInformation deviceInformation in App.sDeviceManager.NearbyDeviceList)
         {
             BleDeviceCollection.Add(new DeviceInformationDisplay(deviceInformation));
         }
     });
 }
Exemplo n.º 5
0
 private async void OnPairedDeviceUpdated(DeviceManager bluetoothWatcher, DeviceWatchEvent eventCode, DeviceInformation deviceInformation)
 {
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         PairedDevicetCollection.Clear();
         lock (App.sDeviceManager.PairedDeviceList) {
             foreach (DeviceInformation devInfo in App.sDeviceManager.PairedDeviceList)
             {
                 PairedDevicetCollection.Add(new DeviceInformationDisplay(devInfo));
             }
         }
     });
 }
 public async void HandleBleAdvertisement(DeviceWatchEvent eventCode)
 {
     if (eventCode == DeviceWatchEvent.Added)
     {
         if (!EarBudStarted)
         {
             EarBudStarted = await Earbuds.Start();
         }
     }
     else if (eventCode == DeviceWatchEvent.Removed)
     {
         // Ignore currently
     }
 }
        // BLE Advertisement Handler
        private void OnBleAdvertisementUpdated(BleAdvertisementWatcher sender, DeviceWatchEvent eventCode, BLEAdvertisementInfo bleAdvertisementInfo)
        {
            if (userKey == null || userKey.Length == 0)
            {
                // FIXME: SERVICE CODE to configuration
                if (bleAdvertisementInfo.Advertisement.ManufacturerData[0].Data.Length > 5)
                {
                    // ignore, because it has user Key.
                    return;
                }
            }

            if (eventCode == DeviceWatchEvent.Added)
            {
                Log.D($"New BLE Advertisement Found: {bleAdvertisementInfo.ToBtAddressString()}");
                ValueSet newBleDeviceMessage = new ValueSet
                {
                    { "opcode", "ble_device" },
                    { "status", "added" },
                    { "name", bleAdvertisementInfo.Advertisement.LocalName },
                    { "id", $"Bluetooth#Bluetooth{localBtAddress}-{bleAdvertisementInfo.ToBtAddressString()}" }
                };
                systrayApplicationServiceConnection.SendMessageAsync(newBleDeviceMessage);
            }
            else if (eventCode == DeviceWatchEvent.Removed)
            {
                Log.D($"BLE Advertisement Removed: {bleAdvertisementInfo.ToBtAddressString()}");
                ValueSet removeBleDeviceMessage = new ValueSet
                {
                    { "opcode", "ble_device" },
                    { "status", "removed" },
                    { "name", bleAdvertisementInfo.Advertisement.LocalName },
                    { "id", $"Bluetooth#Bluetooth{localBtAddress}-{bleAdvertisementInfo.ToBtAddressString()}" }
                };
                systrayApplicationServiceConnection.SendMessageAsync(removeBleDeviceMessage);
            }

            // Propergate Event to Earbuds Menu
            string deviceId = $"Bluetooth#Bluetooth{localBtAddress}-{bleAdvertisementInfo.ToBtAddressString()}";

            foreach (EarbudsMenuItem earbudsMenuItem in PairedDeviceMenuItems)
            {
                if (BluetoothDevices.EqualDevice(deviceId, earbudsMenuItem.BtID))
                {
                    earbudsMenuItem.HandleBleAdvertisement(eventCode);
                    break;
                }
            }
        }
        private void OnBluetoothDeviceUpdated(BluetoothWatcher sender, DeviceWatchEvent eventCode, DeviceInformation deviceInformation)
        {
            string deviceId = deviceInformation == null ? string.Empty : deviceInformation.Id;

            Log.D(string.Format($"OnBluetoothDeviceUpdated: {eventCode} {deviceId}"));

            switch (eventCode)
            {
            case DeviceWatchEvent.Added:
                AddPairedBtDevice(deviceInformation);
                break;

            case DeviceWatchEvent.Updated:
                UpdatePairedBtDevice(deviceInformation);
                break;

            case DeviceWatchEvent.Removed:
                RemovePairedBtDevice(deviceInformation);
                break;
            }

            PairedDeviceUpdated?.Invoke(this, eventCode, deviceInformation);
        }
 private void OnDeviceListChanged(DeviceWatcher sender, DeviceWatchEvent eventCode, DeviceInformation deviceInformation)
 {
     Received?.Invoke(this, eventCode, deviceInformation);
 }