/// <summary> /// Discovers the bluetooth headsets and populates the devices list. /// </summary> public async Task FindDevicesAsync() { Devices.Clear(); _deviceListGnImuService = await DeviceInformation.FindAllAsync( GattDeviceService.GetDeviceSelectorFromUuid(Guid.Parse(IHSUuids.GnImuService))); if (_deviceListGnImuService.Count > 0) { foreach (var deviceInformation in _deviceListGnImuService) { IHSDevice device = new IHSDevice(deviceInformation); Devices.Add(device); } } }
/// <summary> /// Initializes (acquires) the GATT services. /// </summary> /// <param name="device">The headset device whose services to initialize.</param> /// <returns>True, if successful. False otherwise.</returns> public async Task <bool> InitializeServicesAsync(IHSDevice device) { if (_deviceInfoService != null) { _deviceInfoService.Device.ConnectionStatusChanged -= OnDeviceConnectionStatusChangedAsync; } try { _gnImuService = await GattDeviceService.FromIdAsync(device.DeviceInformation.Id); _gnSystemService = _gnImuService.Device.GetGattService(Guid.Parse(IHSUuids.GnSystemService)); _gnGPSservice = _gnImuService.Device.GetGattService(Guid.Parse(IHSUuids.GnGpsService)); _deviceInfoService = _gnImuService.Device.GetGattService(IHSUuids.CreateGuidfromWellKnownUUID(IHSUuids.DeviceInfoServiceId)); _batteryInfoService = _gnImuService.Device.GetGattService(IHSUuids.CreateGuidfromWellKnownUUID(IHSUuids.BatteryServiceId)); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("InitializeServiceAsync(): " + e.Message); } if (_deviceInfoService != null) { _deviceInfoService.Device.ConnectionStatusChanged += OnDeviceConnectionStatusChangedAsync; _deviceInfoHandler = new IHSDeviceInfoHandler(DeviceInfo, _deviceInfoService, _batteryInfoService); } if (_gnImuService != null && _gnGPSservice != null && _gnSystemService != null) { _sensorReadingsHandler = new IHSSensorReadingsHandler(SensorReadings, Gps, _gnImuService, _gnGPSservice, _gnSystemService); _sensorReadingsHandler.SensorsListenedToChanged += SensorsListenedToChanged; } System.Diagnostics.Debug.WriteLine("InitializeServiceAsync(): Status:" + "\n\t- GN system service: " + ((_gnSystemService == null) ? "FAIL" : "OK") + "\n\t- Device information service: " + ((_deviceInfoService == null) ? "FAIL" : "OK") + "\n\t- Battery informatiojn service: " + ((_batteryInfoService == null) ? "FAIL" : "OK") + "\n\t- GN IMU service: " + ((_gnImuService == null) ? "FAIL" : "OK") + "\n\t- GN GPS service: " + ((_gnGPSservice == null) ? "FAIL" : "OK")); IsInitialized = (_deviceInfoService != null && _gnImuService != null); return(IsInitialized); }