Esempio n. 1
0
        private void HandleMessage(ButtplugMessage message)
        {
            var callback = GetPromise(message.Id);

            if (callback != null)
            {
                callback.SetResult(message);
            }
            else
            {
                if (message is DeviceAdded)
                {
                    DeviceAdded added = (DeviceAdded)message;
                    Debug.WriteLine($"Device Added: {added.DeviceName} [{added.DeviceIndex}]");
                    AddDevice(added.DeviceName, added.DeviceIndex);
                }
                else if (message is DeviceRemoved)
                {
                    DeviceRemoved removed = (DeviceRemoved)message;
                    Debug.WriteLine($"Device Removed: [{removed.DeviceIndex}]");
                    RemoveDevice(removed.DeviceIndex);
                }
                else
                {
                    Debug.WriteLine("Unknown messageId");
                }
            }
        }
Esempio n. 2
0
 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));
             }
         }
     }
 }
Esempio n. 3
0
        private void DeviceAddedHandler(object aObj, DeviceAddedEventArgs aEvent)
        {
            // Devices can be turned off by the time they get to this point, at which point they end up null. Make sure the device isn't null.
            if (aEvent.Device == null)
            {
                return;
            }

            var duplicates = from x in _devices
                             where x.Value.Identifier == aEvent.Device.Identifier
                             select x;

            if (duplicates.Any() && (duplicates.Count() > 1 || duplicates.First().Value.IsConnected))
            {
                _bpLogger.Debug($"Already have device {aEvent.Device.Name} in Devices list");
                return;
            }

            // If we get to 4 billion devices connected, this may be a problem.
            var deviceIndex = duplicates.Any() ? duplicates.First().Key : (uint)Interlocked.Increment(ref _deviceIndexCounter);

            _bpLogger.Info((duplicates.Any() ? "Re-" : string.Empty) + $"Adding Device {aEvent.Device.Name} at index {deviceIndex}");

            _devices[deviceIndex]        = aEvent.Device;
            aEvent.Device.DeviceRemoved += DeviceRemovedHandler;
            var msg = new DeviceAdded(deviceIndex, aEvent.Device.Name, GetAllowedMessageTypesAsStrings(aEvent.Device).ToArray());

            DeviceMessageReceived?.Invoke(this, new MessageReceivedEventArgs(msg));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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));
                        });
                    }
                }
            }
        }
Esempio n. 7
0
        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));
            }
        }
Esempio n. 8
0
        public void TestDeviceAddedCmdVersion1()
        {
            void CheckMsg(DeviceAdded aMsg)
            {
                aMsg.DeviceIndex.Should().Be(2);
                aMsg.Id.Should().Be(0);
                aMsg.DeviceName.Should().Be("testDev");
                aMsg.DeviceMessages.Count.Should().Be(2);
                aMsg.DeviceMessages.Keys.Should().Contain(new[] { "StopDeviceCmd", "VibrateCmd" });
                aMsg.DeviceMessages["VibrateCmd"].FeatureCount.Should().Be(1);
            }

            var msg = new DeviceAdded(2, "testDev", new Dictionary <string, MessageAttributes>
            {
                { "StopDeviceCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes()
                  {
                      FeatureCount = 1
                  } },
            });

            CheckMsg(msg);
            var msgSchemaV1 = CheckParsedVersion <DeviceAdded>(msg, 1,
                                                               "[{\"DeviceAdded\":{\"DeviceName\":\"testDev\",\"DeviceMessages\":{\"StopDeviceCmd\":{},\"VibrateCmd\":{\"FeatureCount\":1}},\"DeviceIndex\":2,\"Id\":0}}]");

            CheckMsg(msgSchemaV1);
        }
Esempio n. 9
0
 /// <summary>
 /// A device has been added.
 /// </summary>
 void OnDeviceAdded(object sender, EventArgs <AndroidDevice> e)
 {
     if (InvokeRequired)
     {
         Invoke(new EventHandler <EventArgs <AndroidDevice> >(OnDeviceAdded), sender, e);
     }
     else
     {
         var ui         = TaskScheduler.FromCurrentSynchronizationContext();
         var createTask = Task.Factory.StartNew(() => new AndroidDeviceItem(e.Data));
         createTask.ContinueWith(x => {
             if (x.Status == TaskStatus.RanToCompletion)
             {
                 RemoveItemsBySerial(e.Data.Serial);
                 var item = new AndroidDeviceItem(e.Data);
                 tvList.Items.Add(item);
                 SetIsCompatible(item);
                 ReloadList();
                 if (UserPreferences.Preferences.PreferredDeviceSerial == item.Serial)
                 {
                     Select(item.Device);
                 }
                 UpdateNoDevicesItem();
                 DeviceAdded.Fire(this, e);
             }
         }, ui);
     }
 }
Esempio n. 10
0
        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));
                    }
                }
            }
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
 /// <summary>
 /// New devices found.
 /// </summary>
 private void CallBack(List <AndroidDevice> list)
 {
     lock (devicesLock)
     {
         // Look for removed devices
         var removed = devices.Where(x => list.All(y => y.Serial != x.Serial)).ToList();
         foreach (var device in removed)
         {
             devices.Remove(device);
             DeviceRemoved.Fire(this, new EventArgs <AndroidDevice>(device));
         }
         // Look for added or changed devices
         foreach (var device in list)
         {
             var serial   = device.Serial;
             var existing = devices.FirstOrDefault(x => x.Serial == serial);
             if (existing == null)
             {
                 // Device added
                 devices.Add(device);
                 DeviceAdded.Fire(this, new EventArgs <AndroidDevice>(device));
             }
             else if (existing.DeviceState != device.DeviceState)
             {
                 // State changed
                 devices.Remove(existing);
                 devices.Add(device);
                 DeviceStateChanged.Fire(this, new EventArgs <AndroidDevice>(device));
             }
         }
         receivedInitialUpdate = true;
         Monitor.PulseAll(devicesLock);
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Raises the DeviceAdded event.
 /// </summary>
 /// <param name="e">The event arguments.</param>
 protected virtual void OnDeviceAdded(DeviceAddedEventArgs e)
 {
     if (DeviceAdded != null)
     {
         DeviceAdded.GetInvocationList().InvokeEventGUIThreadSafe(this, e);
     }
 }
Esempio n. 14
0
 protected async virtual void OnDeviceAdded(BTInitEventArgs e)
 {
     await mainPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate
     {
         DeviceAdded?.Invoke(this, e);
     });
 }
Esempio n. 15
0
        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;
                    }
                }
            });
        }
Esempio n. 16
0
        public void ListenForDevices()
        {
            var subscription = DeviceLocator
                               .FindReceiversContinuous()
                               .Subscribe(d => DeviceAdded?.Invoke(this, new DeviceAddedArgs(d)));

            _subscriptions.Add(subscription);
        }
Esempio n. 17
0
        /// <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;
            }
        }
Esempio n. 18
0
        public void Configure(DriverDetails driverDetails)
        {
            var drivers = GetDevices();

            foreach (ControlDevice controlDevice in drivers)
            {
                DeviceAdded?.Invoke(this, new Events.DeviceChangeEventArgs(controlDevice));
            }
        }
Esempio n. 19
0
        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));
            }
        }
        /// <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;
                }
            }
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        public void TestDeviceAddedCmd()
        {
            var msg = new DeviceAdded(2, "testDev", new Dictionary <string, MessageAttributes>
            {
                { "StopDeviceCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes()
                  {
                      FeatureCount = 1
                  } },
            });

            Assert.AreEqual(2, msg.DeviceIndex);
            Assert.AreEqual(0, msg.Id);
            Assert.AreEqual("testDev", msg.DeviceName);
            Assert.AreEqual(2, msg.DeviceMessages.Count);

            var str1 = _parser.Serialize(msg, 1);

            Assert.AreEqual(
                "[{\"DeviceAdded\":{\"DeviceName\":\"testDev\",\"DeviceMessages\":{\"StopDeviceCmd\":{},\"VibrateCmd\":{\"FeatureCount\":1}},\"DeviceIndex\":2,\"Id\":0}}]",
                str1);

            var msgs = _parser.Deserialize(str1);

            Assert.AreEqual(1, msgs.Length);
            Assert.True(msgs[0] is DeviceAdded);
            var msg1 = (DeviceAdded)msgs[0];

            Assert.AreEqual(2, msg1.DeviceIndex);
            Assert.AreEqual(0, msg1.Id);
            Assert.AreEqual("testDev", msg1.DeviceName);
            Assert.AreEqual(2, msg1.DeviceMessages.Count);
            Assert.Contains("StopDeviceCmd", msg1.DeviceMessages.Keys);
            Assert.Contains("VibrateCmd", msg1.DeviceMessages.Keys);

            var str0 = _parser.Serialize(msg, 0);

            Assert.AreEqual(
                "[{\"DeviceAdded\":{\"DeviceName\":\"testDev\",\"DeviceMessages\":[\"StopDeviceCmd\",\"VibrateCmd\"],\"DeviceIndex\":2,\"Id\":0}}]",
                str0);

            msgs = _parser.Deserialize(str0);
            Assert.AreEqual(1, msgs.Length);
            Assert.True(msgs[0] is DeviceAddedVersion0);
            var msg0 = (DeviceAddedVersion0)msgs[0];

            Assert.AreEqual(2, msg0.DeviceIndex);
            Assert.AreEqual(0, msg0.Id);
            Assert.AreEqual("testDev", msg0.DeviceName);
            Assert.AreEqual(2, msg0.DeviceMessages.Length);
            Assert.Contains("StopDeviceCmd", msg0.DeviceMessages);
            Assert.Contains("VibrateCmd", msg0.DeviceMessages);
        }
Esempio n. 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceAddedVersion0"/> class. Downgrade constructor, for creating a <see cref="DeviceAddedVersion0"/> from a <see cref="DeviceAdded"/>
        /// </summary>
        /// <param name="aMsg"><see cref="DeviceAdded"/> Message to convert to <see cref="DeviceAddedVersion0"/></param>
        public DeviceAddedVersion0(DeviceAdded aMsg)
            : base(aMsg.Id, aMsg.DeviceIndex)
        {
            DeviceName = aMsg.DeviceName;
            var tmp = new List <string>();

            foreach (var k in aMsg.DeviceMessages.Keys)
            {
                tmp.Add(k);
            }

            DeviceMessages = tmp.ToArray();
        }
        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);
        }
Esempio n. 27
0
        // 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));
        }
Esempio n. 28
0
        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));
            }
        }
Esempio n. 29
0
 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);
                 }
             }
         }
     });
 }
Esempio n. 30
0
        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);
        }