Beispiel #1
0
        private void Change(int deviceId, int controlOrPitch, int value)
        {
            // Redraw UI etc.

            JoystickControl joystickControl = _joystickControls.SingleOrDefault(x => x.Mapping != null && (x.Mapping.DeviceId == deviceId && x.Mapping.ControlNumber == controlOrPitch));

            if (_currentDeviceId != deviceId || _currentControlId != controlOrPitch)
            {
                _currentDeviceId          = deviceId;
                _currentControlId         = controlOrPitch;
                lblMidiDevice.Text        = "MIDI Device: " + InputDevice.InstalledDevices[deviceId].Name;
                lblMidiControlNumber.Text = "Control #: " + controlOrPitch;

                if (joystickControl != null)
                {
                    radioTypeButton.Checked = joystickControl.IsButton;
                    radioTypeAxis.Checked   = !joystickControl.IsButton;
                    btnUnmap.Enabled        = true;
                }
                else
                {
                    radioTypeAxis.Checked = radioTypeButton.Checked = false;
                    btnUnmap.Enabled      = false;
                }
            }
            progessMidiData.Value = (value + 1);
            progessMidiData.Value = value;

            if (joystickControl != null)
            {
                UpdateJoystick(joystickControl, value);
            }
        }
Beispiel #2
0
 private void UpdateJoystick(JoystickControl joystickControl, int value)
 {
     if (joystickControl.IsButton == false)
     {
         var percentage = value / 127.0f;
         long min = 0, max = 0;
         var axisVal = (int)(percentage * _maxValues[joystickControl.HidUsage]);
         switch (joystickControl.HidUsage)
         {
             case HID_USAGES.HID_USAGE_X:
                 _state.AxisX = axisVal;
                 break;
             case HID_USAGES.HID_USAGE_Y:
                 _state.AxisY = axisVal;
                 break;
             case HID_USAGES.HID_USAGE_Z:
                 _state.AxisZ = axisVal;
                 break;
             case HID_USAGES.HID_USAGE_RX:
                 _state.AxisXRot = axisVal;
                 break;
             case HID_USAGES.HID_USAGE_RY:
                 _state.AxisYRot = axisVal;
                 break;
             case HID_USAGES.HID_USAGE_RZ:
                 _state.AxisZRot = axisVal;
                 break;
             case HID_USAGES.HID_USAGE_SL0:
                 _state.Slider = axisVal;
                 break;
             case HID_USAGES.HID_USAGE_SL1:
                 _state.Dial = axisVal;
                 break;
             case HID_USAGES.HID_USAGE_WHL:
                 _state.Wheel = axisVal;
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     }
     else
     {
         var pressed = value > 0;
         if (pressed)
             _state.Buttons |= (uint)(1 << joystickControl.ButtonNumber);
         else
             _state.Buttons &= ~(uint)(1 << joystickControl.ButtonNumber);
     }
 }
Beispiel #3
0
        private void UpdateJoystick(JoystickControl joystickControl, int value)
        {
            if (joystickControl.IsButton == false)
            {
                var  percentage = value / 127.0f;
                long min = 0, max = 0;
                var  axisVal = (int)(percentage * _maxValues[joystickControl.HidUsage]);
                switch (joystickControl.HidUsage)
                {
                case HID_USAGES.HID_USAGE_X:
                    _state.AxisX = axisVal;
                    break;

                case HID_USAGES.HID_USAGE_Y:
                    _state.AxisY = axisVal;
                    break;

                case HID_USAGES.HID_USAGE_Z:
                    _state.AxisZ = axisVal;
                    break;

                case HID_USAGES.HID_USAGE_RX:
                    _state.AxisXRot = axisVal;
                    break;

                case HID_USAGES.HID_USAGE_RY:
                    _state.AxisYRot = axisVal;
                    break;

                case HID_USAGES.HID_USAGE_RZ:
                    _state.AxisZRot = axisVal;
                    break;

                case HID_USAGES.HID_USAGE_SL0:
                    _state.Slider = axisVal;
                    break;

                case HID_USAGES.HID_USAGE_SL1:
                    _state.Dial = axisVal;
                    break;

                case HID_USAGES.HID_USAGE_WHL:
                    _state.Wheel = axisVal;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                var pressed = value > 0;
                switch (joystickControl.ButtonNumber / 32) //Each button bank in vJoy supports 32 buttons, so divide the button number by 32 to figure out which bank it is
                {
                case 0:                                    //Original bank, Buttons
                    if (pressed)
                    {
                        _state.Buttons |= (uint)(1 << (joystickControl.ButtonNumber % 32));
                    }
                    else
                    {
                        _state.Buttons &= ~(uint)(1 << (joystickControl.ButtonNumber % 32));
                    }
                    break;

                case 1:         //First extended bank, ButtonsEx1
                    if (pressed)
                    {
                        _state.ButtonsEx1 |= (uint)(1 << (joystickControl.ButtonNumber % 32));
                    }
                    else
                    {
                        _state.ButtonsEx1 &= ~(uint)(1 << (joystickControl.ButtonNumber % 32));
                    }
                    break;

                case 2:         //Second extended bank, ButtonsEx2
                    if (pressed)
                    {
                        _state.ButtonsEx2 |= (uint)(1 << (joystickControl.ButtonNumber % 32));
                    }
                    else
                    {
                        _state.ButtonsEx2 &= ~(uint)(1 << (joystickControl.ButtonNumber % 32));
                    }
                    break;

                case 3:         //Third extended bank, ButtonsEx3
                    if (pressed)
                    {
                        _state.ButtonsEx3 |= (uint)(1 << (joystickControl.ButtonNumber % 32));
                    }
                    else
                    {
                        _state.ButtonsEx3 &= ~(uint)(1 << (joystickControl.ButtonNumber % 32));
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }