コード例 #1
0
ファイル: ScpHidReport.cs プロジェクト: zultharion/ScpServer
        /// <summary>
        ///     Checks if a given button state is engaged in the current packet.
        /// </summary>
        /// <param name="button">The DualShock button to question.</param>
        /// <returns>True if the button is pressed, false if the button is released.</returns>
        public IDsButtonState this[IDsButton button]
        {
            get
            {
                if (button is Ds3Button && Model == DsModel.DS3)
                {
                    var buttons =
                        (uint)((RawBytes[10] << 0) | (RawBytes[11] << 8) | (RawBytes[12] << 16) | (RawBytes[13] << 24));

                    return(new DsButtonState
                    {
                        IsPressed = (!button.Equals(Ds3Button.None)) && (buttons & button.Offset) == button.Offset
                    });
                }

                if (button is Ds4Button && Model == DsModel.DS4)
                {
                    var buttons =
                        (uint)((RawBytes[13] << 0) | (RawBytes[14] << 8) | (RawBytes[15] << 16));

                    return(new DsButtonState
                    {
                        IsPressed = (!button.Equals(Ds4Button.None)) && (buttons & button.Offset) == button.Offset
                    });
                }

                return(new DsButtonState());
            }
        }
コード例 #2
0
ファイル: ScpHidReport.cs プロジェクト: knives49/ScpToolkit
        /// <summary>
        ///     Checks if a given button state is engaged in the current packet.
        /// </summary>
        /// <param name="button">The DualShock button to question.</param>
        /// <returns>True if the button is pressed, false if the button is released.</returns>
        public IDsButtonState this[IDsButton button]
        {
            get
            {
                if (button is Ds3Button && Model == DsModel.DS3)
                {
                    var buttons =
                        (uint)((RawBytes[10] << 0) | (RawBytes[11] << 8) | (RawBytes[12] << 16) | (RawBytes[13] << 24));

                    _currentDsButtonState.IsPressed = !button.Equals(Ds3Button.None) &&
                                                      (buttons & button.Offset) == button.Offset;
                    _currentDsButtonState.Xbox360Button = _currentDsButtonState.IsPressed
                        ? button.Xbox360Button
                        : X360Button.None;

                    return(_currentDsButtonState);
                }

                if (button is Ds4Button && Model == DsModel.DS4)
                {
                    var buttons =
                        (uint)((RawBytes[13] << 0) | (RawBytes[14] << 8) | (RawBytes[15] << 16));

                    _currentDsButtonState.IsPressed = !button.Equals(Ds4Button.None) &&
                                                      (buttons & button.Offset) == button.Offset;
                    _currentDsButtonState.Xbox360Button = _currentDsButtonState.IsPressed
                        ? button.Xbox360Button
                        : X360Button.None;

                    return(_currentDsButtonState);
                }

                return(_currentDsButtonState);
            }
        }
コード例 #3
0
        /// <summary>
        ///     Applies button re-mapping to the supplied report.
        /// </summary>
        /// <param name="report">The report to manipulate.</param>
        public void Remap(ScpHidReport report)
        {
            // skip disabled mapping
            if (!IsEnabled)
            {
                return;
            }

            switch (MappingTarget.CommandType)
            {
            case CommandType.GamepadButton:
                foreach (var button in SourceButtons)
                {
                    // turbo is special, apply first
                    if (Turbo.IsEnabled)
                    {
                        Turbo.ApplyOn(report, button);
                    }

                    // get target button
                    IDsButton target = MappingTarget.CommandTarget as Ds3Button;
                    // if target is no valid button or none, skip setting it
                    if (target == null)
                    {
                        continue;
                    }

                    // if it's a DS4, translate button
                    if (report.Model == DsModel.DS4)
                    {
                        target = Ds4Button.Buttons.First(b => b.Name.Equals(target.Name));
                    }

                    // if original isn't pressed we can ignore
                    if (!report[button].IsPressed)
                    {
                        continue;
                    }

                    // unset original button
                    report.Unset(button);
                    // set new button
                    report.Set(target);
                }
                break;
            }
        }
コード例 #4
0
 public DSButton(IDsButton parDs3Button, IDsButton parDs4Button)
 {
     m_DS3 = parDs3Button;
     m_DS4 = parDs4Button;
 }
コード例 #5
0
ファイル: PadSettings.cs プロジェクト: TheLastRar/SCP2vJoy
 public DSButton(IDsButton parDs3Button, IDsButton parDs4Button)
 {
     m_DS3 = parDs3Button;
     m_DS4 = parDs4Button;
 }
コード例 #6
0
ファイル: ScpHidReport.cs プロジェクト: CheesyKek/ScpToolkit
 /// <summary>
 ///     Sets the status of a digital (two-state) button to 'released'.
 /// </summary>
 /// <param name="button">The button of the current report to unset.</param>
 public void Unset(IDsButton button)
 {
     Set(button, false);
 }
コード例 #7
0
ファイル: ScpHidReport.cs プロジェクト: CheesyKek/ScpToolkit
 /// <summary>
 ///     Sets the status of a digital (two-state) button.
 /// </summary>
 /// <param name="button">The button of the current report to manipulate.</param>
 /// <param name="value">True to set the button as pressed, false to set the button as released.</param>
 public void Set(IDsButton button, bool value = true)
 {
     button.ToggleBit(ref RawBytes[button.ArrayIndex], value);
 }
コード例 #8
0
ファイル: ScpHidReport.cs プロジェクト: CheesyKek/ScpToolkit
        /// <summary>
        ///     Checks if a given button state is engaged in the current packet.
        /// </summary>
        /// <param name="button">The DualShock button to question.</param>
        /// <returns>True if the button is pressed, false if the button is released.</returns>
        public IDsButtonState this[IDsButton button]
        {
            get
            {
                if (button is Ds3Button && Model == DsModel.DS3)
                {
                    var buttons =
                        (uint) ((RawBytes[10] << 0) | (RawBytes[11] << 8) | (RawBytes[12] << 16) | (RawBytes[13] << 24));

                    _currentDsButtonState.IsPressed = !button.Equals(Ds3Button.None) &&
                                                      (buttons & button.Offset) == button.Offset;
                    _currentDsButtonState.Xbox360Button = _currentDsButtonState.IsPressed
                        ? button.Xbox360Button
                        : X360Button.None;

                    return _currentDsButtonState;
                }

                if (button is Ds4Button && Model == DsModel.DS4)
                {
                    var buttons =
                        (uint) ((RawBytes[13] << 0) | (RawBytes[14] << 8) | (RawBytes[15] << 16));

                    _currentDsButtonState.IsPressed = !button.Equals(Ds4Button.None) &&
                                                      (buttons & button.Offset) == button.Offset;
                    _currentDsButtonState.Xbox360Button = _currentDsButtonState.IsPressed
                        ? button.Xbox360Button
                        : X360Button.None;

                    return _currentDsButtonState;
                }

                return _currentDsButtonState;
            }
        }
コード例 #9
0
        /// <summary>
        ///     Applies turbo algorithm for a specified <see cref="IDsButton" /> on a given <see cref="ScpHidReport" />.
        /// </summary>
        /// <param name="report">The HID report to manipulate.</param>
        /// <param name="button">The button to trigger turbo on.</param>
        public void ApplyOn(ScpHidReport report, IDsButton button)
        {
            // button type must match model, madness otherwise!
            if ((report.Model != DsModel.DS3 || !(button is Ds3Button)) &&
                (report.Model != DsModel.DS4 || !(button is Ds4Button))) return;

            // if button got released...
            if (_isActive && !report[button].IsPressed)
            {
                // ...disable, reset and return
                _isActive = false;
                _delayedFrame.Reset();
                _engagedFrame.Reset();
                _releasedFrame.Reset();
                return;
            }

            // if turbo is enabled and button is pressed...
            if (!_isActive && report[button].IsPressed)
            {
                // ...start calculating the activation delay...
                if (!_delayedFrame.IsRunning) _delayedFrame.Restart();

                // ...if we are still activating, don't do anything
                if (_delayedFrame.ElapsedMilliseconds < Delay) return;

                // time to activate!
                _isActive = true;
                _delayedFrame.Reset();
            }

            // if the button was released...
            if (!report[button].IsPressed)
            {
                // ...restore default states and skip processing
                _isActive = false;
                return;
            }

            // reset engaged ("keep pressed") time frame...
            if (!_engagedFrame.IsRunning) _engagedFrame.Restart();

            // ...do not change state while within frame and button is still pressed, then skip
            if (_engagedFrame.ElapsedMilliseconds < Interval && report[button].IsPressed) return;

            // reset released time frame ("forecefully release") for button
            if (!_releasedFrame.IsRunning) _releasedFrame.Restart();

            // while we're still within the released time frame...
            if (_releasedFrame.ElapsedMilliseconds < Release)
            {
                // ...re-set the button state to released
                report.Unset(button);
            }
            else
            {
                // all frames passed, reset and start over
                _isActive = false;

                _delayedFrame.Stop();
                _engagedFrame.Stop();
                _releasedFrame.Stop();
            }
        }
コード例 #10
0
        /// <summary>
        ///     Applies turbo algorithm for a specified <see cref="IDsButton" /> on a given <see cref="ScpHidReport" />.
        /// </summary>
        /// <param name="report">The HID report to manipulate.</param>
        /// <param name="button">The button to trigger turbo on.</param>
        public void ApplyOn(ScpHidReport report, IDsButton button)
        {
            // button type must match model, madness otherwise!
            if ((report.Model != DsModel.DS3 || !(button is Ds3Button)) &&
                (report.Model != DsModel.DS4 || !(button is Ds4Button)))
            {
                return;
            }

            // if button got released...
            if (_isActive && !report[button].IsPressed)
            {
                // ...disable, reset and return
                _isActive = false;
                _delayedFrame.Reset();
                _engagedFrame.Reset();
                _releasedFrame.Reset();
                return;
            }

            // if turbo is enabled and button is pressed...
            if (!_isActive && report[button].IsPressed)
            {
                // ...start calculating the activation delay...
                if (!_delayedFrame.IsRunning)
                {
                    _delayedFrame.Restart();
                }

                // ...if we are still activating, don't do anything
                if (_delayedFrame.ElapsedMilliseconds < Delay)
                {
                    return;
                }

                // time to activate!
                _isActive = true;
                _delayedFrame.Reset();
            }

            // if the button was released...
            if (!report[button].IsPressed)
            {
                // ...restore default states and skip processing
                _isActive = false;
                return;
            }

            // reset engaged ("keep pressed") time frame...
            if (!_engagedFrame.IsRunning)
            {
                _engagedFrame.Restart();
            }

            // ...do not change state while within frame and button is still pressed, then skip
            if (_engagedFrame.ElapsedMilliseconds < Interval && report[button].IsPressed)
            {
                return;
            }

            // reset released time frame ("forecefully release") for button
            if (!_releasedFrame.IsRunning)
            {
                _releasedFrame.Restart();
            }

            // while we're still within the released time frame...
            if (_releasedFrame.ElapsedMilliseconds < Release)
            {
                // ...re-set the button state to released
                report.Unset(button);
            }
            else
            {
                // all frames passed, reset and start over
                _isActive = false;

                _delayedFrame.Stop();
                _engagedFrame.Stop();
                _releasedFrame.Stop();
            }
        }
コード例 #11
0
ファイル: ScpHidReport.cs プロジェクト: zultharion/ScpServer
 /// <summary>
 ///     Sets the status of a digital (two-state) button to 'released'.
 /// </summary>
 /// <param name="button">The button of the current report to unset.</param>
 public void Unset(IDsButton button)
 {
     Set(button, false);
 }
コード例 #12
0
ファイル: ScpHidReport.cs プロジェクト: zultharion/ScpServer
 /// <summary>
 ///     Sets the status of a digital (two-state) button.
 /// </summary>
 /// <param name="button">The button of the current report to manipulate.</param>
 /// <param name="value">True to set the button as pressed, false to set the button as released.</param>
 public void Set(IDsButton button, bool value = true)
 {
     button.ToggleBit(ref RawBytes[button.ArrayIndex], value);
 }
コード例 #13
0
ファイル: ScpHidReport.cs プロジェクト: r15ch13/ScpServer
        /// <summary>
        ///     Checks if a given button state is engaged in the current packet.
        /// </summary>
        /// <param name="button">The DualShock button to question.</param>
        /// <returns>True if the button is pressed, false if the button is released.</returns>
        public IDsButtonState this[IDsButton button]
        {
            get
            {
                if (button is Ds3Button && Model == DsModel.DS3)
                {
                    var buttons =
                        (uint) ((RawBytes[10] << 0) | (RawBytes[11] << 8) | (RawBytes[12] << 16) | (RawBytes[13] << 24));

                    return new DsButtonState
                    {
                        IsPressed = (!button.Equals(Ds3Button.None)) && (buttons & button.Offset) == button.Offset
                    };
                }

                if (button is Ds4Button && Model == DsModel.DS4)
                {
                    var buttons =
                        (uint) ((RawBytes[13] << 0) | (RawBytes[14] << 8) | (RawBytes[15] << 16));

                    return new DsButtonState
                    {
                        IsPressed = (!button.Equals(Ds4Button.None)) && (buttons & button.Offset) == button.Offset
                    };
                }

                return new DsButtonState();
            }
        }
コード例 #14
0
        /// <summary>
        ///     Applies button re-mapping to the supplied report.
        /// </summary>
        /// <param name="report">The report to manipulate.</param>
        public void Remap(ScpHidReport report)
        {
            // skip disabled mapping
            if (!IsEnabled)
            {
                return;
            }

            switch (MappingTarget.CommandType)
            {
            case CommandType.GamepadButton:
                foreach (var button in SourceButtons)
                {
                    // turbo is special, apply first
                    if (Turbo.IsEnabled)
                    {
                        Turbo.ApplyOn(report, button);
                    }

                    // get target button
                    IDsButton target = MappingTarget.CommandTarget as Ds3Button;
                    // if target is no valid button or none, skip setting it
                    if (target == null)
                    {
                        continue;
                    }

                    // if it's a DS4, translate button
                    if (report.Model == DsModel.DS4)
                    {
                        target = Ds4Button.Buttons.First(b => b.Name.Equals(target.Name));
                    }

                    // if original isn't pressed we can ignore
                    if (!report.HidReport[button].IsPressed)
                    {
                        continue;
                    }

                    // unset original button
                    //TODO: zzz rewrite mapper
                    ((HidReport.Core.HidReport)report.HidReport).Unset(button);
                    // set new button
                    //((HidReport.Core.HidReport)report.HidReport).Set(target);
                }
                break;

            case CommandType.Keystrokes:
                foreach (var button in SourceButtons)
                {
                    var target = (VirtualKeyCode)Enum.ToObject(typeof(VirtualKeyCode), MappingTarget.CommandTarget);

                    if (report.HidReport[button].IsPressed)
                    {
                        VirtualInput.Keyboard.KeyDown(target);
                    }
                    else
                    {
                        VirtualInput.Keyboard.KeyUp(target);
                    }
                }
                break;
            }
        }
コード例 #15
0
ファイル: DualShockProfile.cs プロジェクト: r15ch13/ScpServer
        public void ApplyOn(ScpHidReport report, IDsButton button)
        {
            if ((report.Model != DsModel.DS3 || !(button is Ds3Button)) &&
                (report.Model != DsModel.DS4 || !(button is Ds4Button))) return;

            // if button got released...
            if (_isActive && !report[button].IsPressed)
            {
                // ...disable, reset and return
                _isActive = false;
                _delayedFrame.Reset();
                _engagedFrame.Reset();
                _releasedFrame.Reset();
                return;
            }

            // if turbo is enabled and button is pressed...
            if (!_isActive && report[button].IsPressed)
            {
                if (!_delayedFrame.IsRunning) _delayedFrame.Restart();

                if (_delayedFrame.ElapsedMilliseconds < Delay) return;

                // time to activate!
                _isActive = true;
                _delayedFrame.Reset();
            }

            // if the button was released...
            if (!report[button].IsPressed)
            {
                // ...restore default states
                _isActive = false;
                return;
            }

            if (!_engagedFrame.IsRunning) _engagedFrame.Restart();

            if (_engagedFrame.ElapsedMilliseconds < Interval && report[button].IsPressed) return;

            if (!_releasedFrame.IsRunning) _releasedFrame.Restart();

            if (_releasedFrame.ElapsedMilliseconds < Release)
            {
                report.Unset(button);
            }
            else
            {
                _isActive = false;

                _delayedFrame.Stop();
                _engagedFrame.Stop();
                _releasedFrame.Stop();
            }
        }