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 void RaiseDeviceChanged(DeviceWatcher sender, string id) { if (UpdateStatus) { // 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)) { MainPage.Current.NotifyUser(message, NotifyType.StatusMessage); } } DeviceChanged?.Invoke(sender, id); }
private static void Watcher() { while (true) { if (DeviceChanged != null) { _devicesRawNew = StartProcessingGetDevices("adb devices -l"); if (_devicesRawNew != _devicesRawOld) { _devicesRawOld = _devicesRawNew; var dl = new AdbDeviceList { GetDevicesRaw = _devicesRawNew, GetDevicesList = ParseDevicesL(_devicesRawNew) }; ConnectedAdbDevices = dl.GetDevicesList.Count; DeviceChanged?.Invoke(dl); } } Thread.Sleep(750); } // ReSharper disable once FunctionNeverReturns }
protected override void WndProc(ref Message m) { //Check for shutdown message from windows switch (m.Msg) { case WM_QUERYENDSESSION: var closingEvent = new RestartManagerEvent(RestartManagerEventType.Query); RestartManagerTriggered?.Invoke(this, closingEvent); m.Result = closingEvent.Result; Log.Information($"Received WM_QUERYENDSESSION responded {m.Result}"); break; case WM_ENDSESSION: RestartManagerTriggered?.Invoke(this, new RestartManagerEvent(RestartManagerEventType.EndSession)); Log.Information("Received WM_ENDSESSION"); break; case WM_CLOSE: RestartManagerTriggered?.Invoke(this, new RestartManagerEvent(RestartManagerEventType.ForceClose)); Log.Information("Received WM_CLOSE"); break; case WM_DEVICECHANGE: DeviceChanged?.Invoke(this, new DeviceChangeEvent()); break; case WM_HOTKEY: ProcessHotKeyEvent(m); break; } base.WndProc(ref m); }
public async void Watcher_Removed(DeviceWatcher sender, DeviceInformationUpdate devUpdate) { int count2 = 0; //Convert interfaces array to a list (IList). List <DeviceInformation> interfaceList = new List <DeviceInformation>(interfaces); foreach (DeviceInformation deviceInterface in interfaces) { if (count2 < count) { if (interfaces[count2].Id == devUpdate.Id) { //Remove the element. interfaceList.RemoveAt(count2); } } count2 += 1; } DeviceChanged?.Invoke(this, null); //Convert the list back to the interfaces array. interfaces = interfaceList.ToArray(); count -= 1; await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { DisplayDeviceInterfaceArray(); }); }
private void OnDeviceChangeEvent(object sender, EventArrivedEventArgs e) { if (Math.Abs(DateTime.Now.Second - _lastTrigger) > 1) { DeviceChanged?.Invoke(this, new EventArgs()); } _lastTrigger = DateTime.Now.Second; }
protected IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == 0x219) { Console.WriteLine($"Caught windows message {msg}"); DeviceChanged?.Invoke(this, EventArgs.Empty); } return(IntPtr.Zero); }
private void OnBridgeConnected(object sender, EventArgs e) { Dispatcher.Invoke(() => { DeviceChanged?.Invoke(this, new DeviceChangedEventArgs() { HasHue = true, }); }); HueFX.Instance.BridgeConnected -= OnBridgeConnected; }
void Thread(CancellationTokenSource cts) { while (!cts.IsCancellationRequested) { var changes = Triggers.ProcessDiscovery(Scanner.Scan(SubnetAddress).Online); foreach (var change in changes) { DeviceChanged?.Invoke(this, change); } cts.Token.WaitHandle.WaitOne(TimeSpan.FromSeconds(10)); } }
public async void Watcher_Added(DeviceWatcher sender, DeviceInformation deviceInterface) { interfaces[count] = deviceInterface; count += 1; if (isEnumerationComplete) { await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { DisplayDeviceInterfaceArray(); }); } DeviceChanged?.Invoke(this, null); }
public void OnDeviceChange(object newDevicesObject) { var newDevices = JsonConvert.DeserializeObject <List <MediaDeviceInfo> >(newDevicesObject.ToString()); var removedDevices = CurrentMediaDevices.Where(cmd => !newDevices.Any(nd => cmd.Name == nd.Name)).ToList(); var addedDevices = newDevices.Where(nd => !CurrentMediaDevices.Any(cmd => cmd.Name == nd.Name)).ToList(); DeviceChanged?.Invoke(this, new DeviceChangeEventArgs() { Devices = newDevices, RemovedDevices = removedDevices, AddedDevices = addedDevices }); CurrentMediaDevices = newDevices; }
protected override void WndProc(ref Message m) { //Check for shutdown message from windows switch (m.Msg) { case WM_QUERYENDSESSION: var closingEvent = new RestartManagerEvent(RestartManagerEventType.Query); RestartManagerTriggered?.Invoke(this, closingEvent); m.Result = closingEvent.Result; Log.Information($"Received WM_QUERYENDSESSION responded {m.Result}"); break; case WM_ENDSESSION: RestartManagerTriggered?.Invoke(this, new RestartManagerEvent(RestartManagerEventType.EndSession)); Log.Information("Received WM_ENDSESSION"); break; case WM_CLOSE: RestartManagerTriggered?.Invoke(this, new RestartManagerEvent(RestartManagerEventType.ForceClose)); Log.Information("Received WM_CLOSE"); break; case WM_DEVICECHANGE: DeviceChanged?.Invoke(this, new DeviceChangeEvent()); break; case WM_HOTKEY: ProcessHotKeyEvent(m); break; } if (WindowDestroyed != null && m.Msg == _msgNotifyShell) { // Receive shell messages switch ((Interop.ShellEvents)m.WParam.ToInt32()) { case Interop.ShellEvents.HSHELL_WINDOWDESTROYED: var hwnd = User32.NativeMethods.HWND.Cast(m.LParam); var(_, windowText, windowClass) = WindowMonitor.ProcessWindowInformation(hwnd); Task.Factory.StartNew(() => { WindowDestroyed?.Invoke(this, new WindowDestroyedEvent(hwnd)); }); break; } } base.WndProc(ref m); }
private void DeviceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var controlGroup = (DeviceControlGroup)((ComboBox)sender).Tag; var deviceType = controlGroup.DeviceType; var newDevice = controlGroup.DeviceComboBox.SelectedItem as PluginDevice; controlGroup.ConfigButton.IsEnabled = (newDevice?.Factory.Parameters?.Count ?? 0) > 0; controlGroup.PreviewButton.IsEnabled = newDevice?.Factory != null; var selectedDevice = SelectedDevices[deviceType]; var eventArgs = new DeviceChangedEventArgs(controlGroup.DeviceType, selectedDevice.Device, newDevice, selectedDevice.Params); DeviceChanged?.Invoke(this, eventArgs); selectedDevice.Device = newDevice; selectedDevice.Params = eventArgs.NewDeviceParams ?? EmptyContext.Instance; }
private void StartChromaDetection() { bool hasChromaSdk = InitChroma(); if (!hasChromaSdk) { return; } Dispatcher.Invoke(() => { DeviceChanged?.Invoke(this, new DeviceChangedEventArgs() { HasChroma = true, }); }); }
private IntPtr HwndHandler(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled) { if (!_isDisposed && msg == WmDeviceChange) { switch ((int)wparam) { case DbtDeviceRemoveComplete: DeviceChanged?.Invoke(this, false); break; case DbtDeviceArrival: DeviceChanged?.Invoke(this, true); break; } } handled = false; return(IntPtr.Zero); }
private void DeviceComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { var comboBox = (ComboBox)sender; var viewModel = (DeviceConfigViewModel)comboBox.Tag; var device = comboBox.SelectedItem as DeviceTemplate; var oldDevice = viewModel.Current; var oldContext = viewModel.ParamPanel.Context; InitializeDeviceConfigurationPanel(device); if (_deviceUpdateLock.IsReferred) { return; } var eventArgs = new DeviceChangedEventArgs(_deviceType, oldDevice, device, oldContext); DeviceChanged?.Invoke(this, eventArgs); viewModel.ParamPanel.Context = eventArgs.NewDeviceArgs ?? EmptyContext.Instance; }
private void Poll() { try { //Pollen joystickDevice.Poll(); //Status refresh state = joystickDevice.CurrentJoystickState; } catch { //lost joystick connection JoystickActiv = false; if (DeviceChanged != null) { DeviceChanged.Invoke(false, this); } } }
public async void Watcher_Updated(DeviceWatcher sender, DeviceInformationUpdate devUpdate) { int count2 = 0; foreach (DeviceInformation deviceInterface in interfaces) { if (count2 < count) { if (interfaces[count2].Id == devUpdate.Id) { //Update the element. interfaces[count2].Update(devUpdate); } } count2 += 1; } DeviceChanged?.Invoke(this, null); await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => DisplayDeviceInterfaceArray()); }
private void _watch_Added(DeviceWatcher sender, DeviceInformation args) { if (!args.IsEnabled) { return; } if (!_complete) { var t = args.EnclosureLocation; if (!args.Id.Contains(BcDeviceType.Core.ID) && !args.Id.Contains(BcDeviceType.Dongle.ID)) { return; } } DeviceChanged?.Invoke(this, new UsbWatcherEventArgs { Operation = UsbWatcherOperation.Added, Id = args.Id, Kind = args.Kind, IsEnabled = args.IsEnabled }); }
protected override void WndProc(ref Message m) { //Check for shutdown message from windows switch (m.Msg) { case WM_QUERYENDSESSION: if (ConvertLParam(m.LParam) != ENDSESSION_CLOSEAPP) { break; } var closingEvent = new RestartManagerEvent(RestartManagerEventType.Query); RestartManagerTriggered?.Invoke(this, closingEvent); m.Result = closingEvent.Result; break; case WM_ENDSESSION: if (ConvertLParam(m.LParam) != ENDSESSION_CLOSEAPP) { break; } RestartManagerTriggered?.Invoke(this, new RestartManagerEvent(RestartManagerEventType.EndSession)); break; case WM_CLOSE: RestartManagerTriggered?.Invoke(this, new RestartManagerEvent(RestartManagerEventType.ForceClose)); break; case WM_DEVICECHANGE: DeviceChanged?.Invoke(this, new DeviceChangeEvent()); break; case WM_HOTKEY: ProcessHotKeyEvent(m); break; } base.WndProc(ref m); }
private void T_Tick1(object sender, EventArgs e) { DeviceChanged?.Invoke(this, new EventArgs()); }
protected virtual void OnDeviceChanged() { DeviceChanged?.Invoke(this, EventArgs.Empty); }
private void SetDevice(IDevice device) { if (device is null) { DemoItems = new List <DemoItem>() { new DemoItem("Find Devices", new FindDevicesView() { DataContext = new FindDevicesViewModel(new Action <string>((string id) => { SetDeviceFromIdAsync(id); })) }) }; } else { DemoItems = new List <DemoItem>(); if (device.EnvironmentalSource.IsAvailable) { DemoItems.Add(new DemoItem("Enviroment", new EnvironmentalView() { DataContext = new EnviromentalViewModel(device.EnvironmentalSource) })); } if (device.AccGyroMagSource.IsAvailable) { DemoItems.Add(new DemoItem("Acc, Gyro and Mag", new AccGyroMagView() { DataContext = new AccGyroMagViewModel(device.AccGyroMagSource) })); } if (device.AudioLevelSource.IsAvailable) { DemoItems.Add(new DemoItem("Audio Level", new AudioLevelView() { DataContext = new AudioLevelViewModel(device.AudioLevelSource) })); } if (device.LEDStateSource.IsAvailable) { DemoItems.Add(new DemoItem("LED State", new LedStateView() { DataContext = new LedStateViewModel(device.LEDStateSource, device.LEDStateConfigSource) })); } if (device.LightSensorSource.IsAvailable) { DemoItems.Add(new DemoItem("Light Sensor", new LightSensorView() { DataContext = new LightSensorViewModel(device.LightSensorSource) })); } if (device.BatteryStatusSource.IsAvailable) { DemoItems.Add(new DemoItem("Battery Status", new BatteryStatusView() { DataContext = new BatteryStatusViewModel(device.BatteryStatusSource) })); } if (device.OrientationSource.IsAvailable) { DemoItems.Add(new DemoItem("Orientation", new OrientationView() { DataContext = new OrientationViewModel(device.OrientationSource) })); } if (device.CompassSource.IsAvailable) { DemoItems.Add(new DemoItem("Compass", new CompassView() { DataContext = new CompassViewModel(device.CompassSource) })); } if (device.ProximitySource.IsAvailable) { DemoItems.Add(new DemoItem("Proximity", new ProximityView() { DataContext = new ProximityViewModel(device.ProximitySource) })); } if (device.UltraVioletSource.IsAvailable) { DemoItems.Add(new DemoItem("Ultra Violet", new UltraVioletView() { DataContext = new UltraVioletViewModel(device.UltraVioletSource) })); } if (device.SmokeSensorSource.IsAvailable) { DemoItems.Add(new DemoItem("Smoke Sensor", new SmokeSensorView() { DataContext = new SmokeSensorViewModel(device.SmokeSensorSource) })); } DemoItems.Add(new DemoItem("Cloud", new AzureCloudView() { DataContext = new AzureCloudViewModel(device) })); } DeviceChanged?.Invoke(); }
private void SetDevice(IDevice device) { var demoItems = new List <DemoItem>(); if (device is null) { Device?.Disconnect(); demoItems.Add(new DemoItem("Find Devices", new FindDevicesView() { DataContext = new FindDevicesViewModel(new Action <ulong>((ulong bluetoothAddress) => { SetDeviceByAdddressAsync(bluetoothAddress); })) })); } else { if (device.EnvironmentalSource.IsAvailable) { demoItems.Add(new DemoItem("Enviroment", new EnvironmentalView() { DataContext = new EnviromentalViewModel(device.EnvironmentalSource) })); } if (device.AccGyroMagSource.IsAvailable) { demoItems.Add(new DemoItem("Acc, Gyro and Mag", new AccGyroMagView() { DataContext = new AccGyroMagViewModel(device.AccGyroMagSource) })); } if (device.AudioLevelSource.IsAvailable) { demoItems.Add(new DemoItem("Audio Level", new AudioLevelView() { DataContext = new AudioLevelViewModel(device.AudioLevelSource) })); } if (device.LEDStateSource.IsAvailable) { demoItems.Add(new DemoItem("LED State", new LedStateView() { DataContext = new LedStateViewModel(device.LEDStateSource, device.LEDStateConfigSource) })); } if (device.LightSensorSource.IsAvailable) { demoItems.Add(new DemoItem("Light Sensor", new LightSensorView() { DataContext = new LightSensorViewModel(device.LightSensorSource) })); } if (device.BatteryStatusSource.IsAvailable) { demoItems.Add(new DemoItem("Battery Status", new BatteryStatusView() { DataContext = new BatteryStatusViewModel(device.BatteryStatusSource) })); } if (device.OrientationSource.IsAvailable) { demoItems.Add(new DemoItem("Orientation", new OrientationView() { DataContext = new OrientationViewModel(device.OrientationSource) })); } if (device.CompassSource.IsAvailable) { demoItems.Add(new DemoItem("Compass", new CompassView() { DataContext = new CompassViewModel(device.CompassSource) })); } if (device.ProximitySource.IsAvailable) { demoItems.Add(new DemoItem("Proximity", new ProximityView() { DataContext = new ProximityViewModel(device.ProximitySource) })); } if (device.UltraVioletSource.IsAvailable) { demoItems.Add(new DemoItem("Ultra Violet", new UltraVioletView() { DataContext = new UltraVioletViewModel(device.UltraVioletSource) })); } if (device.SmokeSensorSource.IsAvailable) { demoItems.Add(new DemoItem("Smoke Sensor", new SmokeSensorView() { DataContext = new SmokeSensorViewModel(device.SmokeSensorSource) })); } demoItems.Add(new DemoItem("Azure cloud", new AzureCloudView() { DataContext = new AzureCloudViewModel(device) })); demoItems.Add(new DemoItem("Amazon cloud", new AmazonCloudView() { DataContext = new AmazonCloudViewModel(device) })); demoItems.Add(new DemoItem("IBMWatsons cloud", new IBMWatsonCloudView() { DataContext = new IBMWatsonsCloudViewModel(device) })); } DemoItems = demoItems; DeviceChanged?.Invoke(); }
private void _watch_Removed(DeviceWatcher sender, DeviceInformationUpdate args) { DeviceChanged?.Invoke(this, new UsbWatcherEventArgs { Operation = UsbWatcherOperation.Removed, Id = args.Id, Kind = args.Kind, IsEnabled = false }); }
private void cbDevice_SelectionChangeCommitted(object sender, System.EventArgs e) { DeviceChanged?.Invoke(cbDevice.SelectedItem as ComboItem); }
private void OnDeviceChanged() { DeviceChanged?.Invoke(this, new EventArgs()); }
public async Task GetAsync() { try { if (client == null) { return; } var currentTrack = await client.GetPlayingTrackAsync(); if (currentTrack.IsPlaying) { var devices = (await client.GetDevicesAsync()).Devices; if (devices.Except(AvailableSpotifyDevices).Any()) { AvailableSpotifyDevices = devices; } var currentActiveDevice = devices.Find(x => x.IsActive); if (ActiveDevice.Id != currentActiveDevice.Id) { ActiveDevice = _deiceMapper.Map <SpotifyDevice, Device>(currentActiveDevice); DeviceChanged?.Invoke(ActiveDevice); } if (currentTrack.Item != null) { Duration_ms = currentTrack.Item.DurationMs; Position_ms = currentTrack.ProgressMs; Volume = currentActiveDevice.VolumePercent; var testURL = currentTrack.Item.ExternUrls.FirstOrDefault(); var url = testURL.Equals(default(KeyValuePair <string, string>)) ? string.Empty : testURL.Value; if (Url != url) { Url = url; AlbumArtwork?.Dispose(); AlbumArtwork = null; } if (AlbumArtwork == null) { var artist = await client.GetArtistAsync(currentTrack.Item.Artists.FirstOrDefault()?.Id); if (artist != null) { Genre = artist.Genres.FirstOrDefault(); Type = artist.Type; } Track = currentTrack.Item.Name; Album = currentTrack.Item.Album.Name; var mainArtist = currentTrack.Item.Artists.First().Name; if (currentTrack.Item.Artists.Count() > 1) { var artistFeat = $@"{mainArtist} feat. "; artistFeat += string.Join(", ", currentTrack.Item.Artists.Skip(1).Select(x => x.Name)); Artist = artistFeat; } else { Artist = mainArtist; } //Lyrics = await LyricsHelpers.GetLyricsAsync(mainArtist, this.Track); if (currentTrack.Item.Album.Images.Any()) { ArtworkURL = currentTrack.Item.Album.Images[0].Url; AlbumArtwork = await GetImageAsync(ArtworkURL); } else { AlbumArtwork = new Bitmap(1, 1); } TrackChanged?.Invoke(this); } ; } else { Track = "Loading..."; Artist = "Loading..."; Album = "Loading..."; Duration_ms = 0; Position_ms = 0; Volume = 0; TrackChanged?.Invoke(this); } } if (IsPlaying != currentTrack.IsPlaying) { TrackPlayStateChanged?.Invoke(currentTrack.IsPlaying ? PlayState.Play : PlayState.Pause); } IsPlaying = currentTrack.IsPlaying; TrackDurationChanged?.Invoke(this); } catch (Exception ex) { Console.WriteLine(ex); } }
public void FindDevice() { //Joysticks = new Dictionary<Guid, string>(); JoystickActiv = false; // find all connected devices DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly); if (gameControllerList.Count > 0) //is there at least one device { for (Int32 i = 1; i <= gameControllerList.Count; i++) //run trough devices { gameControllerList.MoveNext(); //choose next device DeviceInstance deviceInstance = (DeviceInstance)gameControllerList.Current; //create deviceinstance //Joysticks.Add(deviceInstance.InstanceGuid, deviceInstance.ProductName); if ((deviceInstance.DeviceType == DeviceType.Joystick) || (deviceInstance.DeviceType == DeviceType.Gamepad)) //is the selected device a joystick { if (!desiredId.Equals(Guid.Empty)) { if (deviceInstance.ProductGuid.Equals(desiredId)) { joystickDevice = new Device(deviceInstance.InstanceGuid); //create joystick device this.id = deviceInstance.ProductGuid; i = gameControllerList.Count + 1; //leave loop } } else { joystickDevice = new Device(deviceInstance.InstanceGuid); //create joystick device this.id = deviceInstance.ProductGuid; i = gameControllerList.Count + 1; //leave loop } } } if (joystickDevice == null)//no joystick found { if (DeviceChanged != null) { DeviceChanged.Invoke(false, this);//Message. no joystick found } } else //Wenn Joystick vorhanden { // HMMMMMM joystickDevice.SetCooperativeLevel(Form, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive); //define interaction //joystickDevice.SetDataFormat(DeviceDataFormat.Joystick);//define that device is a joystick joystickDevice.Acquire();//make free //Referenz auch "Eigenschaften" in einer variable speichern DeviceCaps cps = joystickDevice.Caps; //Axis Number Axes = cps.NumberAxes; //Number of Buttons Buttons = cps.NumberButtons; //Views Number Views = cps.NumberPointOfViews; //Joystickname Name = joystickDevice.DeviceInformation.ProductName; //Timer start // Time.Enabled = true; JoystickActiv = true; if (DeviceChanged != null) { DeviceChanged.Invoke(true, this); } } } else { if (DeviceChanged != null) { DeviceChanged.Invoke(false, this); } } }