Exemplo n.º 1
0
 private static bool[] CaptureControllerInput()
 {
     try
     {
         if (DXJoystick == null || !DXJoystick.Acquire().IsSuccess)
         {
             return(null);
         }
         bool[]          flagArray    = new bool[256];
         DXJoystickState currentState = DXJoystick.GetCurrentState();
         flagArray = currentState.GetButtons();
         int length = flagArray.Length;
         if (currentState.X > 500)
         {
             flagArray[102] = true;
         }
         else if (currentState.X < -500)
         {
             flagArray[103] = true;
         }
         if (currentState.Y > 500)
         {
             flagArray[101] = true;
         }
         else if (currentState.Y < -500)
         {
             flagArray[100] = true;
         }
         return(flagArray);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 2
0
 private void _UpdateState()
 {
     if (IsAcquired)
     {
         JoystickState currentState = _device.GetCurrentState();
         foreach (JoystickInput input in Inputs)
         {
             input.Update(currentState);
         }
     }
 }
Exemplo n.º 3
0
        private void CaptureThread()
        {
            while (true)
            {
                try
                {
                    if (!this.isCapturing)
                    {
                        return;
                    }

                    if (gamepad.Acquire().IsFailure)
                    {
                        return;
                    }

                    if (gamepad.Poll().IsFailure)
                    {
                        return;
                    }

                    if (SlimDX.Result.Last.IsFailure)
                    {
                        return;
                    }

                    state = gamepad.GetCurrentState();

                    bool[] buttons = state.GetButtons();
                    //for (int i = 0; i < buttons.Length; i++)
                    //    if (buttons[i])
                    //        label2.Text = i.ToString();
                }
                catch (Exception ex) { }


                if (OnStateUpdated != null)
                {
                    OnStateUpdated(state);
                }

                try
                {
                    gamepad.Unacquire();
                }
                catch (Exception ex) { }

                Thread.Sleep(50);
            }
        }
Exemplo n.º 4
0
        void StickHandlerLogic(Joystick js)
        {
            //Enumerate a snapshot of the joystick
            JoystickState state = new JoystickState();

            tab_mate.Acquire();
            state = tab_mate.GetCurrentState();

            bool[] buttons = state.GetButtons();

            for (int button_num = 0; button_num < buttons.Length; button_num++)
            {
                if (buttons[button_num])
                {
                    Console.WriteLine("Button " + button_num + " was pressed!");
                }
            }
        }
        private void joystickTimer_Tick(object sender, EventArgs e)
        {
            JoystickState state = new JoystickState();

            state = stick.GetCurrentState();

            int leftStickX  = state.X;
            int leftStickY  = state.Y;
            int rightStickX = state.Z;
            int rightStickY = state.RotationZ;

            this.Text = state.RotationX.ToString();
            //stick simülasyonları
            radioButton1.Left = leftStickX + 100;  //left left-right
            radioButton1.Top  = leftStickY + 100;  //left up-down
            radioButton2.Left = rightStickX + 100; //right left-right
            radioButton2.Top  = rightStickY + 100; //right up-down

            if (state.IsPressed(10))
            {
                radioButton1.Checked = false;
            }
            else
            {
                radioButton1.Checked = true;
            }
            if (state.IsPressed(11))
            {
                radioButton2.Checked = false;
            }
            else
            {
                radioButton2.Checked = true;
            }



            if (state.IsPressed(9))
            {
                labelDegeri = "START";
            }
            if (state.IsPressed(8))
            {
                labelDegeri = "SELECT";
            }
            if (state.IsPressed(7))
            {
                labelDegeri = "R2";
            }
            if (state.IsPressed(6))
            {
                labelDegeri = "L2";
            }
            if (state.IsPressed(5))
            {
                labelDegeri = "R1";
            }
            if (state.IsPressed(4))
            {
                labelDegeri = "L1";
            }
            if (state.IsPressed(3))
            {
                labelDegeri = "Y";
            }
            if (state.IsPressed(2))
            {
                labelDegeri = "X";
            }
            if (state.IsPressed(1))
            {
                labelDegeri = "B";
            }
            if (state.IsPressed(0))
            {
                labelDegeri = "A";
            }
            label1.Text = labelDegeri;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Callback, получающий информацию об изменениях в состоянии контролов джойстика
        /// </summary>
        private void GetJoystickData()
        {
            while (true)
            {
                try
                {
                    lock (_threadLock)
                    {
                        if (_quitThread)
                        {
                            break;
                        }
                    }
                    if (!_joystickEvent.WaitOne(30))
                    {
                        continue;
                    }
                    _joystick.Poll();
                    var state   = _joystick.GetCurrentState();
                    var buttons = state.GetButtons();

                    lock (_dumpObjectLocker)
                    {
                        for (uint i = 0; i < _buttons.Length; i++)
                        {
                            if ((buttons[i] == _buttons[i]) && _dumpMode == false)
                            {
                                continue;
                            }

                            var ev = new ButtonEvent
                            {
                                Hardware =
                                    new ControlProcessorHardware
                                {
                                    ModuleType    = HardwareModuleType.Button,
                                    MotherBoardId = GetJoystickGuid(),
                                    ModuleId      = (uint)JoystickModule.Button,
                                    ControlId     = i
                                },
                                IsPressed = buttons[i]
                            };
                            _buttons[i] = buttons[i];
                            _incomingEvents.Enqueue(ev);
                        }
                        // ControlId начинается с 1
                        var axisIndex = 1;
                        if (_axis.Length >= axisIndex)
                        {
                            AddAxisEvent((uint)axisIndex, _axis[axisIndex++], state.X);
                        }
                        if (_axis.Length >= axisIndex)
                        {
                            AddAxisEvent((uint)axisIndex, _axis[axisIndex++], state.Y);
                        }
                        if (_axis.Length >= axisIndex)
                        {
                            AddAxisEvent((uint)axisIndex, _axis[axisIndex++], state.Z);
                        }
                        if (_axis.Length >= axisIndex)
                        {
                            AddAxisEvent((uint)axisIndex, _axis[axisIndex++], state.RotationX);
                        }
                        if (_axis.Length >= axisIndex)
                        {
                            AddAxisEvent((uint)axisIndex, _axis[axisIndex++], state.RotationY);
                        }
                        if (_axis.Length >= axisIndex)
                        {
                            AddAxisEvent((uint)axisIndex, _axis[axisIndex++], state.RotationZ);
                        }
                        var extAxis = state.GetSliders();
                        if (_axis.Length >= axisIndex && extAxis.Length >= 1)
                        {
                            AddAxisEvent((uint)axisIndex, _axis[axisIndex++], extAxis[0]);
                        }
                        if (_axis.Length >= axisIndex && extAxis.Length >= 2)
                        {
                            AddAxisEvent((uint)axisIndex, _axis[axisIndex++], extAxis[1]);
                        }
                        _dumpMode = false;
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Exemplo n.º 7
0
        public void ListenerThread()
        {
            SlimDX.DirectInput.JoystickState state;

            while (!stopThread && !Global.IsShuttingDown)
            {
                Thread.Sleep(2);
                state = gamepad.GetCurrentState();

                deviceWrapper.ax.Value = state.AccelerationX / 1000f;
                deviceWrapper.ay.Value = state.AccelerationY / 1000f;
                deviceWrapper.az.Value = state.AccelerationZ / 1000f;

                deviceWrapper.aax.Value = state.AngularAccelerationX / 1000f;
                deviceWrapper.aay.Value = state.AngularAccelerationY / 1000f;
                deviceWrapper.aaz.Value = state.AngularAccelerationZ / 1000f;

                deviceWrapper.avx.Value = state.AngularVelocityX / 1000f;
                deviceWrapper.avy.Value = state.AngularVelocityY / 1000f;
                deviceWrapper.avz.Value = state.AngularVelocityZ / 1000f;

                deviceWrapper.fx.Value = state.ForceX / 1000f;
                deviceWrapper.fy.Value = state.ForceY / 1000f;
                deviceWrapper.fz.Value = state.ForceZ / 1000f;

                deviceWrapper.rx.Value = state.RotationX / 1000f;
                deviceWrapper.ry.Value = state.RotationY / 1000f;
                deviceWrapper.rz.Value = state.RotationZ / 1000f;

                deviceWrapper.tx.Value = state.TorqueX / 1000f;
                deviceWrapper.ty.Value = state.TorqueY / 1000f;
                deviceWrapper.tz.Value = state.TorqueZ / 1000f;

                deviceWrapper.vx.Value = state.VelocityX / 1000f;
                deviceWrapper.vy.Value = state.VelocityY / 1000f;
                deviceWrapper.vz.Value = state.VelocityZ / 1000f;

                deviceWrapper.x.Value = state.X / 1000f;
                deviceWrapper.y.Value = state.Y / 1000f;
                deviceWrapper.z.Value = state.Z / 1000f;

                deviceWrapper.b1.Value  = state.IsPressed(0);
                deviceWrapper.b2.Value  = state.IsPressed(1);
                deviceWrapper.b3.Value  = state.IsPressed(2);
                deviceWrapper.b4.Value  = state.IsPressed(3);
                deviceWrapper.b5.Value  = state.IsPressed(4);
                deviceWrapper.b6.Value  = state.IsPressed(5);
                deviceWrapper.b7.Value  = state.IsPressed(6);
                deviceWrapper.b8.Value  = state.IsPressed(7);
                deviceWrapper.b9.Value  = state.IsPressed(8);
                deviceWrapper.b10.Value = state.IsPressed(9);
                deviceWrapper.b11.Value = state.IsPressed(10);
                deviceWrapper.b12.Value = state.IsPressed(11);
                deviceWrapper.b13.Value = state.IsPressed(12);
                deviceWrapper.b14.Value = state.IsPressed(13);
                deviceWrapper.b15.Value = state.IsPressed(14);
                deviceWrapper.b16.Value = state.IsPressed(15);
                deviceWrapper.b17.Value = state.IsPressed(16);
                deviceWrapper.b18.Value = state.IsPressed(17);
                deviceWrapper.b19.Value = state.IsPressed(18);
                deviceWrapper.b20.Value = state.IsPressed(19);

                var pov = (state.GetPointOfViewControllers()[0]);
                deviceWrapper.pov1up.Value    = (0 <= pov && pov <= 4500 || 31500 <= pov);
                deviceWrapper.pov1down.Value  = (13500 <= pov && pov <= 22500);
                deviceWrapper.pov1left.Value  = (22500 <= pov && pov <= 31500);
                deviceWrapper.pov1right.Value = (4500 <= pov && pov <= 13500);

                pov = (state.GetPointOfViewControllers()[1]);
                deviceWrapper.pov2up.Value    = (0 <= pov && pov <= 4500 || 31500 <= pov);
                deviceWrapper.pov2down.Value  = (13500 <= pov && pov <= 22500);
                deviceWrapper.pov2left.Value  = (22500 <= pov && pov <= 31500);
                deviceWrapper.pov2right.Value = (4500 <= pov && pov <= 13500);

                int[] sliders = state.GetSliders();
                if (sliders.Count() > 0)
                {
                    deviceWrapper.Slider1.Value = sliders[0] / 65535f;
                }
                if (sliders.Count() > 1)
                {
                    deviceWrapper.Slider1.Value = sliders[1] / 65535f;
                }
                if (sliders.Count() > 2)
                {
                    deviceWrapper.Slider1.Value = sliders[2] / 65535f;
                }
                if (sliders.Count() > 3)
                {
                    deviceWrapper.Slider1.Value = sliders[3] / 65535f;
                }
                if (sliders.Count() > 4)
                {
                    deviceWrapper.Slider1.Value = sliders[4] / 65535f;
                }
                if (sliders.Count() > 5)
                {
                    deviceWrapper.Slider1.Value = sliders[5] / 65535f;
                }
                if (sliders.Count() > 6)
                {
                    deviceWrapper.Slider1.Value = sliders[6] / 65535f;
                }
                if (sliders.Count() > 7)
                {
                    deviceWrapper.Slider1.Value = sliders[7] / 65535f;
                }
                if (sliders.Count() > 8)
                {
                    deviceWrapper.Slider1.Value = sliders[8] / 65535f;
                }
                if (sliders.Count() > 9)
                {
                    deviceWrapper.Slider1.Value = sliders[9] / 65535f;
                }
            }
        }
Exemplo n.º 8
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            for (int i = 0; i < reverserSwitchKeyTexts.Length; i++)
            {
                addKey(reverserSwitchKeyTexts[i]);
                keyCodeTable.Add(new int[2] {
                    0, i
                });
            }
            for (int i = 0; i < cabSwitchKeyTexts.Length; i++)
            {
                addKey(cabSwitchKeyTexts[i]);
                keyCodeTable.Add(new int[2] {
                    -1, i
                });
            }
            for (int i = 0; i < atsKeyTexts.Length; i++)
            {
                addKey(atsKeyTexts[i]);
                keyCodeTable.Add(new int[2] {
                    -2, i
                });
            }
            for (int i = 0; i < gameControlKeyTexts.Length; i++)
            {
                addKey(gameControlKeyTexts[i]);
                keyCodeTable.Add(new int[2] {
                    -3, i
                });
            }

            selectDropDownList(buttonSKeyList, DenshadeGoInterface.settings.ButtonS);
            selectDropDownList(buttonPKeyList, DenshadeGoInterface.settings.ButtonP);
            selectDropDownList(buttonAKeyList, DenshadeGoInterface.settings.ButtonA);
            selectDropDownList(buttonBKeyList, DenshadeGoInterface.settings.ButtonB);
            selectDropDownList(buttonCKeyList, DenshadeGoInterface.settings.ButtonC);

            bool added = false;
            List <SlimDX.DirectInput.Joystick> sticks = new List <SlimDX.DirectInput.Joystick>();

            foreach (DeviceInstance device in DenshadeGoInterface.input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    controllerList.Items.Add(device.ProductName);
                    Joystick stick = new SlimDX.DirectInput.Joystick(DenshadeGoInterface.input, device.InstanceGuid);
                    stick.Acquire();
                    int size = stick.GetCurrentState().GetButtons().Length;
                    buttonSize.Add(size);
                    if (device.ProductName.Equals(DenshadeGoInterface.settings.ControllerName))
                    {
                        added = true;
                        controllerList.SelectedIndex = controllerList.Items.Count - 1;
                        resizeUpDown(size);
                    }
                    stick.Unacquire();
                }
                catch (DirectInputException)
                {
                }
            }
            if (!added)
            {
                buttonSize.Add(128);
                controllerList.Items.Add(DenshadeGoInterface.settings.ControllerName);
                controllerList.SelectedIndex = controllerList.Items.Count - 1;
                resizeUpDown(128);
            }
            loadUpDown();
        }
        /// <summary>Initialises the joystick.</summary>
        private void InitialiseJoystick()
        {
            List<DI.Joystick> joysticks = GetAttachedJoysticks();

            if(ControllerIndex < joysticks.Count)
            {
                _joystick = joysticks[ControllerIndex];
                _joystickState = _joystick.GetCurrentState();

                System.Diagnostics.Debug.WriteLine("Using joystick: " + _joystick.Information.InstanceName);
            }

            _joystickConnected = (_joystickState != null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handler stavu gamepadu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gamepadHandle(object sender, EventArgs e)
        {
            if (enabled)
            {
                try
                {
                    gamepad.Acquire();
                }
                catch (DirectInputException)
                {
                    dinput.Dispose();
                    periodicChecker.Dispose();
                    errorObserver();
                }
                JoystickState stateNow = new JoystickState();
                stateNow = gamepad.GetCurrentState();
                bool[] buttons = stateNow.GetButtons();
                if ((Math.Abs(state.stickDirectMoveX - stateNow.X) > sensitivityJoystick || Math.Abs(state.stickDirectMoveY - stateNow.Y) > sensitivityJoystick) && stickDirectMoveObserver != null)
                {
                    state.stickDirectMoveX = stateNow.X;
                    state.stickDirectMoveY = stateNow.Y;
                    int x = state.stickDirectMoveX;
                    int y = state.stickDirectMoveY;
                    if (Math.Abs(x) < 10 && Math.Abs(y) < 10)
                    {
                        x = 0;
                        y = 0;
                    }
                    stickDirectMoveObserver(x, y);
                }

                if (state.moveDown != buttons[0] && buttonMoveDownObserver != null)
                {
                    buttonMoveDownObserver(buttons[0]);
                    state.moveDown = buttons[0];
                }

                if (state.moveUp != buttons[3] && buttonMoveUpObserver != null)
                {
                    buttonMoveUpObserver(buttons[3]);
                    state.moveUp = buttons[3];
                }

                if (state.narrow != buttons[2] && buttonNarrowObserver != null)
                {
                    buttonNarrowObserver(buttons[2]);
                    state.narrow = buttons[2];
                }

                if (state.widen != buttons[1] && buttonWidenObserver != null)
                {
                    buttonWidenObserver(buttons[1]);
                    state.widen = buttons[1];
                }

                if (state.defaultPosition != buttons[7] && buttonDefaultPositionObserver != null)
                {
                    buttonDefaultPositionObserver(buttons[7]);
                    state.defaultPosition = buttons[7];
                }

                if (state.rotateLeft != buttons[8] && buttonRotateLeftObserver != null)
                {
                    buttonRotateLeftObserver(buttons[8]);
                    state.rotateLeft = buttons[8];
                }

                if (state.rotateRight != buttons[9] && buttonRotateRightObserver != null)
                {
                    buttonRotateRightObserver(buttons[9]);
                    state.rotateRight = buttons[9];
                }

                if (state.stop != buttons[10] && buttonStopObserver != null)
                {
                    buttonStopObserver(buttons[10]);
                    state.stop = buttons[10];
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// handles all events that are trigged from joystick.
        /// </summary>
        private void pollingClient()
        {
            joystickDevice.Poll();
            JoystickState state = joystickDevice.GetCurrentState();

            if (previousState.X != state.X && !(state.X == beforePreviousState.X && previousState.X == beforeBeforePreviousState.X))
            {
                int status = calculateStateValue(axisX, state.X);

                onAxisX(status);
                log("pollingClient", "onAxisX(" + status + ")");
            }

            if (previousState.Y != state.Y && !(state.Y == beforePreviousState.Y && previousState.Y == beforeBeforePreviousState.Y))
            {
                int status = calculateStateValue(axisY, state.Y);

                onAxisY(status);
                log("pollingClient", "onAxisY(" + status + ")");
            }

            if (previousState.Z != state.Z && !(state.Z == beforePreviousState.Z && previousState.Z == beforeBeforePreviousState.Z))
            {
                int status = calculateStateValue(axisZ, state.Z);

                onAxisZ(status);
                log("pollingClient", "onAxisZ(" + status + ")");
            }

            /* Rotation */
            if (previousState.RotationX != state.RotationX && !(state.RotationX == beforePreviousState.RotationX && previousState.RotationX == beforeBeforePreviousState.RotationX))
            {
                int status = calculateStateValue(axisRx, state.RotationX);

                onAxisRx(status);
                log("pollingClient", "onAxisRx(" + status + ")");
            }

            if (previousState.RotationY != state.RotationY && !(state.RotationY == beforePreviousState.RotationY && previousState.RotationY == beforeBeforePreviousState.RotationY))
            {
                int status = calculateStateValue(axisRy, state.RotationY);

                onAxisRy(status);
                log("pollingClient", "onAxisRy(" + status + ")");
            }

            if (previousState.RotationZ != state.RotationZ && !(state.RotationZ == beforePreviousState.RotationZ && previousState.RotationZ == beforeBeforePreviousState.RotationZ))
            {
                int status = calculateStateValue(axisRz, state.RotationZ);

                onAxisRz(status);
                log("pollingClient", "onAxisRz(" + status + ")");
            }

            /* Extra axis */
            int[] axis                     = state.GetSliders();
            int[] previousAxis             = previousState.GetSliders();
            int[] beforePreviousAxis       = beforePreviousState.GetSliders();
            int[] beforeBeforePreviousAxis = beforeBeforePreviousState.GetSliders();
            for (int i = 0, c = axis.Length; i < c; i++)
            {
                if (previousAxis[i] != axis[i] && !(axis[i] == beforePreviousAxis[i] && previousAxis[i] == beforeBeforePreviousAxis[i]))
                {
                    int status = calculateStateValue(axisExtra, axis[i]);

                    onAxisExtra(i, status);
                    log("pollingClient", "onAxisExtra(" + i + "," + status + ")");
                }
            }

            /* All Buttons */
            bool[] buttons         = state.GetButtons();
            bool[] previousButtons = previousState.GetButtons();

            for (int i = 0, c = buttons.Length; i < c; i++)
            {
                if (previousButtons[i] != buttons[i])
                {
                    onButton(i, buttons[i]);
                    log("pollingClient", "onButton(" + i + "," + buttons[i] + ")");
                }
            }

            int[] pointOfViews         = state.GetPointOfViewControllers();
            int[] previousPointOfViews = previousState.GetPointOfViewControllers();
            for (int i = 0, c = pointOfViews.Length; i < c; i++)
            {
                if (previousPointOfViews[i] != pointOfViews[i])
                {
                    onPov(i, pointOfViews[i]);
                    log("pollingClient", "onPov(" + i + "," + pointOfViews[i] + ")");
                }
            }

            beforeBeforePreviousState = beforePreviousState;
            beforePreviousState       = previousState;
            previousState             = state;
        }