/// <summary> /// Starts observing capabilities information for changes. /// </summary> /// <remarks> /// Capabilities' events will be never invoked before calling this method. /// </remarks> public void StartListening() { try { SystemSettings.Data3GNetworkSettingChanged += (s, e) => { Network3GChanged?.Invoke(s, new CapabilityChangedEventArgs(e.Value)); }; } catch (NotSupportedException e) { Log.Warn("SystemInfo", e.Message); } try { SystemSettings.NetworkWifiNotificationSettingChanged += (s, e) => { WifiNotificationChanged?.Invoke(s, new CapabilityChangedEventArgs(e.Value)); }; } catch (NotSupportedException e) { Log.Warn("SystemInfo", e.Message); } try { SystemSettings.NetworkFlightModeSettingChanged += (s, e) => { FlightModeChanged?.Invoke(s, new CapabilityChangedEventArgs(e.Value)); }; } catch (NotSupportedException e) { Log.Warn("SystemInfo", e.Message); } }
/// <summary> /// Default class constructor. /// </summary> public Capability() { _service = DependencyService.Get <ICapability>(); _service.Network3GChanged += (s, e) => { Network3GChanged?.Invoke(s, e); }; _service.WifiNotificationChanged += (s, e) => { WifiNotificationChanged?.Invoke(s, e); }; _service.FlightModeChanged += (s, e) => { FlightModeChanged?.Invoke(s, e); }; _service.StartListening(); }
protected async Task SwitchMode(FlightOperationMode newMode, Flight u, int delay = 0) { if (u.isSwitchingMode) { return; } if (u != null && u.isConnected) { u.isSwitchingMode = true; FlightModeChangedArgs args = new FlightModeChangedArgs(); args.from = _uav.mode; args.to = newMode; _uav.mode = newMode; if (delay > 0) { await Task.Delay(delay); } u.isSwitchingMode = false; FlightModeChanged.Invoke(this, args); } }