/// <summary> /// Initialize the Open Vario device proxy /// </summary> /// <returns>true if the proxy has been initialized, false otherwise</returns> public async Task <bool> Initialize() { bool ret = true; // List all services IList <BleGattService> ble_services = await _ble_device.GetServicesAsync(); foreach (BleGattService ble_service in ble_services) { // Add service to the list _ble_services.Add(ble_service.Guid, ble_service); } // Look for the identification service try { BleGattService identification_service = _ble_services[IdentificationService.Guid]; IdentificationService = new IdentificationService(_ble_device, identification_service); IdentificationService.IdentificationInfo id_info = await IdentificationService.GetIdentificationInfo(); if (id_info != null) { ret = true; } } catch (KeyNotFoundException) { ret = false; } if (ret) { // Look for the other services try { BleGattService altimeter_service = _ble_services[AltimeterService.Guid]; AltimeterService = new AltimeterService(_ble_device, altimeter_service); BleGattService navigation_service = _ble_services[NavigationService.Guid]; NavigationService = new NavigationService(_ble_device, navigation_service); BleGattService barometer_service = _ble_services[BarometerService.Guid]; BarometerService = new BarometerService(_ble_device, barometer_service); BleGattService variometer_service = _ble_services[VariometerService.Guid]; VariometerService = new VariometerService(_ble_device, variometer_service); } catch (KeyNotFoundException) { _ble_services.Clear(); AltimeterService = null; NavigationService = null; BarometerService = null; VariometerService = null; ret = false; } } return(ret); }
async void Notifications(object param) { if (_open_vario_device != null) { AltimeterService altimeter_service = _open_vario_device.AltimeterService; altimeter_service.MainAltitudeChanged += OnAltitudeChanged; altimeter_service.Altitude1Changed += OnAltitudeChanged; altimeter_service.Altitude2Changed += OnAltitudeChanged; altimeter_service.Altitude3Changed += OnAltitudeChanged; altimeter_service.Altitude4Changed += OnAltitudeChanged; await altimeter_service.StartNotification(AltimeterService.Altitude.MainAltitude); await altimeter_service.StartNotification(AltimeterService.Altitude.Altitude1); await altimeter_service.StartNotification(AltimeterService.Altitude.Altitude2); await altimeter_service.StartNotification(AltimeterService.Altitude.Altitude3); await altimeter_service.StartNotification(AltimeterService.Altitude.Altitude4); NavigationService navigation_service = _open_vario_device.NavigationService; navigation_service.SpeedChanged += OnSpeedChanged; navigation_service.LatitudeChanged += OnLatitudeChanged; navigation_service.LongitudeChanged += OnLongitudeChanged; navigation_service.TrackAngleChanged += OnTrackAngleChanged; await navigation_service.StartNotification(NavigationService.NavigationValue.Speed); await navigation_service.StartNotification(NavigationService.NavigationValue.Latitude); await navigation_service.StartNotification(NavigationService.NavigationValue.Longitude); await navigation_service.StartNotification(NavigationService.NavigationValue.TrackAngle); BarometerService barometer_service = _open_vario_device.BarometerService; barometer_service.PressureChanged += OnPressureChanged; barometer_service.TemperatureChanged += OnTemperatureChanged; await barometer_service.StartNotification(BarometerService.BarometerValue.Pressure); await barometer_service.StartNotification(BarometerService.BarometerValue.Temperature); VariometerService variometer_service = _open_vario_device.VariometerService; variometer_service.VarioChanged += OnVarioChanged; variometer_service.AccelerationChanged += OnAccelerationChanged; await variometer_service.StartNotification(VariometerService.VariometerValue.Vario); await variometer_service.StartNotification(VariometerService.VariometerValue.Acceleration); lbStatus.Text = "Notifications started!"; } }