public async Task <PlotDeviceProperties> DeviceCreatedAsync(Guid deviceId, CancellationToken cancellationToken) { await _shell.SwitchToMainThreadAsync(cancellationToken); var device = new RPlotDevice(deviceId); lock (_devicesLock) { _devices.Add(device); } PlotDeviceProperties props; var visualComponent = GetVisualComponentForDevice(deviceId); if (visualComponent != null) { visualComponent.Container.Show(focus: false, immediate: true); props = visualComponent.GetDeviceProperties(); } else { Debug.Assert(false, "Failed to create a plot visual component."); props = PlotDeviceProperties.Default; } device.PixelWidth = props.Width; device.PixelHeight = props.Height; device.Resolution = props.Resolution; DeviceAdded?.Invoke(this, new RPlotDeviceEventArgs(device)); return(props); }
protected async virtual void OnDeviceAdded(BTInitEventArgs e) { await mainPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate { DeviceAdded?.Invoke(this, e); }); }
private void CompareDrives() { var drivesNow = GetRemovableDrives(); var addedDrives = drivesNow.Except(_drives); var removedDrives = _drives.Except(drivesNow); if (addedDrives.Any()) { foreach (var addedDrive in addedDrives) { if (DeviceAdded != null) { DeviceAdded.Invoke(new Device(addedDrive)); } DisplayNewDeviceToast(addedDrive); } } if (removedDrives.Any()) { foreach (var removedDrive in removedDrives) { if (DeviceRemoved != null) { DeviceRemoved.Invoke(new Device(removedDrive)); } } } }
public void Configure(DriverDetails driverDetails) { client = new OpenRGBClient(name: "RGB Sync Studio", autoconnect: true, timeout: 1000); var deviceCount = client.GetControllerCount(); var devices = client.GetAllControllerData(); for (int devId = 0; devId < devices.Length; devId++) { ORGBControlDevice slsDevice = new ORGBControlDevice(); slsDevice.id = devId; slsDevice.Driver = this; slsDevice.Name = devices[devId].Name; slsDevice.DeviceType = DeviceTypeConverter.GetType(devices[devId].Type); slsDevice.Has2DSupport = false; slsDevice.ProductImage = (Bitmap)Image.FromStream(orgbImage); List <ControlDevice.LedUnit> deviceLeds = new List <ControlDevice.LedUnit>(); int i = 0; foreach (Led orgbLed in devices[devId].Leds) { ControlDevice.LedUnit slsLed = new ControlDevice.LedUnit(); slsLed.LEDName = orgbLed.Name; deviceLeds.Add(slsLed); } slsDevice.LEDs = deviceLeds.ToArray(); DeviceAdded?.Invoke(slsDevice, new Events.DeviceChangeEventArgs(slsDevice)); } }
public async Task <PlotDeviceProperties> DeviceCreatedAsync(Guid deviceId) { InteractiveWorkflow.Shell.AssertIsOnMainThread(); var device = new RPlotDevice(deviceId); _devices.Add(device); PlotDeviceProperties props; var visualComponent = await GetVisualComponentForDevice(deviceId); if (visualComponent != null) { visualComponent.Container.Show(focus: false, immediate: true); props = visualComponent.GetDeviceProperties(); } else { Debug.Assert(false, "Failed to create a plot visual component."); props = PlotDeviceProperties.Default; } device.PixelWidth = props.Width; device.PixelHeight = props.Height; device.Resolution = props.Resolution; DeviceAdded?.Invoke(this, new RPlotDeviceEventArgs(device)); return(props); }
public bool Add(Device device) { if (device == null) { return(false); } if (GetDevice(device.DeviceType, device.DeviceIndex) != null) { Logger.Info(string.Format("add device failed, this device[{0}] already in device group", device.GetDeviceName())); return(false); } lock (locker) { this.devices.Add(device); } if (DeviceAdded != null) { DeviceAdded.Invoke(device, null); } return(true); }
public void SorterCallback(UIntPtr buf, int buf_length) { unsafe { Span <byte> byteArray = new Span <byte>(buf.ToPointer(), buf_length); ByteBuffer byteBuf = new ByteBuffer(byteArray.ToArray()); var server_message = ServerMessage.GetRootAsServerMessage(byteBuf); if (server_message.Id > 0) { _messageSorter.CheckMessage(server_message); } else { if (server_message.MessageType == ServerMessageType.DeviceAdded) { var device_added_message = server_message.Message <DeviceAdded>(); var device_handle = ButtplugFFI.SendCreateDevice(_clientHandle, device_added_message.Value.Index); var attribute_dict = new Dictionary <MessageAttributeType, ButtplugMessageAttributes>(); for (var i = 0; i < device_added_message.Value.AttributesLength; ++i) { var attributes = device_added_message.Value.Attributes(i).Value; var device_message_attributes = new ButtplugMessageAttributes(attributes.FeatureCount, attributes.GetStepCountArray(), attributes.GetEndpointsArray(), attributes.GetMaxDurationArray(), null, null); attribute_dict.Add(attributes.MessageType, device_message_attributes); } var device = new ButtplugClientDevice(_messageSorter, device_handle, device_added_message.Value.Index, device_added_message.Value.Name, attribute_dict); DeviceAdded.Invoke(this, new DeviceAddedEventArgs(device)); } } } }
public async Task RequestDeviceList() { var resp = await SendMessage(new RequestDeviceList(nextMsgId)); if (!(resp is DeviceList) || (resp as DeviceList).Devices == null) { if (resp is Error) { _owningDispatcher.Invoke(() => { ErrorReceived?.Invoke(this, new ErrorEventArgs(resp as Error)); }); } return; } foreach (var d in (resp as DeviceList).Devices) { if (!_devices.ContainsKey(d.DeviceIndex)) { var device = new ButtplugClientDevice(d); if (_devices.TryAdd(d.DeviceIndex, device)) { _owningDispatcher.Invoke(() => { DeviceAdded?.Invoke(this, new DeviceEventArgs(device, DeviceAction.ADDED)); }); } } } }
private async static void HardDeviceList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: { foreach (DriveRelatedData Device in e.NewItems) { DeviceAdded?.Invoke(null, Device); } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: { foreach (DriveRelatedData Device in e.OldItems) { DeviceRemoved?.Invoke(null, Device); } break; } } }); }
public void ListenForDevices() { var subscription = DeviceLocator .FindReceiversContinuous() .Subscribe(d => DeviceAdded?.Invoke(this, new DeviceAddedArgs(d))); _subscriptions.Add(subscription); }
/// <summary> /// Message Received event handler. Either tries to match incoming messages as replies to /// messages we've sent, or fires an event related to an incoming event, like device /// additions/removals, log messages, etc. /// </summary> /// <param name="aSender">Object sending the open event, unused.</param> /// <param name="aArgs">Event parameters, including the data received.</param> private async void MessageReceivedHandler(object aSender, MessageReceivedEventArgs aArgs) { var msg = aArgs.Message; switch (msg) { case Log l: Log?.Invoke(this, new LogEventArgs(l)); break; case DeviceAdded d: var dev = new ButtplugClientDevice(_bpLogManager, this, SendDeviceMessageAsync, d); _devices.Add(d.DeviceIndex, dev); DeviceAdded?.Invoke(this, new DeviceAddedEventArgs(dev)); break; case DeviceRemoved d: if (!_devices.ContainsKey(d.DeviceIndex)) { ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs( new ButtplugDeviceException(_bpLogger, "Got device removed message for unknown device.", msg.Id))); return; } var oldDev = _devices[d.DeviceIndex]; _devices.Remove(d.DeviceIndex); DeviceRemoved?.Invoke(this, new DeviceRemovedEventArgs(oldDev)); break; case ScanningFinished _: // The scanning finished event is self explanatory and doesn't require extra arguments. ScanningFinished?.Invoke(this, new EventArgs()); break; case Error e: // This will both log the error and fire it from our ErrorReceived event handler. ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs(ButtplugException.FromError(_bpLogger, e))); if (e.ErrorCode == Error.ErrorClass.ERROR_PING) { PingTimeout?.Invoke(this, EventArgs.Empty); await DisconnectAsync().ConfigureAwait(false); } break; default: ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs( new ButtplugMessageException(_bpLogger, $"Got unhandled message: {msg}", msg.Id))); break; } }
/// <summary> /// Websocket Message Received event handler. Either tries to match incoming messages as /// replies to messages we've sent, or fires an event related to an incoming event, like /// device additions/removals, log messages, etc. /// </summary> /// <param name="aSender">Object sending the open event, unused.</param> /// <param name="aArgs">Event parameters, including the data received.</param> private void MessageReceivedHandler(object aSender, WebSocket4Net.MessageReceivedEventArgs aArgs) { var msgs = Deserialize(aArgs.Message); foreach (var msg in msgs) { if (msg.Id > 0 && _waitingMsgs.TryRemove(msg.Id, out TaskCompletionSource <ButtplugMessage> queued)) { queued.TrySetResult(msg); continue; } switch (msg) { case Log l: _owningDispatcher.Send(_ => { Log?.Invoke(this, new LogEventArgs(l)); }, null); break; case DeviceAdded d: var dev = new ButtplugClientDevice(d); _devices.AddOrUpdate(d.DeviceIndex, dev, (idx, old) => dev); _owningDispatcher.Send(_ => { DeviceAdded?.Invoke(this, new DeviceEventArgs(dev, DeviceEventArgs.DeviceAction.ADDED)); }, null); break; case DeviceRemoved d: if (_devices.TryRemove(d.DeviceIndex, out ButtplugClientDevice oldDev)) { _owningDispatcher.Send(_ => { DeviceRemoved?.Invoke(this, new DeviceEventArgs(oldDev, DeviceEventArgs.DeviceAction.REMOVED)); }, null); } break; case ScanningFinished sf: _owningDispatcher.Send(_ => { ScanningFinished?.Invoke(this, new ScanningFinishedEventArgs(sf)); }, null); break; case Error e: _owningDispatcher.Send(_ => { ErrorReceived?.Invoke(this, new ErrorEventArgs(e)); }, null); break; } } }
public void InterestedUSBChange(int VID, int PID, bool connected) { if (!connected) { var dev = devices.First(x => x is HyperXAlloyRgbControlDevice hx && hx.HID == PID); devices.Remove(dev); DeviceRemoved?.Invoke(this, new Events.DeviceChangeEventArgs(dev)); } else { var sdevice = supportedDevices.First(x => x.Pid == PID); HyperXKeyboardSupport hyperX = new HyperXKeyboardSupport(sdevice.Vid, sdevice.Pid, sdevice.Usb); dv = new HyperXAlloyRgbControlDevice { Name = sdevice.Name, DeviceType = DeviceTypes.Keyboard, Driver = this, ProductImage = Assembly.GetExecutingAssembly().GetEmbeddedImage("Driver.HyperXAlloy.RGB." + sdevice.Name + ".png"), HyperXSupport = hyperX, GridHeight = 6, GridWidth = 23, Has2DSupport = true, HID = sdevice.Pid }; KeyboardHelper.AddKeyboardWatcher(sdevice.Vid, sdevice.Pid, dv.HandleInput); List <ControlDevice.LedUnit> leds = new List <ControlDevice.LedUnit>(); int ctt = 0; var tled = new ControlDevice.LedUnit[106]; int ct = 0; foreach (var tp in hyperX.humm) { var ld = new ControlDevice.LedUnit { LEDName = HyperXKeyboardSupport.KeyNames[tp.Order], Data = new ControlDevice.PositionalLEDData { LEDNumber = Array.IndexOf(hyperX.humm, tp), X = tp.X, Y = tp.Y }, }; leds.Add(ld); } dv.LEDs = leds.OrderBy(p => ((ControlDevice.PositionalLEDData)p.Data).X + ((ControlDevice.PositionalLEDData)p.Data).Y).ToArray(); devices.Add(dv); DeviceAdded?.Invoke(this, new Events.DeviceChangeEventArgs(dv)); } }
public void Configure(DriverDetails driverDetails) { var drivers = GetDevices(); foreach (ControlDevice controlDevice in drivers) { DeviceAdded?.Invoke(this, new Events.DeviceChangeEventArgs(controlDevice)); } }
private Device GetOrAddDevice(string name) { Device device = null; if (!devices.TryGetValue(name, out device)) { device = new Device(name, this); devices.Add(device.Name, device); DeviceAdded?.Invoke(device); } return(device); }
public bool TryAddDevice(DeviceType device, DeviceState state, out DeviceStatus status) { status = new DeviceStatus(device, state, DateTime.Now); if (_devices.TryAdd(device, status)) { DeviceAdded?.Invoke(this, status); return(true); } return(false); }
private void ListenToDevice(IAudioDevice device) { device.PropertyChanged += Device_PropertyChanged; device.Groups.CollectionChanged += Groups_CollectionChanged; foreach (var app in device.Groups) { ListenToApp(app); } DeviceAdded?.Invoke(device); }
public static void GetAccessToken(string authCode) { var client = new RestClient("https://sandbox-api.dexcom.com/v2/oauth2/token"); var request = new RestRequest(Method.POST); request.AddHeader("cache-control", "no-cache"); request.AddHeader("content-type", "application/x-www-form-urlencoded"); request.AddParameter("application/x-www-form-urlencoded", $"client_secret=xxxx&code={authCode}&grant_type=authorization_code&redirect_uri=android.app.pact.com:/oauth2redirect", ParameterType.RequestBody); var response = client.Execute <AccessTokenPayload>(request); AuthenticationStorage.SetTokenPayloadAsync(response.Data); DeviceAdded?.Invoke("Authentication", null); }
// Token: 0x06000003 RID: 3 RVA: 0x0000215E File Offset: 0x0000035E public void Configure(DriverDetails driverDetails) { ControlDevice rainbowWaveDevice = new ControlDevice { Name = "Rainbow Wave", Driver = this, ProductImage = (Bitmap)System.Drawing.Image.FromStream(imageStream), LEDs = this.leds, DeviceType = DeviceTypes.Effect }; DeviceAdded?.Invoke(rainbowWaveDevice, new Events.DeviceChangeEventArgs(rainbowWaveDevice)); }
public void Configure(DriverDetails driverDetails) { _sdk = (IAuraSdk2) new AuraSdk(); _sdk.SwitchMode(); _collection = _sdk.Enumerate(0); var drivers = GetDevices(); foreach (ControlDevice controlDevice in drivers) { DeviceAdded?.Invoke(this, new Events.DeviceChangeEventArgs(controlDevice)); } }
private async void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args) { await Task.Run(() => { lock (__lockObj) { if (!string.IsNullOrEmpty(args.Name)) { var deviceExists = _deviceInformationList.Any(x => x.Name == args.Name); if (!deviceExists) { Log.Debug("New device detected"); Log.Debug("Name: " + args.Name + " ID: " + args.Id); DeviceAdded?.Invoke(this, new DeviceCollectionChangeEventArgs() { Device = new DeviceModel() { Id = args.Id, Name = args.Name } }); _deviceInformationList.Add(args); if (args.Name == "Bluno") { ConnectDevice(args.Id); StopWatcher(); } } else { Log.Debug("Device Updated"); Log.Debug("Name: " + args.Name + " ID: " + args.Id); DeviceRemoved?.Invoke(this, new DeviceCollectionChangeEventArgs() { Device = new DeviceModel() { Id = args.Id, Name = args.Name } }); DeviceAdded?.Invoke(this, new DeviceCollectionChangeEventArgs() { Device = new DeviceModel() { Id = args.Id, Name = args.Name } }); _deviceInformationList.Remove(_deviceInformationList.First(x => x.Name == args.Name)); _deviceInformationList.Add(args); } } } }); }
public GlimDevice FindOrCreate(string hostname) { var g = Find(hostname); if (null == g) { g = new GlimDevice(hostname); lock ( mList ) { mList.Add(g.HostName, g); } DeviceAdded?.Invoke(this, new DeviceAddedEventArgs(g)); } return(g); }
private void DeviceSetup() { foreach (var dd in addedDevices) { DeviceRemoved?.Invoke(this, new Events.DeviceChangeEventArgs(dd)); } var d = GetDevices(); foreach (ControlDevice controlDevice in d) { addedDevices.Add(controlDevice); DeviceAdded.Invoke(this, new Events.DeviceChangeEventArgs(controlDevice)); } }
public void AddDevice(int PID) { var supportedDevice = HIDDevices.First(x => x.PID == PID); SteelSeriesControlDevice device = new SteelSeriesControlDevice { LEDs = new ControlDevice.LedUnit[supportedDevice.NumberOfLeds], Driver = this, Name = supportedDevice.Name, DeviceType = supportedDevice.DeviceClass, ProductImage = supportedDevice.Image, HID = PID, SSDeviceType = supportedDevice.SteelSeriesDeviceType }; List <KeyValuePair <LedId, SteelSeriesLedId> > mp = supportedDevice.Mapping.ToList(); for (int i = 0; i < supportedDevice.NumberOfLeds; i++) { int ln = i; int kc = 2; SteelSeriesLedId tp = SteelSeriesLedId.ZoneOne; if (i < mp.Count) { ln = (int)mp[i].Key; kc = (int)mp[i].Value; tp = mp[i].Value; } device.LEDs[i] = new ControlDevice.LedUnit { LEDName = "LED " + i, Data = new SteelSeriesLedData { LEDNumber = ln, KeyCode = kc, ZoneName = tp.GetAPIName() } }; } DeviceAdded?.Invoke(this, new Events.DeviceChangeEventArgs(device)); foundDevices.Add(device); }
public void UpdateResource(TDevice device) { TResource resource; if (Resources.TryGetValue(device, out resource)) { if (NeedsUpdate) { FUpdateResourceFunc?.Invoke(Metadata, resource); } } else { FUpdateResourceFunc?.Invoke(Metadata, this[device]); DeviceAdded?.Invoke(this, device); } }
public void AddController(WLEDConfigModel.WLEDController controller) { WLEDControlDevice wled = new WLEDControlDevice(); wled.Name = controller.Name; wled.DeviceType = DeviceTypes.LedStrip; wled.Driver = this; wled.Has2DSupport = false; wled.LedCount = controller.LedCount; wled.ConnectedTo = controller.ControllerType.ToUpper(); wled.OverrideSupport = OverrideSupport.Self; if (wled.ConnectedTo == "ESP32") { wled.ProductImage = (Bitmap)System.Drawing.Image.FromStream(Esp32Stream); } else if (wled.ConnectedTo == "ESP8266") { wled.ProductImage = (Bitmap)System.Drawing.Image.FromStream(Esp8266Stream); } else { wled.ProductImage = (Bitmap)System.Drawing.Image.FromStream(GenericStream); } wled.Endpoint = new IPEndPoint(IPAddress.Parse(controller.IP), Int32.Parse(controller.Port)); List <ControlDevice.LedUnit> deviceLeds = new List <ControlDevice.LedUnit>(); for (int i = 0; i < controller.LedCount; i++) { ControlDevice.LedUnit newLed = new ControlDevice.LedUnit(); newLed.Data = new ControlDevice.LEDData(); newLed.Data.LEDNumber = i; deviceLeds.Add(newLed); } wled.LEDs = deviceLeds.ToArray(); DeviceAdded?.Invoke(wled, new Events.DeviceChangeEventArgs(wled)); deviceList.Add(wled); var helloWorld = new List <byte>() { 0x02, 0xFF, 0x00, 0xFF, 0x00 }; wled.Socket.SendTo(helloWorld.ToArray(), wled.Endpoint); }
IntPtr notificationHandle = IntPtr.Zero; // Дескриптор подписки. /// <summary> /// Процедура обработки оконных сообщений. /// </summary> /// <param name="m">Структура, описывающая сообщения.</param> protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == DeviceNotificator.WmDevicechange) // сообщение - изменился состав устройств. { EventArgs e = new EventArgs(); if ((int)m.WParam == DeviceNotificator.DbtDevicearrival) // добавилось новое? { DeviceAdded?.Invoke(this, e); DeviceListChanged?.Invoke(this, e); } else if ((int)m.WParam == DeviceNotificator.DbtDeviceremovecomplete) // удалили старое? { DeviceRemoved?.Invoke(this, e); DeviceListChanged?.Invoke(this, e); } } }
public async Task RequestDeviceList() { var deviceList = (await SendMessage(new RequestDeviceList(nextMsgId))) as DeviceList; if (deviceList.Devices == null) { return; } foreach (var d in deviceList.Devices) { if (!_devices.ContainsKey(d.DeviceIndex)) { var device = new ButtplugClientDevice(d); if (_devices.TryAdd(d.DeviceIndex, device)) { _owningDispatcher.Invoke(() => { DeviceAdded?.Invoke(this, new DeviceEventArgs(device, DeviceAction.ADDED)); }); } } } }
public void SorterCallback(UIntPtr buf, int buf_length) { Span <byte> byteArray; unsafe { byteArray = new Span <byte>(buf.ToPointer(), buf_length); } var server_message = ButtplugFFIServerMessage.Parser.ParseFrom(byteArray.ToArray()); if (server_message.Id > 0) { _messageSorter.CheckMessage(server_message); } else if (server_message.Message.MsgCase == ButtplugFFIServerMessage.Types.FFIMessage.MsgOneofCase.ServerMessage) { if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.DeviceAdded) { var device_added_message = server_message.Message.ServerMessage.DeviceAdded; var device_handle = ButtplugFFI.SendCreateDevice(_clientHandle, device_added_message.Index); var attribute_dict = new Dictionary <ServerMessage.Types.MessageAttributeType, ButtplugMessageAttributes>(); for (var i = 0; i < device_added_message.MessageAttributes.Count; ++i) { var attributes = device_added_message.MessageAttributes[i]; var device_message_attributes = new ButtplugMessageAttributes(attributes.FeatureCount, attributes.StepCount.ToArray(), attributes.Endpoints.ToArray(), attributes.MaxDuration.ToArray(), null, null); attribute_dict.Add(attributes.MessageType, device_message_attributes); } var device = new ButtplugClientDevice(_messageSorter, device_handle, device_added_message.Index, device_added_message.Name, attribute_dict); _devices.Add(device_added_message.Index, device); DeviceAdded.Invoke(this, new DeviceAddedEventArgs(device)); } else if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.DeviceRemoved) { var device_removed_message = server_message.Message.ServerMessage.DeviceRemoved; var device = _devices[device_removed_message.Index]; _devices.Remove(device_removed_message.Index); DeviceRemoved.Invoke(this, new DeviceRemovedEventArgs(device)); } else if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.Disconnect) { Connected = false; ServerDisconnect?.Invoke(this, null); } else if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.Error) { var errorMsg = server_message.Message.ServerMessage.Error; var error = ButtplugException.FromError(errorMsg); if (error is ButtplugPingException) { PingTimeout?.Invoke(this, null); } ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs(error)); } else if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.ScanningFinished) { ScanningFinished?.Invoke(this, null); } else { // We should probably do something here with unhandled events, but I'm not particularly sure what. I miss pattern matching. :( } } else { // We should probably do something here with unhandled events, but I'm not particularly sure what. I miss pattern matching. :( } }
protected virtual void OnDeviceAdded(Events.DeviceAddedEventArgs e) { DeviceAdded?.Invoke(this, e); }