Exemplo n.º 1
0
        private void Joystick_OnStateUpdated(SlimDX.DirectInput.JoystickState state)
        {
            if (!this.joystickInitialized)
            {
                return;
            }

            var aircraftState = new AircraftState()
            {
                rudderValue = MapJoystickPosInRange(
                    state.X, CurveMode.Linear, this.radioConfig.Rudder_MinValue, this.radioConfig.Rudder_MaxValue, 0, this.radioConfig.Rudder_ReverseJoystick),
                aileronValue = MapJoystickPosInRange(
                    state.RotationX, CurveMode.Linear, this.radioConfig.Aileron_MinValue, this.radioConfig.Aileron_MaxValue, 0, this.radioConfig.Aileron_ReverseJoystick),
                elevatorValueRaw = state.RotationY,
                elevatorValue1   = MapJoystickPosInRange(
                    state.RotationY, this.radioConfig.Elevator_Curve1, this.radioConfig.Elevator_MinValue1,
                    this.radioConfig.Elevator_MaxValue1,
                    this.radioConfig.Elevator_Offset1,
                    this.radioConfig.Elevator_Reverse1),
                elevatorValue2 = MapJoystickPosInRange(
                    state.RotationY, this.radioConfig.Elevator_Curve2, this.radioConfig.Elevator_MinValue2,
                    this.radioConfig.Elevator_MaxValue2,
                    this.radioConfig.Elevator_Offset2,
                    this.radioConfig.Elevator_Reverse2),
                throtleValue = MapJoystickPosInRange(
                    state.Y, CurveMode.Linear, this.radioConfig.Throtle_MinValue, this.radioConfig.Throtle_MaxValue, 0, this.radioConfig.Throtle_ReverseJoystick),
            };

            //if (this.joystickSending)
            {
                if (this.comInitialized)
                {
                    this.rCommand.SetAircraftValues(aircraftState);
                }
            }

            lock (currentAircraftStateLock)
            {
                this.currentAircraftState = aircraftState;
            }
        }
Exemplo n.º 2
0
        private void onCurrentState()
        {
            Console.Clear();

            SlimDX.DirectInput.JoystickState state = joystick.currentState;

            Console.WriteLine("Controller:" + joystick.JoystickName);

            bool[] jsButtons = state.GetButtons();
            int[]  POVs      = state.GetPointOfViewControllers();
            int[]  Axis      = state.GetSliders();

            Console.WriteLine("X: {0}, Y: {1},Z: {2}", state.X, state.Y, state.Z);
            Console.WriteLine("RX: {0}, RY: {1}, RZ: {2}", state.RotationX, state.RotationY, state.RotationZ);

            int i = 0;

            foreach (int Ax in Axis)
            {
                Console.WriteLine("Axel Nr {0}: {1}", i, Ax);
                i++;
            }

            foreach (int POV in POVs)
            {
                Console.WriteLine("POV Nr {0}: Aktiv", POV);
            }

            i = 0;
            foreach (bool button in jsButtons)
            {
                if (button)
                {
                    Console.WriteLine("Knapp Nr {0}: Aktiv", i);
                }
                i++;
            }
        }
Exemplo n.º 3
0
        private byte[] DetectInput(byte index)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            SlimDX.DirectInput.JoystickState jState = dev.joystick.GetCurrentState();
            bool input = false;

            byte[] b = new byte[] { 0, 0, 0 };

            int[] axisNeutral    = new int[] { jState.X, jState.Y, jState.Z, jState.RotationX, jState.RotationY, jState.RotationZ }; //gets the current axis positions and assumes them as neutral
            int[] slidersNeutral = new int[] { jState.GetSliders()[0], jState.GetSliders()[1] };

            while (!input)
            {
                jState = dev.joystick.GetCurrentState();
                bool[] buttons = jState.GetButtons();                                                                              //return bool for every button as array
                int[]  pov     = jState.GetPointOfViewControllers();                                                               //returns int for every pov position as array
                int[]  axis    = new int[] { jState.X, jState.Y, jState.Z, jState.RotationX, jState.RotationY, jState.RotationZ }; //returns int for every slider position as array
                int[]  sliders = new int[] { jState.GetSliders()[0], jState.GetSliders()[1] };

                int i;
                i = 0;
                while (i < buttons.Length && !input)
                {
                    if (buttons[i])
                    {
                        input = true;
                        b[0]  = 0;
                        b[1]  = (byte)i;
                        b[2]  = index;
                        Console.WriteLine("Binding button {0} to index {1}", i + 1, b[2]);
                        return(b);
                    }
                    i++;
                }

                i = 0;
                while (i < axis.Length && !input)
                {
                    // adding a deadzone, just to make sure user really presses the right direction
                    if (axis[i] > axisNeutral[i] + 15000)
                    {
                        input = true;
                        b[0]  = 16;
                        b[1]  = (byte)i;
                        b[2]  = index;
                        Console.WriteLine("Binding + axis {0} to index {1}", i + 1, b[2]);
                        return(b);
                    }
                    // adding a deadzone, just to make sure user really presses the right direction
                    else if (axis[i] < axisNeutral[i] - 15000)
                    {
                        input = true;
                        b[0]  = 17;
                        b[1]  = (byte)i;
                        b[2]  = index;
                        Console.WriteLine("Binding - axis {0} to index {1}", i + 1, b[2]);
                        return(b);
                    }
                    i++;
                }

                i = 0;
                while (i < sliders.Length && !input)
                {
                    if (sliders[i] > slidersNeutral[i] + 15000)
                    {
                        input = true;
                        b[0]  = 48;
                        b[1]  = (byte)i;
                        b[2]  = index;
                        Console.WriteLine("Binding + slider {0} to index {1}", i + 1, b[2]);
                        return(b);
                    }
                    else if (sliders[i] < slidersNeutral[i] - 15000)
                    {
                        input = true;
                        b[0]  = 49;
                        b[1]  = (byte)i;
                        b[2]  = index;
                        Console.WriteLine("Binding - slider {0} to index {1}", i + 1, b[2]);
                        return(b);
                    }
                    i++;
                }

                i = 0;
                while (i < pov.Length && !input)
                {
                    {
                        switch (pov[i])
                        {
                        case 0:
                            input = true;
                            b[0]  = 32;
                            b[1]  = (byte)i;
                            b[2]  = index;
                            Console.WriteLine("Binding DPad Up {0} to index {1}", i + 1, b[2]);
                            return(b);

                        case 9000:
                            input = true;
                            b[0]  = 35;
                            b[1]  = (byte)i;
                            b[2]  = index;
                            Console.WriteLine("Binding DPad Right {0} to index {1}", i + 1, b[2]);
                            return(b);

                        case 18000:
                            input = true;
                            b[0]  = 33;
                            b[1]  = (byte)i;
                            b[2]  = index;
                            Console.WriteLine("Binding DPad Down {0} to index {1}", i + 1, b[2]);
                            return(b);

                        case 27000:
                            input = true;
                            b[0]  = 34;
                            b[1]  = (byte)i;
                            b[2]  = index;
                            Console.WriteLine("Binding DPad Left {0} to index {1}", i + 1, b[2]);
                            return(b);
                        }
                    }
                    i++;
                }

                if (sw.ElapsedMilliseconds > 2000)
                {
                    b[0] = 127; // this type defines an unsuccessful detection
                    b[2] = index;
                    break;
                }
            }
            return(b);
        }