Ejemplo n.º 1
0
        public override void Connect()
        {
            base.Connect();

            //
            // Callback to event
            //
            _notificationCallback = (client, target, motor, smallMotor, color) => FeedbackReceived?.Invoke(this,
                                                                                                           new DualShock4FeedbackReceivedEventArgs(motor, smallMotor,
                                                                                                                                                   new LightbarColor(color.Red, color.Green, color.Blue)));

            var error = ViGEmClient.vigem_target_ds4_register_notification(Client.NativeHandle, NativeHandle,
                                                                           _notificationCallback);

            switch (error)
            {
            case ViGEmClient.VIGEM_ERROR.VIGEM_ERROR_BUS_NOT_FOUND:
                throw new VigemBusNotFoundException();

            case ViGEmClient.VIGEM_ERROR.VIGEM_ERROR_INVALID_TARGET:
                throw new VigemInvalidTargetException();

            case ViGEmClient.VIGEM_ERROR.VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED:
                throw new VigemCallbackAlreadyRegisteredException();
            }
        }
Ejemplo n.º 2
0
        private void Ds4Notification(ViGemUm.VigemTarget target, byte largeMotor, byte smallMotor,
                                     ViGemUm.Ds4LightbarColor lightbarColor)
        {
            var color = new LightbarColor(lightbarColor.Red, lightbarColor.Green, lightbarColor.Blue);

            FeedbackReceived?.Invoke(this, new DualShock4FeedbackReceivedEventArgs(largeMotor, smallMotor, color));
        }
Ejemplo n.º 3
0
 protected override void ProcessMessage(MessageBase message)
 {
     if (message is XboxFeedbackResponse)
     {
         var feedbackMessage = message as XboxFeedbackResponse;
         FeedbackReceived?.Invoke(this, new XboxDeviceFeedbackReceivedEventArgs
         {
             SmallForceFeedback = feedbackMessage.SmallForceFeedback,
             BigForceFeedback   = feedbackMessage.BigForceFeedback,
         });
     }
 }
Ejemplo n.º 4
0
 protected override void ProcessMessage(MessageBase message)
 {
     if (message is InputDeviceInputResponse)
     {
         var feedbackMessage = message as InputDeviceInputResponse;
         FeedbackReceived?.Invoke(this, new InputDeviceFeedbackReceivedEventArgs
         {
             InputValues = feedbackMessage.Sources.Select(s => new InputDeviceSourceValue {
                 Id = s.Id, Value = s.Value
             }).ToList(),
             ForceFeedbacks = feedbackMessage.Targets.Select(t => new InputDeviceTargetValue {
                 Id = t.Id, Value = t.Value
             }).ToList(),
         });
     }
 }
Ejemplo n.º 5
0
        public override void Connect()
        {
            base.Connect();

            //
            // Callback to event
            //
            _notificationCallback = (client, target, largeMotor, smallMotor, number) =>
            {
                UserIndex = number;

                FeedbackReceived?.Invoke(this,
                                         new Xbox360FeedbackReceivedEventArgs(largeMotor, smallMotor, number));
            };

            var error = ViGEmClient.vigem_target_x360_register_notification(Client.NativeHandle, NativeHandle,
                                                                            _notificationCallback);

            switch (error)
            {
            case ViGEmClient.VIGEM_ERROR.VIGEM_ERROR_NONE:
                break;

            case ViGEmClient.VIGEM_ERROR.VIGEM_ERROR_BUS_NOT_FOUND:
                throw new VigemBusNotFoundException();

            case ViGEmClient.VIGEM_ERROR.VIGEM_ERROR_INVALID_TARGET:
                throw new VigemInvalidTargetException();

            case ViGEmClient.VIGEM_ERROR.VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED:
                throw new VigemCallbackAlreadyRegisteredException();

            default:
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 6
0
        public override void Connect()
        {
            base.Connect();

            //
            // Callback to event
            //
            _notificationCallback = (client, target, largeMotor, smallMotor, number) => FeedbackReceived?.Invoke(this,
                                                                                                                 new Xbox360FeedbackReceivedEventArgs(largeMotor, smallMotor, number));

            var error = ViGEmClient.vigem_target_x360_register_notification(Client.NativeHandle, NativeHandle,
                                                                            _notificationCallback);

            switch (error)
            {
            case VIGEM_ERROR.VIGEM_ERROR_BUS_NOT_FOUND:
            case VIGEM_ERROR.VIGEM_ERROR_INVALID_TARGET:
            case VIGEM_ERROR.VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED:
                throw new ViGEmException(error);
            }
        }
Ejemplo n.º 7
0
 private void XusbNotification(ViGemUm.VigemTarget target, byte largeMotor, byte smallMotor, byte ledNumber)
 {
     FeedbackReceived?.Invoke(this, new Xbox360FeedbackReceivedEventArgs(largeMotor, smallMotor, ledNumber));
 }
Ejemplo n.º 8
0
        public async Task CheckAsync()
        {
            var encoding = Encoding.ASCII;

            var certificate = Configuration.Certificate;

            var certificates = new X509CertificateCollection();

            certificates.Add(certificate);

            var client = new TcpClient();
            await client.ConnectAsync(Configuration.FeedbackHost, Configuration.FeedbackPort);

            var stream = new SslStream(
                client.GetStream(),
                true,
                (sender, cert, chain, sslErrs) => { return(true); },
                (sender, targetHost, localCerts, remoteCert, acceptableIssuers) => { return(certificate); });

            await stream.AuthenticateAsClientAsync(Configuration.FeedbackHost, certificates, System.Security.Authentication.SslProtocols.Tls, false);

            //Set up
            byte[] buffer = new byte[4096];
            int    recd   = 0;
            var    data   = new List <byte>();

            //Get the first feedback
            recd = stream.Read(buffer, 0, buffer.Length);

            //Continue while we have results and are not disposing
            while (recd > 0)
            {
                // Add the received data to a list buffer to work with (easier to manipulate)
                for (int i = 0; i < recd; i++)
                {
                    data.Add(buffer[i]);
                }

                //Process each complete notification "packet" available in the buffer
                while (data.Count >= (4 + 2 + 32)) // Minimum size for a valid packet
                {
                    var secondsBuffer     = data.GetRange(0, 4).ToArray();
                    var tokenLengthBuffer = data.GetRange(4, 2).ToArray();

                    // Get our seconds since epoch
                    // Check endianness and reverse if needed
                    if (BitConverter.IsLittleEndian)
                    {
                        Array.Reverse(secondsBuffer);
                    }

                    var seconds = BitConverter.ToInt32(secondsBuffer, 0);

                    //Add seconds since 1970 to that date, in UTC
                    var timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(seconds);

                    //flag to allow feedback times in UTC or local, but default is local
                    if (!Configuration.FeedbackTimeIsUTC)
                    {
                        timestamp = timestamp.ToLocalTime();
                    }

                    if (BitConverter.IsLittleEndian)
                    {
                        Array.Reverse(tokenLengthBuffer);
                    }

                    var tokenLength = BitConverter.ToInt16(tokenLengthBuffer, 0);

                    if (data.Count >= 4 + 2 + tokenLength)
                    {
                        var tokenBuffer = data.GetRange(6, tokenLength).ToArray();

                        var token = BitConverter.ToString(tokenBuffer).Replace("-", "").ToLower().Trim();

                        // Remove what we parsed from the buffer
                        data.RemoveRange(0, 4 + 2 + tokenLength);

                        // Raise the event to the consumer
                        FeedbackReceived?.Invoke(token, timestamp);
                    }
                    else
                    {
                        continue;
                    }
                }

                //Read the next feedback
                recd = stream.Read(buffer, 0, buffer.Length);
            }

            try
            {
#if NET45
                stream.Close();
#endif
                stream.Dispose();
            }
            catch
            {
            }

            try
            {
                client.Client.Shutdown(SocketShutdown.Both);
                client.Client.Dispose();
            }
            catch
            {
            }

#if NET45
            try
            {
                client.Close();
            }
            catch
            {
            }
#endif
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Handle an inbound message from a hub
 /// </summary>
 /// <param name="method">event name</param>
 /// <param name="message">message content</param>
 private void HandleFeedback(string feedback)
 {
     // raise an event to subscribers
     FeedbackReceived?.Invoke(this, new FeedbackReceivedEventArgs(feedback));
 }
Ejemplo n.º 10
0
        public void SetFeedback(double smallMotor, double bigMotor)
        {
            var mappedTargets = new List <InputDeviceTargetWithValue>(); // TODO complete mapping for targets

            FeedbackReceived?.Invoke(this, new InputDeviceFeedbackEventArgs(mappedTargets));
        }
Ejemplo n.º 11
0
 public void SetFeedback(double smallMotor, double bigMotor)
 {
     FeedbackReceived?.Invoke(this, new MappableDeviceFeedbackEventArgs(smallMotor, bigMotor));
 }