예제 #1
0
        public ControllerDevice(Joystick joy, int num)
        {
            joystick = joy;
            deviceNumber = num;
            name = joystick.Information.InstanceName;
            cOutput = new OutputState();

            //initialize values
            joystick.Poll();
            JoystickState jState = joystick.GetCurrentState();
            buttons = jState.GetButtons();
            dPads = jState.GetPointOfViewControllers();
            analogs = GetAxes(jState);
            
            //TODO: delete this code.  Initial value is already blank.
            //for (int i = 0; i < controlMappings.Length; i++)
            //{
            //    controlMappings[i] = 255; //Changed default mapping to blank
            //}

            var saveData = SaveManager.LoadDeviceControls(joy.Information.ProductName.ToString());
            if (saveData != null)
            {
                controlMappings = saveData;
            }
        }
        private void setPovButtons()
        {
            var povControllers = _state.GetPointOfViewControllers();
            var value          = povControllers[0];

            switch (value)
            {
            case ButtonRelease:
            {
                if (_isSpeedDribblerIncPressed && _speedDribbler < 100)
                {
                    _speedDribbler += 10;
                }
                if (_isSpeedDribblerDecPressed && _speedDribbler > 0)
                {
                    _speedDribbler -= 10;
                }
                if (_isVoltageLevelIncPressed && _voltageLevel < 30)
                {
                    _voltageLevel += 6;
                }
                if (_isVoltageLevelDecPressed && _voltageLevel > 0)
                {
                    _voltageLevel -= 6;
                }
                _isSpeedDribblerIncPressed = false;
                _isSpeedDribblerDecPressed = false;
                _isVoltageLevelIncPressed  = false;
                _isVoltageLevelDecPressed  = false;
                break;
            }

            case SpeedDribblerIncValue:
            {
                _isSpeedDribblerIncPressed = true;
                break;
            }

            case SpeedDribblerDecValue:
            {
                _isSpeedDribblerDecPressed = true;
                break;
            }

            case VoltageLevelIncValue:
            {
                _isVoltageLevelIncPressed = true;
                break;
            }

            case VoltageLevelDecValue:
            {
                _isVoltageLevelDecPressed = true;
                break;
            }
            }
        }
예제 #3
0
 public ControllerState(JoystickState state) : this()
 {
     _buttons  = state.GetButtons();
     _hats     = state.GetPointOfViewControllers();
     X         = state.X;
     Y         = state.Y;
     RotationX = state.RotationX;
     RotationY = state.RotationY;
 }
예제 #4
0
        private void updateInput()
        {
            joystick.Poll();
            JoystickState jState = joystick.GetCurrentState();

            buttons = jState.GetButtons();
            dPads   = jState.GetPointOfViewControllers();
            analogs = GetAxes(jState);

            input funcButton = Button;
            input funcAnalog = Analog;
            input funcDPad   = DPad;

            input[] funcArray = new input[] { funcButton, funcAnalog, funcDPad };

            byte[] output = new byte[22];
            for (int i = 0; i < 22; i++)
            {
                if (mapping[i * 2] == 255 || mapping[i * 2] == 253)
                {
                    continue;
                }
                byte subtype = (byte)(mapping[i * 2] & 0x0F);
                byte type    = (byte)((mapping[i * 2] & 0xF0) >> 4);
                byte num     = mapping[(i * 2) + 1];
                output[i] = funcArray[type](subtype, num);
            }

            cOutput.A = output[0] != 0;
            cOutput.B = output[1] != 0;
            cOutput.X = output[2] != 0;
            cOutput.Y = output[3] != 0;

            cOutput.DpadUp    = output[4] != 0;
            cOutput.DpadDown  = output[5] != 0;
            cOutput.DpadLeft  = output[6] != 0;
            cOutput.DpadRight = output[7] != 0;

            cOutput.L2 = output[9];
            cOutput.R2 = output[8];

            cOutput.L1 = output[10] != 0;
            cOutput.R1 = output[11] != 0;

            cOutput.L3 = output[12] != 0;
            cOutput.R3 = output[13] != 0;

            cOutput.Home  = output[14] != 0;
            cOutput.Start = output[15] != 0;
            cOutput.Back  = output[16] != 0;

            cOutput.LY = output[17];
            cOutput.LX = output[18];
            cOutput.RY = output[19];
            cOutput.RX = output[20];
        }
예제 #5
0
        private void updateInput()
        {
            joystick.Poll();
            JoystickState jState = joystick.GetCurrentState();
            buttons = jState.GetButtons();
            dPads = jState.GetPointOfViewControllers();
            analogs = GetAxes(jState);

            input funcButton = Button;
            input funcAnalog = Analog;
            input funcDPad = DPad;
            input[] funcArray = new input[] { funcButton, funcAnalog, funcDPad };

            byte[] output = new byte[XINPUT_CONTROL_COUNT];
            for (int i = 0; i < XINPUT_CONTROL_COUNT; i++)
            {
                if (controlMappings[i].Type == ControlTypeEnum.Disabled)
                {
                    continue;
                }
                var type = controlMappings[i].Type;
                var subtype = controlMappings[i].SubType;
                var num = controlMappings[i].InputIndex;
                output[i] = funcArray[(byte)type - 1](subtype, num);
            }

            cOutput.A = output[0] != 0;
            cOutput.B = output[1] != 0;
            cOutput.X = output[2] != 0;
            cOutput.Y = output[3] != 0;

            cOutput.DpadUp = output[4] != 0;
            cOutput.DpadDown = output[5] != 0;
            cOutput.DpadLeft = output[6] != 0;
            cOutput.DpadRight = output[7] != 0;

            cOutput.L2 = output[9];
            cOutput.R2 = output[8];

            cOutput.L1 = output[10] != 0;
            cOutput.R1 = output[11] != 0;

            cOutput.L3 = output[12] != 0;
            cOutput.R3 = output[13] != 0;

            cOutput.Home = output[14] != 0;
            cOutput.Start = output[15] != 0;
            cOutput.Back = output[16] != 0;

            cOutput.LY = output[17];
            cOutput.LX = output[18];
            cOutput.RY = output[19];
            cOutput.RX = output[20];
            
        }
예제 #6
0
        /// <summary>Converts all digital buttons and the controller's PoV hat</summary>
        /// <param name="gamePadState">Game pad state that will receive the results</param>
        /// <param name="joystickState">Joystick state the values are taken from</param>
        private void convertButtonsAndPov(
            FlatGamePadState gamePadState, ref JoystickState joystickState
            )
        {
            Buttons pressedButtons = 0;

            // Try to match up the joystick's buttons with those that would be on
            // an XBox 360 controller.
            bool[] buttons = joystickState.GetButtons();
            for (int index = 0; index < this.buttonCount; ++index)
            {
                if (buttons[index])
                {
                    pressedButtons |= buttonOrder[index];
                }
            }

            // If this controller has a Point-of-View hat, we interpret the hat as
            // 4 additional buttons. If not, the buttonCount property is limited to
            // 14, allowing an additional 4 normal buttons on the controller to act
            // as if they were a PoV hat.
            if (this.hasPovHat)
            {
                int pov = joystickState.GetPointOfViewControllers()[0];

                // PoV hats report either -1 or 65535 when they're centered and their
                // position in degrees times 100 if they're not centered.
                if ((ushort)(pov) != 0xFFFF)
                {
                    bool right = ((pov > 0) && (pov < 18000));
                    bool down  = ((pov > 9000) && (pov < 27000));
                    bool left  = ((pov > 18000) && (pov < 36000));
                    bool up    = ((pov > 27000) || (pov < 9000));

                    if (right)
                    {
                        pressedButtons |= Buttons.DPadRight;
                    }
                    if (down)
                    {
                        pressedButtons |= Buttons.DPadDown;
                    }
                    if (left)
                    {
                        pressedButtons |= Buttons.DPadLeft;
                    }
                    if (up)
                    {
                        pressedButtons |= Buttons.DPadUp;
                    }
                }
            }

            this.gamePadState.Buttons = pressedButtons;
        }
        public double GetValue(JoystickState joystickState, int povIndex)
        {
            // Position is quantized degrees from North quantized to the four cardinal directions.
            int position = joystickState.GetPointOfViewControllers()[povIndex];
            foreach(Range range in _directionRanges) {
                if(range.Contains(position)) {
                    return range.Value / 100d;
                }
            }

            return -1;
        }
예제 #8
0
        public void checkDemPovs(int joyNum)
        {
            int[] pov = state.GetPointOfViewControllers();

            for (int i = 0; i < pov.Length; ++i)
            {
                if (pov[i] != -1)
                {
                    inputGroup.Add(new inputObj(joyNum, "pov", pov[0]));
                }
            }
        }
예제 #9
0
        private byte[] ifPressed(int[] axesStart)
        {
            dev.joystick.Poll();
            JoystickState jState = dev.joystick.GetCurrentState();

            bool[] buttons = jState.GetButtons();
            int[]  dPads   = jState.GetPointOfViewControllers();
            int[]  axes    = ControllerDevice.GetAxes(jState);

            // Buttons
            int i = 0;

            foreach (bool button in buttons)
            {
                if (button)
                {
                    return new byte[] { 0, (byte)i }
                }
                ;
                i++;
            }

            // dPads
            i = 0;
            foreach (int dPad in dPads)
            {
                bool[] dp = getPov(dPad);
                for (int x = 0; x < 4; x++)
                {
                    if (dp[x])
                    {
                        return new byte[] { (byte)(32 + x), (byte)i }
                    }
                    ;
                }
                i++;
            }

            // Axes
            i = 0;
            foreach (int axis in axes)
            {
                if (axis != axesStart[i])
                {
                    return new byte[] { 16, (byte)i }
                }
                ;

                i++;
            }
            return(null);
        }
예제 #10
0
        public static PressedButtons GetInputs()
        {
            var state = new JoystickState();

            var buttons = new PressedButtons();

            if (Pad == null)
            {
                return(new PressedButtons());
            }

            if (Pad.Poll().IsFailure)
            {
            }

            if (Pad.GetCurrentState(ref state).IsFailure)
            {
            }
            State = state;

            var _buttons = state.GetButtons().ToList();

            var pov = state.GetPointOfViewControllers()[0];

            _buttons.Add((state.X / 5000.0f == 1));
            _buttons.Add((state.X / 5000.0f == -1));

            _buttons.Add((state.Y / 5000.0f == 1));
            _buttons.Add((state.Y / 5000.0f == -1));

            _buttons.Add((state.Z / 5000.0f >= 0.5));
            _buttons.Add((state.Z / 5000.0f <= -0.5));


            _buttons.Add(pov == 0 || pov == 31500 || pov == 4500);
            _buttons.Add(pov == 27000 || pov == 31500 || pov == 22500);
            _buttons.Add(pov == 9000 || pov == 4500 || pov == 13500);
            _buttons.Add(pov == 18000 || pov == 22500 || pov == 13500);


            for (int i = 0; i < _buttons.Count; i++)
            {
                if (_buttons[i])
                {
                    buttons.buttons.Add(i);
                }
            }



            return(buttons);
        }
예제 #11
0
        public double GetValue(JoystickState joystickState, int povIndex)
        {
            // Position is quantized degrees from North quantized to the four cardinal directions.
            int position = joystickState.GetPointOfViewControllers()[povIndex];

            foreach (Range range in _directionRanges)
            {
                if (range.Contains(position))
                {
                    return(range.Value / 100d);
                }
            }

            return(-1);
        }
예제 #12
0
        public override void Poll()
        {
            JoystickState state = Joystick.GetCurrentState();

            //Straight forward for PS Controllers
            //Just convert to -400 to 400 scale.
            X         = (state.X / 82) - 400;
            Y         = (state.Y / 82) - 400;
            Z         = (state.Z / 82) - 400;
            RotationX = (state.RotationX / 163);
            RotationY = (state.RotationY / 163);
            RotationZ = (state.RotationZ / 82) - 400;
            PointOfViewControllers = state.GetPointOfViewControllers();
            Buttons = state.GetButtons();

            //add more as we need more
        }
예제 #13
0
        public void Load(JoystickState state)
        {
            button_a = state.GetButtons()[0];
            button_b = state.GetButtons()[1];
            button_x = state.GetButtons()[2];
            button_y = state.GetButtons()[3];

            button_lb     = state.GetButtons()[4];
            button_rb     = state.GetButtons()[5];
            button_select = state.GetButtons()[6];
            button_start  = state.GetButtons()[7];
            button_lj     = state.GetButtons()[8];
            button_rj     = state.GetButtons()[9];

            lj_x = joy2byte(state.X);
            lj_y = joy2byte(state.Y);
            rj_x = joy2byte(state.RotationX);
            rj_y = joy2byte(state.RotationY);

            rt = joy2byte(state.Z);
            lt = joy2byte(state.Z);

            int[] all_pov = state.GetPointOfViewControllers();
            int   pov     = all_pov[0];

            if (pov != -1)
            {
                pov /= 100;

                pov_u = pov == 0 || pov == 45 || pov == 315;
                pov_d = pov == 180 || pov == 225 || pov == 135;
                pov_l = pov == 270 || pov == 315 || pov == 225;
                pov_r = pov == 90 || pov == 45 || pov == 135;
            }
            else
            {
                pov_u = false;
                pov_l = false;
                pov_d = false;
                pov_r = false;
            }

            PropertyChanged(this, new PropertyChangedEventArgs(null));
        }
예제 #14
0
        void UpdateUI()
        {
            if (joystick == null)
            {
                createDeviceButton.Text = "Create Device";
            }
            else
            {
                createDeviceButton.Text = "Release Device";
            }

            string strText = null;

            label_X.Text = state.X.ToString(CultureInfo.CurrentCulture);
            label_Y.Text = state.Y.ToString(CultureInfo.CurrentCulture);
            label_Z.Text = state.Z.ToString(CultureInfo.CurrentCulture);

            label_XRot.Text = state.RotationX.ToString(CultureInfo.CurrentCulture);
            label_YRot.Text = state.RotationY.ToString(CultureInfo.CurrentCulture);
            label_ZRot.Text = state.RotationZ.ToString(CultureInfo.CurrentCulture);

            int[] slider = state.GetSliders();

            label_S0.Text = slider[0].ToString(CultureInfo.CurrentCulture);
            label_S1.Text = slider[1].ToString(CultureInfo.CurrentCulture);

            int[] pov = state.GetPointOfViewControllers();

            label_P0.Text = pov[0].ToString(CultureInfo.CurrentCulture);
            label_P1.Text = pov[1].ToString(CultureInfo.CurrentCulture);
            label_P2.Text = pov[2].ToString(CultureInfo.CurrentCulture);
            label_P3.Text = pov[3].ToString(CultureInfo.CurrentCulture);

            bool[] buttons = state.GetButtons();

            for (int b = 0; b < buttons.Length; b++)
            {
                if (buttons[b])
                {
                    strText += b.ToString("00 ", CultureInfo.CurrentCulture);
                }
            }
            label_ButtonList.Text = strText;
        }
예제 #15
0
        void stickHandle(Joystick stick, int id)
        {
            JoystickState state = new JoystickState();

            state = stick.GetCurrentState();

            xValue = state.X;
            yValue = state.Y;
            zValue = state.Z;

            xRotValue = state.RotationX;
            yRotValue = state.RotationY;
            zRotValue = state.RotationZ;

            bool[] buttons     = state.GetButtons();
            int[]  pointOfView = state.GetPointOfViewControllers();
            if (id == 0)
            {
                if (buttons[0])
                {
                    if (MouseClicked = false)
                    {
                        mouse_event(MOUSEEVENT_LEFTDOWN, 0, 0, 0, 0);
                        MouseClicked = true;
                    }
                }
                else
                {
                    if (MouseClicked == true)
                    {
                        mouse_event(MOUSEEVENT_LEFTUP, 0, 0, 0, 0);
                        MouseClicked = false;
                    }
                }
                label1.Text = pointOfView[0] + "";

                checkBox1.Text = buttons[0] + "";
                checkBox2.Text = buttons[1] + "";
                checkBox3.Text = buttons[2] + "";
                checkBox4.Text = buttons[3] + "";
                checkBox5.Text = buttons[4] + "";
                checkBox6.Text = buttons[5] + "";
            }
        }
예제 #16
0
        /* Controller Stuff Happens Here */
        private void PlayerControllerHandle(Joystick PlayerController, int id)
        {
            JoystickState State = new JoystickState();

            State = PlayerController.GetCurrentState();

            // Currently pressed controller buttons
            ControllerButtons = State.GetButtons();
            ControllerDPad    = State.GetPointOfViewControllers();

            // What are we gonna do with this controller?
            switch (ControllerInputActionID)
            {
            case (int)ControllerInputAction.Null:     // Default Method Calls
                PlayerControllerExecuteMethod(ControllerButtons, ControllerDPad);
                break;

            case (int)ControllerInputAction.IsAssigningButton:     // Assigning Buttons
                PlayerControllerAssignButton(ControllerButtons, ControllerDPad);
                break;
            }
        }
예제 #17
0
파일: Main.cs 프로젝트: tjrov/1819-Core
        /*
         * Handles Controller Inputs
         */
        void stickHandle(Joystick stick, int id)
        {
            JoystickState state = new JoystickState();

            state = stick.GetCurrentState();

            xValue = state.X;
            yValue = state.Y;
            zValue = state.Z;

            xRotValue = state.RotationX;
            yRotValue = state.RotationY;
            zRotValue = state.RotationZ;

            bool[] buttons     = state.GetButtons();
            int[]  pointOfView = state.GetPointOfViewControllers();
            if (id == 0) //User One Controller input definitions go here
            {
            }
            if (id == 1) //User Two Controller input definitions go here
            {
            }
        }
예제 #18
0
        public ControllerDevice(Joystick joy, int num)
        {
            joystick     = joy;
            deviceNumber = num;
            name         = joystick.Information.InstanceName;
            cOutput      = new OutputState();

            joystick.Poll();
            JoystickState jState = joystick.GetCurrentState();

            buttons = jState.GetButtons();
            dPads   = jState.GetPointOfViewControllers();
            analogs = GetAxes(jState);

            for (int i = 0; i < mapping.Length; i++)
            {
                mapping[i] = 255; //Changed default mapping to blank
            }
            byte[] saveData = SaveManager.Load(joy.Information.ProductName.ToString());
            if (saveData != null)
            {
                mapping = saveData;
            }
        }
예제 #19
0
        void InitializeCallbacks()
        {
            const int dzp = 400;
            const int dzn = -400;

            names.Clear();
            actions.Clear();
            NumButtons = 0;

            AddItem("AccelerationX+", () => state.AccelerationX >= dzp);
            AddItem("AccelerationX-", () => state.AccelerationX <= dzn);
            AddItem("AccelerationY+", () => state.AccelerationY >= dzp);
            AddItem("AccelerationY-", () => state.AccelerationY <= dzn);
            AddItem("AccelerationZ+", () => state.AccelerationZ >= dzp);
            AddItem("AccelerationZ-", () => state.AccelerationZ <= dzn);
            AddItem("AngularAccelerationX+", () => state.AngularAccelerationX >= dzp);
            AddItem("AngularAccelerationX-", () => state.AngularAccelerationX <= dzn);
            AddItem("AngularAccelerationY+", () => state.AngularAccelerationY >= dzp);
            AddItem("AngularAccelerationY-", () => state.AngularAccelerationY <= dzn);
            AddItem("AngularAccelerationZ+", () => state.AngularAccelerationZ >= dzp);
            AddItem("AngularAccelerationZ-", () => state.AngularAccelerationZ <= dzn);
            AddItem("AngularVelocityX+", () => state.AngularVelocityX >= dzp);
            AddItem("AngularVelocityX-", () => state.AngularVelocityX <= dzn);
            AddItem("AngularVelocityY+", () => state.AngularVelocityY >= dzp);
            AddItem("AngularVelocityY-", () => state.AngularVelocityY <= dzn);
            AddItem("AngularVelocityZ+", () => state.AngularVelocityZ >= dzp);
            AddItem("AngularVelocityZ-", () => state.AngularVelocityZ <= dzn);
            AddItem("ForceX+", () => state.ForceX >= dzp);
            AddItem("ForceX-", () => state.ForceX <= dzn);
            AddItem("ForceY+", () => state.ForceY >= dzp);
            AddItem("ForceY-", () => state.ForceY <= dzn);
            AddItem("ForceZ+", () => state.ForceZ >= dzp);
            AddItem("ForceZ-", () => state.ForceZ <= dzn);
            AddItem("RotationX+", () => state.RotationX >= dzp);
            AddItem("RotationX-", () => state.RotationX <= dzn);
            AddItem("RotationY+", () => state.RotationY >= dzp);
            AddItem("RotationY-", () => state.RotationY <= dzn);
            AddItem("RotationZ+", () => state.RotationZ >= dzp);
            AddItem("RotationZ-", () => state.RotationZ <= dzn);
            AddItem("TorqueX+", () => state.TorqueX >= dzp);
            AddItem("TorqueX-", () => state.TorqueX <= dzn);
            AddItem("TorqueY+", () => state.TorqueY >= dzp);
            AddItem("TorqueY-", () => state.TorqueY <= dzn);
            AddItem("TorqueZ+", () => state.TorqueZ >= dzp);
            AddItem("TorqueZ-", () => state.TorqueZ <= dzn);
            AddItem("VelocityX+", () => state.VelocityX >= dzp);
            AddItem("VelocityX-", () => state.VelocityX <= dzn);
            AddItem("VelocityY+", () => state.VelocityY >= dzp);
            AddItem("VelocityY-", () => state.VelocityY <= dzn);
            AddItem("VelocityZ+", () => state.VelocityZ >= dzp);
            AddItem("VelocityZ-", () => state.VelocityZ <= dzn);
            AddItem("X+", () => state.X >= dzp);
            AddItem("X-", () => state.X <= dzn);
            AddItem("Y+", () => state.Y >= dzp);
            AddItem("Y-", () => state.Y <= dzn);
            AddItem("Z+", () => state.Z >= dzp);
            AddItem("Z-", () => state.Z <= dzn);

            // i don't know what the "Slider"s do, so they're omitted for the moment

            for (int i = 0; i < state.GetButtons().Length; i++)
            {
                int j = i;
                AddItem(string.Format("B{0}", i + 1), () => state.IsPressed(j));
            }

            for (int i = 0; i < state.GetPointOfViewControllers().Length; i++)
            {
                int j = i;
                AddItem(string.Format("POV{0}U", i + 1),
                        () => { int t = state.GetPointOfViewControllers()[j]; return((t >= 0 && t <= 4500) || (t >= 31500 && t < 36000)); });
                AddItem(string.Format("POV{0}D", i + 1),
                        () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 13500 && t <= 22500); });
                AddItem(string.Format("POV{0}L", i + 1),
                        () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 22500 && t <= 31500); });
                AddItem(string.Format("POV{0}R", i + 1),
                        () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 4500 && t <= 13500); });
            }
        }
예제 #20
0
 // Gets controller state for temporary buttons/lockin mode
 public void GetControllerStateTemp()
 {
     State             = PlayerController.GetCurrentState();
     ControllerButtons = State.GetButtons();
     ControllerDPad    = State.GetPointOfViewControllers();
 }
예제 #21
0
        void InitializeCallbacks()
        {
            const int dzp = 400;
            const int dzn = -400;

            names.Clear();
            actions.Clear();
            NumButtons = 0;

            // populate DIAXISINFO
            devObList = (joystick.GetObjects()
                         .Where(a => a.UsagePage == 1 && a.Usage > 0 && a.Usage != 4)
                         .GroupBy(x => x.Name).Select(x => x.First())
                         .OrderBy(o => o.Usage)
                         .ThenBy(o2 => o2.Offset)).ToArray();

            for (int axis = 0; axis < devObList.Count(); axis++)
            {
                DeviceObjectInstance deviceObject = joystick.GetObjects()[axis];
                InputRange           diprg        = joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).LogicalRange;
                int min = diprg.Minimum;
                int max = diprg.Maximum;

                if (min < max)
                {
                    di_axis_info dai = new di_axis_info();
                    dai.jd_logical_offset = axis;
                    dai.maximum           = max;
                    dai.minimum           = min;
                    dai.name         = deviceObject.Name;
                    dai.usage        = deviceObject.Usage;
                    dai.usagepage    = deviceObject.UsagePage;
                    dai.offset       = deviceObject.Offset / 4;
                    dai.offsetActual = deviceObject.Offset;
                    dai.device       = deviceObject;
                    DIAxisInfo.Add(dai);
                }

                //axis_config_type[axis] = 0;
            }


            num_rel_axes = 0;
            num_axes     = DIAxisInfo.Count(); // + joystick.Capabilities.PovCount * 2;
            num_buttons  = joystick.Capabilities.ButtonCount;

            /* States */
            axis_state.Resize(num_axes);
            rel_axis_state.Resize(num_rel_axes);
            button_state.Resize(num_buttons);

            // buttons
            for (int button = 0; button < joystick.Capabilities.ButtonCount; button++)
            {
                if (state.GetButtons()[button] == true)
                {
                    button_state[button] = true;
                }
                else
                {
                    button_state[button] = false;
                }
            }

            // axis
            unsafe
            {
                for (int axis = 0; axis < DIAxisInfo.Count; axis++)
                {
                    int   X  = state.X;
                    Int64 rv = (&X)[DIAxisInfo[axis].jd_logical_offset];

                    rv = (((rv - DIAxisInfo[axis].minimum) * 32767 * 2) / (DIAxisInfo[axis].maximum - DIAxisInfo[axis].minimum)) - 32767;
                    if (rv < -32767)
                    {
                        rv = -32767;
                    }

                    if (rv > 32767)
                    {
                        rv = 32767;
                    }
                    axis_state[axis] = Convert.ToInt16(rv);
                }
            }

            // hats

            /*
             * for (int hat = 0; hat < joystick.Capabilities.PovCount; hat++)
             * {
             *  uint hat_val = Convert.ToUInt32(state.GetPointOfViewControllers()[hat]);
             *
             *  if (hat_val >= 36000)
             *  {
             *      axis_state[(DIAxisInfo.Count + hat * 2) + 0] = 0;
             *      axis_state[(DIAxisInfo.Count + hat * 2) + 1] = 0;
             *  }
             *  else
             *  {
             *      int x = 0;
             *      int y = 0;
             *      uint octant = (hat_val / 4500) & 0x7;
             *      int octant_doff = Convert.ToInt32(hat_val) % 4500;
             *
             *      switch (octant)
             *      {
             *          case 0: x = octant_doff * 32767 / 4500; y = -32767; break;
             *          case 1: x = 32767; y = (-4500 + octant_doff) * 32767 / 4500; break;
             *
             *          case 2: x = 32767; y = octant_doff * 32767 / 4500; break;
             *          case 3: x = (4500 - octant_doff) * 32767 / 4500; y = 32767; break;
             *
             *          case 4: x = (-octant_doff) * 32767 / 4500; y = 32767; break;
             *          case 5: x = -32767; y = (4500 - octant_doff) * 32767 / 4500; break;
             *
             *          case 6: x = -32767; y = (-octant_doff) * 32767 / 4500; break;
             *          case 7: x = (-4500 + octant_doff) * 32767 / 4500; y = -32767; break;
             *      }
             *
             *      axis_state[(DIAxisInfo.Count + hat * 2) + 0] = Convert.ToInt16(x);
             *      axis_state[(DIAxisInfo.Count + hat * 2) + 1] = Convert.ToInt16(y);
             *  }
             *
             * }
             */

            //string iD = IdGenerator.CalcOldStyleID(DIAxisInfo.Count, 0, joystick.Capabilities.PovCount, joystick.Capabilities.ButtonCount).ToString();
            //string iD = IdGenerator.CalcOldStyleID(num_axes, 0, num_hats, num_buttons).ToString();

            /* populate objects */

            // buttons first

            if (VersionChecker.Instance.IsNewConfig)
            {
                // new stype
                for (int i = 0; i < num_buttons; i++)
                {
                    int    j            = i;
                    bool   button_state = state.GetButtons()[i];
                    UInt32 butnameint   = Convert.ToUInt32(i);
                    string buttStr      = "button_" + i;

                    BConfig.Add(butnameint);

                    AddItem("joystick " + id + " " + buttStr, () => state.IsPressed(j));
                }
            }
            else
            {
                // old style
                for (int i = 0; i < num_buttons; i++)
                {
                    int    j            = i;
                    bool   button_state = state.GetButtons()[i];
                    UInt32 butnameint   = Convert.ToUInt32(i);
                    string buttonnum    = butnameint.ToString("X8");

                    BConfig.Add(butnameint);

                    AddItem("joystick " + id + " " + butnameint.ToString("X8").ToLower(), () => state.IsPressed(j));
                }
            }

            Func <bool> cbPos;
            Func <bool> cbNeg;

            // names
            int buttNamePos;
            int buttNameNeg;

            string buttNamePosString;
            string buttNameNegString;

            // axis
            for (int axis = 0; axis < num_axes; axis++)
            {
                Int16 a_state           = axis_state[axis];
                DeviceObjectInstance di = devObList[axis];

                // dynamically create callback

                if (VersionChecker.Instance.IsNewConfig)
                {
                    // new style
                    string abs = "abs_";

                    // new config format
                    switch (di.Usage)
                    {
                    case 0x30:          // X Axis
                        cbPos             = () => state.X >= dzp;
                        cbNeg             = () => state.X <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x31:          // y Axis
                        cbPos             = () => state.Y >= dzp;
                        cbNeg             = () => state.Y <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x32:          // Z Axis
                        cbPos             = () => state.Z >= dzp;
                        cbNeg             = () => state.Z <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x33:          // X Rotation
                        cbPos             = () => state.RotationX >= dzp;
                        cbNeg             = () => state.RotationX <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x34:          // Y Rotation
                        cbPos             = () => state.RotationY >= dzp;
                        cbNeg             = () => state.RotationY <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x35:          // Z Rotation
                        cbPos             = () => state.RotationZ >= dzp;
                        cbNeg             = () => state.RotationZ <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x40:          // X Velocity
                        cbPos             = () => state.RotationZ >= dzp;
                        cbNeg             = () => state.RotationZ <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x41:          // Y Velocity
                        cbPos             = () => state.RotationZ >= dzp;
                        cbNeg             = () => state.RotationZ <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x42:          // Z Velocity
                        cbPos             = () => state.RotationZ >= dzp;
                        cbNeg             = () => state.RotationZ <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x39:          // Hat Switch (contains 2 actual axis)

                        // skip

                        /*
                         * povTmpCount++;
                         * // L - R
                         * buttNamePos = 0x8000 + axis;
                         * buttNameNeg = 0xc000 + axis;
                         * AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 22500 && t <= 31500; });
                         * AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 4500 && t <= 13500; });
                         * BConfig.Add(Convert.ToUInt32(buttNamePos));
                         * BConfig.Add(Convert.ToUInt32(buttNameNeg));
                         *
                         * // U - D
                         * buttNamePos = 0x8000 + axis;
                         * buttNameNeg = 0xc000 + axis;
                         * AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return (t >= 0 && t <= 4500) || (t >= 31500 && t < 36000); });
                         * AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 13500 && t <= 22500; });
                         * BConfig.Add(Convert.ToUInt32(buttNamePos));
                         * BConfig.Add(Convert.ToUInt32(buttNameNeg));
                         */
                        break;

                    default:
                        cbPos = null;
                        cbNeg = null;
                        break;
                    }
                }
                else
                {
                    // old style
                    switch (di.Usage)
                    {
                    case 0x30:          // X Axis
                        cbPos       = () => state.X >= dzp;
                        cbNeg       = () => state.X <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x31:          // y Axis
                        cbPos       = () => state.Y >= dzp;
                        cbNeg       = () => state.Y <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x32:          // Z Axis
                        cbPos       = () => state.Z >= dzp;
                        cbNeg       = () => state.Z <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x33:          // X Rotation
                        cbPos       = () => state.RotationX >= dzp;
                        cbNeg       = () => state.RotationX <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x34:          // Y Rotation
                        cbPos       = () => state.RotationY >= dzp;
                        cbNeg       = () => state.RotationY <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x35:          // Z Rotation
                        cbPos       = () => state.RotationZ >= dzp;
                        cbNeg       = () => state.RotationZ <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x40:          // X Velocity
                        cbPos       = () => state.RotationZ >= dzp;
                        cbNeg       = () => state.RotationZ <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x41:          // Y Velocity
                        cbPos       = () => state.RotationZ >= dzp;
                        cbNeg       = () => state.RotationZ <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x42:          // Z Velocity
                        cbPos       = () => state.RotationZ >= dzp;
                        cbNeg       = () => state.RotationZ <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x39:          // Hat Switch (contains 2 actual axis)

                        // skip

                        /*
                         * povTmpCount++;
                         * // L - R
                         * buttNamePos = 0x8000 + axis;
                         * buttNameNeg = 0xc000 + axis;
                         * AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 22500 && t <= 31500; });
                         * AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 4500 && t <= 13500; });
                         * BConfig.Add(Convert.ToUInt32(buttNamePos));
                         * BConfig.Add(Convert.ToUInt32(buttNameNeg));
                         *
                         * // U - D
                         * buttNamePos = 0x8000 + axis;
                         * buttNameNeg = 0xc000 + axis;
                         * AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return (t >= 0 && t <= 4500) || (t >= 31500 && t < 36000); });
                         * AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 13500 && t <= 22500; });
                         * BConfig.Add(Convert.ToUInt32(buttNamePos));
                         * BConfig.Add(Convert.ToUInt32(buttNameNeg));
                         */
                        break;

                    default:
                        cbPos = null;
                        cbNeg = null;
                        break;
                    }
                }
            }


            /*
             *
             * AddItem("AccelerationX+", () => state.AccelerationX >= dzp);
             * AddItem("AccelerationX-", () => state.AccelerationX <= dzn);
             * AddItem("AccelerationY+", () => state.AccelerationY >= dzp);
             * AddItem("AccelerationY-", () => state.AccelerationY <= dzn);
             * AddItem("AccelerationZ+", () => state.AccelerationZ >= dzp);
             * AddItem("AccelerationZ-", () => state.AccelerationZ <= dzn);
             * AddItem("AngularAccelerationX+", () => state.AngularAccelerationX >= dzp);
             * AddItem("AngularAccelerationX-", () => state.AngularAccelerationX <= dzn);
             * AddItem("AngularAccelerationY+", () => state.AngularAccelerationY >= dzp);
             * AddItem("AngularAccelerationY-", () => state.AngularAccelerationY <= dzn);
             * AddItem("AngularAccelerationZ+", () => state.AngularAccelerationZ >= dzp);
             * AddItem("AngularAccelerationZ-", () => state.AngularAccelerationZ <= dzn);
             * AddItem("AngularVelocityX+", () => state.AngularVelocityX >= dzp);
             * AddItem("AngularVelocityX-", () => state.AngularVelocityX <= dzn);
             * AddItem("AngularVelocityY+", () => state.AngularVelocityY >= dzp);
             * AddItem("AngularVelocityY-", () => state.AngularVelocityY <= dzn);
             * AddItem("AngularVelocityZ+", () => state.AngularVelocityZ >= dzp);
             * AddItem("AngularVelocityZ-", () => state.AngularVelocityZ <= dzn);
             * AddItem("ForceX+", () => state.ForceX >= dzp);
             * AddItem("ForceX-", () => state.ForceX <= dzn);
             * AddItem("ForceY+", () => state.ForceY >= dzp);
             * AddItem("ForceY-", () => state.ForceY <= dzn);
             * AddItem("ForceZ+", () => state.ForceZ >= dzp);
             * AddItem("ForceZ-", () => state.ForceZ <= dzn);
             * AddItem("RotationX+", () => state.RotationX >= dzp);
             * AddItem("RotationX-", () => state.RotationX <= dzn);
             * AddItem("RotationY+", () => state.RotationY >= dzp);
             * AddItem("RotationY-", () => state.RotationY <= dzn);
             * AddItem("00008003", () => state.RotationZ >= dzp); //AddItem("RotationZ+", () => state.RotationZ >= dzp);
             * AddItem("0000c003", () => state.RotationZ <= dzn); //AddItem("RotationZ-", () => state.RotationZ <= dzn);
             * AddItem("TorqueX+", () => state.TorqueX >= dzp);
             * AddItem("TorqueX-", () => state.TorqueX <= dzn);
             * AddItem("TorqueY+", () => state.TorqueY >= dzp);
             * AddItem("TorqueY-", () => state.TorqueY <= dzn);
             * AddItem("TorqueZ+", () => state.TorqueZ >= dzp);
             * AddItem("TorqueZ-", () => state.TorqueZ <= dzn);
             * AddItem("VelocityX+", () => state.VelocityX >= dzp);
             * AddItem("VelocityX-", () => state.VelocityX <= dzn);
             * AddItem("VelocityY+", () => state.VelocityY >= dzp);
             * AddItem("VelocityY-", () => state.VelocityY <= dzn);
             * AddItem("VelocityZ+", () => state.VelocityZ >= dzp);
             * AddItem("VelocityZ-", () => state.VelocityZ <= dzn);
             * AddItem("00008000", () => state.X >= dzp); //AddItem("X+", () => state.X >= dzp);
             * AddItem("0000c000", () => state.X <= dzn); //AddItem("X-", () => state.X <= dzn);
             * AddItem("00008001", () => state.Y >= dzp); //AddItem("Y+", () => state.Y >= dzp);
             * AddItem("0000c001", () => state.Y <= dzn); //AddItem("Y-", () => state.Y <= dzn);
             * AddItem("00008002", () => state.Z >= dzp); //AddItem("Z+", () => state.Z >= dzp);
             * AddItem("0000c002", () => state.Z <= dzn); //AddItem("Z-", () => state.Z <= dzn);
             *
             */

            // i don't know what the "Slider"s do, so they're omitted for the moment

            for (int i = 0; i < state.GetButtons().Length; i++)
            {
                //int j = i;
                //AddItem(string.Format("B{0}", i + 1), () => state.IsPressed(j));
            }


            // add sliders
            int povCount  = state.GetPointOfViewControllers().Length;
            int nPovCount = joystick.Capabilities.PovCount;
            int axiscount = DevCaps.AxesCount;

            for (int i = 0; i < nPovCount; i++)
            {
                int j    = i;
                int axis = axiscount - nPovCount + i;

                if (VersionChecker.Instance.IsNewConfig)
                {
                    // new style

                    // L - R
                    buttNamePos = 0x8000 + axis;
                    buttNameNeg = 0xc000 + axis;

                    buttNamePosString = "abs_" + axis + "+";
                    buttNameNegString = "abs_" + axis + "-";

                    AddItem("joystick " + id + " " + buttNamePosString,
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 22500 && t <= 31500); });

                    AddItem("joystick " + id + " " + buttNameNegString,
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 4500 && t <= 13500); });

                    BConfig.Add(Convert.ToUInt32(buttNamePos));
                    BConfig.Add(Convert.ToUInt32(buttNameNeg));

                    // U - D
                    buttNamePos = 0x8000 + (axis + 1);
                    buttNameNeg = 0xc000 + (axis + 1);

                    buttNamePosString = "abs_" + (axis + 1) + "+";
                    buttNameNegString = "abs_" + (axis + 1) + "-";

                    AddItem("joystick " + id + " " + buttNamePosString,
                            () => { int t = state.GetPointOfViewControllers()[j]; return((t >= 0 && t <= 4500) || (t >= 31500 && t < 36000)); });

                    AddItem("joystick " + id + " " + buttNameNegString,
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 13500 && t <= 22500); });

                    BConfig.Add(Convert.ToUInt32(buttNamePos));
                    BConfig.Add(Convert.ToUInt32(buttNameNeg));

                    // increment axis count (as there are effectively two axis in a POV Hat)
                    axiscount++;
                }
                else
                {
                    // old style
                    // L - R
                    buttNamePos = 0x8000 + axis;
                    buttNameNeg = 0xc000 + axis;
                    //AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 22500 && t <= 31500; });
                    AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(),  //string.Format("joystick " + id + " " + "POV{0}L", i + 1),
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 22500 && t <= 31500); });
                    //AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 4500 && t <= 13500; });
                    AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(),  //string.Format("joystick " + id + " " + "POV{0}R", i + 1),
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 4500 && t <= 13500); });
                    BConfig.Add(Convert.ToUInt32(buttNamePos));
                    BConfig.Add(Convert.ToUInt32(buttNameNeg));

                    // U - D
                    buttNamePos = 0x8000 + (axis + 1);
                    buttNameNeg = 0xc000 + (axis + 1);
                    //AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return (t >= 0 && t <= 4500) || (t >= 31500 && t < 36000); });
                    AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(),   //string.Format("joystick " + id + " " + "POV{0}U", i + 1),
                            () => { int t = state.GetPointOfViewControllers()[j]; return((t >= 0 && t <= 4500) || (t >= 31500 && t < 36000)); });
                    //AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 13500 && t <= 22500; });
                    AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(),   //string.Format("joystick " + id + " " + "POV{0}D", i + 1),
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 13500 && t <= 22500); });
                    BConfig.Add(Convert.ToUInt32(buttNamePos));
                    BConfig.Add(Convert.ToUInt32(buttNameNeg));

                    // increment axis count (as there are effectively two axis in a POV Hat)
                    axiscount++;
                }
            }
        }
예제 #22
0
        void UpdateUI()
        {
            if (isStartingSequence)
            {
                DoStartingSequence();
                return;
            }

            if (hasrestarted == true)
            {
                hasrestarted = false;
                tilt         = 0;
                t            = 0;
                time         = 0;
            }
            if (initState == 0)
            {
                initState = state.X;
            }

            if (joystick == null)
            {
                createDeviceButton.Text = "Create Device";
            }
            else
            {
                createDeviceButton.Text = "Release Device";
            }

            string strText = null;

            double gausnoise = Utils.RandGauss(0, 1);

            // int tilt = (int)Math.Pow(5, noise);

            // noise = (int)(tilt + state.X / 10);

            double difficulty = (double)time / 300 + 1;

            if (state.X < 50 && state.X > -50)
            {
                // t = 0;
                // initState = state.X;
                t++;
            }
            else
            {
                // t++;
                if (t > 0 && Math.Abs(tilt) < 89)
                {
                    t--;
                }

                // noise = Utils.RandGauss(0, 1);
            }

            if (tilt > -1 && tilt < 1)
            {
                tilt = Utils.RandGauss(0, 1);
            }

            // t++;
            time++;



            difficultyLabel.Text = (difficulty * 1000).ToString();

            tilt  = tilt * Math.Pow((1 + (.005 * difficulty)), t);
            tilt += state.X / (100);

            int arrayPosition = time;

            if (Math.Abs(tilt) >= 90)
            {
                isStartingSequence    = true;
                startingSequenceTimer = 0;
                if (tilt > 0)
                {
                    tilt          = 90;
                    hasrestarted  = true;
                    shouldVibrate = false;
                    // System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    tilt          = -90;
                    hasrestarted  = true;
                    shouldVibrate = false;
                    // System.Threading.Thread.Sleep(1000);
                }
            }


            log.WriteLine(games + "," + difficulty + "," + tilt + "," + state.X + "," + state.Y);


            vibrate((int)tilt);

            noiseLabel.Text = tilt.ToString();


            unicycle.Image = RotateImage(uniImage, new PointF(505, 697), (int)tilt);

            label_X.Text = state.X.ToString(CultureInfo.CurrentCulture);
            label_Y.Text = state.Y.ToString(CultureInfo.CurrentCulture);
            label_Z.Text = state.Z.ToString(CultureInfo.CurrentCulture);

            label_XRot.Text = state.RotationX.ToString(CultureInfo.CurrentCulture);
            label_YRot.Text = state.RotationY.ToString(CultureInfo.CurrentCulture);
            label_ZRot.Text = state.RotationZ.ToString(CultureInfo.CurrentCulture);

            int[] slider = state.GetSliders();

            label_S0.Text = slider[0].ToString(CultureInfo.CurrentCulture);
            label_S1.Text = slider[1].ToString(CultureInfo.CurrentCulture);

            int[] pov = state.GetPointOfViewControllers();

            label_P0.Text = pov[0].ToString(CultureInfo.CurrentCulture);
            label_P1.Text = pov[1].ToString(CultureInfo.CurrentCulture);
            label_P2.Text = pov[2].ToString(CultureInfo.CurrentCulture);
            label_P3.Text = pov[3].ToString(CultureInfo.CurrentCulture);

            bool[] buttons = state.GetButtons();


            for (int b = 0; b < buttons.Length; b++)
            {
                if (buttons[b])
                {
                    strText += b.ToString("00 ", CultureInfo.CurrentCulture);
                }
            }
            label_ButtonList.Text = strText;
        }
예제 #23
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FInit[0] || init || FDevice.IsChanged)
            {
                if (FInit[0])
                {
                }
                InitDevice();
                init = false;
            }

            FName.SliceCount    = Joysticks.Count;
            FXYZ.SliceCount     = Joysticks.Count;
            Fv.SliceCount       = Joysticks.Count;
            Fa.SliceCount       = Joysticks.Count;
            FRot.SliceCount     = Joysticks.Count;
            FAv.SliceCount      = Joysticks.Count;
            FAa.SliceCount      = Joysticks.Count;
            Ft.SliceCount       = Joysticks.Count;
            Ff.SliceCount       = Joysticks.Count;
            FSliders.SliceCount = Joysticks.Count;
            FPoV.SliceCount     = Joysticks.Count;
            FButtons.SliceCount = Joysticks.Count;
            FObjects.SliceCount = Joysticks.Count;

            for (int i = 0; i < Joysticks.Count; i++)
            {
                Joystick      J  = Joysticks[i];
                JoystickState Js = J.GetCurrentState();

                FName[i] = J.Information.InstanceName;
                FXYZ[i]  = new Vector3D(Js.X, Js.Y, Js.Z);
                Fv[i]    = new Vector3D(Js.VelocityX, Js.VelocityY, Js.VelocityZ);
                Fa[i]    = new Vector3D(Js.AccelerationX, Js.AccelerationY, Js.AccelerationZ);
                FRot[i]  = new Vector3D(Js.RotationX, Js.RotationY, Js.RotationZ);
                FAv[i]   = new Vector3D(Js.AngularVelocityX, Js.AngularVelocityY, Js.AngularVelocityZ);
                FAa[i]   = new Vector3D(Js.AngularAccelerationX, Js.AngularAccelerationY, Js.AngularAccelerationZ);
                Ft[i]    = new Vector3D(Js.TorqueX, Js.TorqueY, Js.TorqueZ);
                Ff[i]    = new Vector3D(Js.ForceX, Js.ForceY, Js.ForceZ);

                int[] sliders = Js.GetSliders();
                FSliders[i].SliceCount = sliders.Length;
                for (int j = 0; j < sliders.Length; j++)
                {
                    FSliders[i][j] = sliders[j];
                }

                int[] pov = Js.GetPointOfViewControllers();
                FPoV[i].SliceCount = pov.Length;
                for (int j = 0; j < pov.Length; j++)
                {
                    FPoV[i][j] = pov[j];
                }

                bool[] buttons = Js.GetButtons();
                FButtons[i].SliceCount = buttons.Length;
                for (int j = 0; j < buttons.Length; j++)
                {
                    FButtons[i][j] = buttons[j];
                }

                IList <DeviceObjectInstance> objs = J.GetObjects();
                FObjects[i].SliceCount = objs.Count;
                for (int j = 0; j < objs.Count; j++)
                {
                    FObjects[i][j] = objs[j];
                }
            }
        }
예제 #24
0
        private void updateInput()
        {
            joystick.Poll();
            JoystickState jState = joystick.GetCurrentState();

            buttons = jState.GetButtons();
            dPads   = jState.GetPointOfViewControllers();
            analogs = GetAxes(jState);

            input funcButton = Button;
            input funcAnalog = Analog;
            input funcDPad   = DPad;

            input[] funcArray = new input[] { funcButton, funcAnalog, funcDPad };

            byte[] output = new byte[21];
            // Everything should be initialized to 0, except for the Sticks, which should be centered
            output[17] = JOYSTICK_CENTER;
            output[18] = JOYSTICK_CENTER;
            output[19] = JOYSTICK_CENTER;
            output[20] = JOYSTICK_CENTER;

            for (int i = 0; i < 21; i++)
            {
                if (mapping[i * 2] == 255)
                {
                    continue;
                }
                byte subtype = (byte)(mapping[i * 2] & 0x0F);
                byte type    = (byte)((mapping[i * 2] & 0xF0) >> 4);
                byte num     = mapping[(i * 2) + 1];
                output[i] = funcArray[type](subtype, num);
            }

            cOutput.A = output[0] != 0;
            cOutput.B = output[1] != 0;
            cOutput.X = output[2] != 0;
            cOutput.Y = output[3] != 0;

            cOutput.DpadUp    = output[4] != 0;
            cOutput.DpadDown  = output[5] != 0;
            cOutput.DpadLeft  = output[6] != 0;
            cOutput.DpadRight = output[7] != 0;

            cOutput.L2 = output[9];
            cOutput.R2 = output[8];

            cOutput.L1 = output[10] != 0;
            cOutput.R1 = output[11] != 0;

            cOutput.L3 = output[12] != 0;
            cOutput.R3 = output[13] != 0;

            cOutput.Home  = output[14] != 0;
            cOutput.Start = output[15] != 0;
            cOutput.Back  = output[16] != 0;


            cOutput.LY = getDeadzonedJoystickAxis(output[17], mapping[43]);
            cOutput.LX = getDeadzonedJoystickAxis(output[18], mapping[43]);
            cOutput.RY = getDeadzonedJoystickAxis(output[19], mapping[45]);
            cOutput.RX = getDeadzonedJoystickAxis(output[20], mapping[45]);
        }
 public void GetControllerState(Joystick PlayerControllerX)
 {
     State             = PlayerControllerX.GetCurrentState();
     ControllerButtons = State.GetButtons();
     ControllerDPad    = State.GetPointOfViewControllers();
 }
예제 #26
0
        public void tポーリング(bool bWindowがアクティブ中, bool bバッファ入力を使用する)
        {
            #region [ bButtonフラグ初期化 ]
            for (int i = 0; i < 256; i++)
            {
                this.bButtonPushDown[i] = false;
                this.bButtonPullUp[i]   = false;
            }
            #endregion

            if ((bWindowがアクティブ中 && !this.devJoystick.Acquire().IsFailure) && !this.devJoystick.Poll().IsFailure)
            {
                // this.list入力イベント = new List<STInputEvent>( 32 );
                this.list入力イベント.Clear();                                                                // #xxxxx 2012.6.11 yyagi; To optimize, I removed new();


                if (bバッファ入力を使用する)
                {
                    #region [ a.バッファ入力 ]
                    //-----------------------------
                    var bufferedData = this.devJoystick.GetBufferedData();
                    if (Result.Last.IsSuccess && bufferedData != null)
                    {
                        foreach (JoystickState data in bufferedData)
                        {
#if false
//if ( 0 < data.X && data.X < 128 && 0 < data.Y && data.Y < 128 && 0 < data.Z && data.Z < 128 )
                            {
                                Trace.TraceInformation("TS={0}: offset={4}, X={1},Y={2},Z={3}", data.TimeStamp, data.X, data.Y, data.Z, data.JoystickDeviceType);
                                if (data.JoystickDeviceType == (int)JoystickDeviceType.POV0 ||
                                    data.JoystickDeviceType == (int)JoystickDeviceType.POV1 ||
                                    data.JoystickDeviceType == (int)JoystickDeviceType.POV2 ||
                                    data.JoystickDeviceType == (int)JoystickDeviceType.POV3)
                                {
//if ( data.JoystickDeviceType== (int)JoystickDeviceType.POV0 )
//{
                                    Debug.WriteLine("POV0です!!");
                                }
//Trace.TraceInformation( "TS={0}: X={1},Y={2},Z={3}", data.TimeStamp, data.X, data.Y, data.Z );
                                string pp  = "";
                                int[]  pp0 = data.GetPointOfViewControllers();
                                for (int ii = 0; ii < pp0.Length; ii++)
                                {
                                    pp += pp0[ii];
                                }
                                Trace.TraceInformation("TS={0}: povs={1}", data.TimeStamp, pp);
                                string pp2 = "", pp3 = "";
                                for (int ii = 0; ii < 32; ii++)
                                {
                                    pp2 += (data.IsPressed(ii)) ? "1" : "0";
                                    pp3 += (data.IsReleased(ii)) ? "1" : "0";
                                }
                                Trace.TraceInformation("TS={0}: IsPressed={1}, IsReleased={2}", data.TimeStamp, pp2, pp3);
                            }
#endif
                            switch (data.JoystickDeviceType)
                            {
                            case (int)JoystickDeviceType.X:
                                #region [ X軸- ]
                                //-----------------------------
                                bButtonUpDown(data, data.X, 0, 1);
                                //-----------------------------
                                #endregion
                                #region [ X軸+ ]
                                //-----------------------------
                                bButtonUpDown(data, data.X, 1, 0);
                                //-----------------------------
                                #endregion
                                break;

                            case (int)JoystickDeviceType.Y:
                                #region [ Y軸- ]
                                //-----------------------------
                                bButtonUpDown(data, data.Y, 2, 3);
                                //-----------------------------
                                #endregion
                                #region [ Y軸+ ]
                                //-----------------------------
                                bButtonUpDown(data, data.Y, 3, 2);
                                #endregion
                                break;

                            case (int)JoystickDeviceType.Z:
                                #region [ Z軸- ]
                                //-----------------------------
                                bButtonUpDown(data, data.Z, 4, 5);
                                //-----------------------------
                                #endregion
                                #region [ Z軸+ ]
                                //-----------------------------
                                bButtonUpDown(data, data.Z, 5, 4);
                                #endregion
                                break;

                            case (int)JoystickDeviceType.POV0:
                            case (int)JoystickDeviceType.POV1:
                            case (int)JoystickDeviceType.POV2:
                            case (int)JoystickDeviceType.POV3:
                                // #24341 2011.3.12 yyagi: POV support
                                // #26880 2011.12.6 yyagi: improve to support "pullup" of POV buttons
                                #region [ POV HAT 4/8way ]
                                int[] povs = data.GetPointOfViewControllers();
                                if (povs != null)
                                {
                                    STInputEvent e = new STInputEvent();
                                    int          p = ((int)data.JoystickDeviceType - (int)JoystickDeviceType.POV0) / ((int)JoystickDeviceType.POV1 - (int)JoystickDeviceType.POV0);                                             // p = 0,1,2,3
                                    // #31030 2013.3.25 yyagi; p is not 0123 but 048.. Sop must be divided into 4 ( POV1 - POV0 == 4).
                                    int nPovDegree = povs[p];
                                    int nWay       = (nPovDegree + 2250) / 4500;
                                    if (nWay == 8)
                                    {
                                        nWay = 0;
                                    }
                                    //Debug.WriteLine( "POVS:" + povs[ 0 ].ToString( CultureInfo.CurrentCulture ) + ", " +stevent.nKey );
//Debug.WriteLine( "nPovDegree=" + nPovDegree );
                                    if (nPovDegree == -1)
                                    {
                                        e.nKey            = 6 + 128 + this.nPovState[p];
                                        this.nPovState[p] = -1;
//Debug.WriteLine( "POVS離された" + data.TimeStamp + " " + e.nKey );
                                        e.b押された     = false;
                                        e.nVelocity = 0;
                                        this.bButtonState[e.nKey]  = false;
                                        this.bButtonPullUp[e.nKey] = true;
                                    }
                                    else
                                    {
                                        this.nPovState[p]            = nWay;
                                        e.nKey                       = 6 + 128 + nWay;
                                        e.b押された                      = true;
                                        e.nVelocity                  = CInput管理.n通常音量;
                                        this.bButtonState[e.nKey]    = true;
                                        this.bButtonPushDown[e.nKey] = true;
//Debug.WriteLine( "POVS押された" + data.TimeStamp + " " + e.nKey );
                                    }
                                    //e.nTimeStamp = data.TimeStamp;
                                    e.nTimeStamp = CSound管理.rc演奏用タイマ.nサウンドタイマーのシステム時刻msへの変換(data.TimeStamp);
                                    this.list入力イベント.Add(e);
                                }
                                #endregion
                                break;

                            default:
                                #region [ ボタン ]
                                //-----------------------------
                                for (int i = 0; i < 32; i++)
                                {
                                    if (data.IsPressed(i))
                                    {
                                        STInputEvent e = new STInputEvent()
                                        {
                                            nKey       = 6 + i,
                                            b押された      = true,
                                            b離された      = false,
                                            nTimeStamp = CSound管理.rc演奏用タイマ.nサウンドタイマーのシステム時刻msへの変換(data.TimeStamp),
                                            nVelocity  = CInput管理.n通常音量
                                        };
                                        this.list入力イベント.Add(e);

                                        this.bButtonState[6 + i]    = true;
                                        this.bButtonPushDown[6 + i] = true;
                                    }
                                    else if (data.IsReleased(i))
                                    {
                                        var ev = new STInputEvent()
                                        {
                                            nKey       = 6 + i,
                                            b押された      = false,
                                            b離された      = true,
                                            nTimeStamp = CSound管理.rc演奏用タイマ.nサウンドタイマーのシステム時刻msへの変換(data.TimeStamp),
                                            nVelocity  = CInput管理.n通常音量,
                                        };
                                        this.list入力イベント.Add(ev);

                                        this.bButtonState[6 + i]  = false;
                                        this.bButtonPullUp[6 + i] = true;
                                    }
                                }
                                //-----------------------------
                                #endregion
                                break;
                            }
                        }
                    }
                    //-----------------------------
                    #endregion
                }
                else
                {
                    #region [ b.状態入力 ]
                    //-----------------------------
                    JoystickState currentState = this.devJoystick.GetCurrentState();
                    if (Result.Last.IsSuccess && currentState != null)
                    {
                        #region [ X軸- ]
                        //-----------------------------
                        if (currentState.X < -500)
                        {
                            if (this.bButtonState[0] == false)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 0,
                                    b押された      = true,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[0]    = true;
                                this.bButtonPushDown[0] = true;
                            }
                        }
                        else
                        {
                            if (this.bButtonState[0] == true)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 0,
                                    b押された      = false,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[0]  = false;
                                this.bButtonPullUp[0] = true;
                            }
                        }
                        //-----------------------------
                        #endregion
                        #region [ X軸+ ]
                        //-----------------------------
                        if (currentState.X > 500)
                        {
                            if (this.bButtonState[1] == false)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 1,
                                    b押された      = true,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[1]    = true;
                                this.bButtonPushDown[1] = true;
                            }
                        }
                        else
                        {
                            if (this.bButtonState[1] == true)
                            {
                                STInputEvent event7 = new STInputEvent()
                                {
                                    nKey       = 1,
                                    b押された      = false,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(event7);

                                this.bButtonState[1]  = false;
                                this.bButtonPullUp[1] = true;
                            }
                        }
                        //-----------------------------
                        #endregion
                        #region [ Y軸- ]
                        //-----------------------------
                        if (currentState.Y < -500)
                        {
                            if (this.bButtonState[2] == false)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 2,
                                    b押された      = true,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[2]    = true;
                                this.bButtonPushDown[2] = true;
                            }
                        }
                        else
                        {
                            if (this.bButtonState[2] == true)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 2,
                                    b押された      = false,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[2]  = false;
                                this.bButtonPullUp[2] = true;
                            }
                        }
                        //-----------------------------
                        #endregion
                        #region [ Y軸+ ]
                        //-----------------------------
                        if (currentState.Y > 500)
                        {
                            if (this.bButtonState[3] == false)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 3,
                                    b押された      = true,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[3]    = true;
                                this.bButtonPushDown[3] = true;
                            }
                        }
                        else
                        {
                            if (this.bButtonState[3] == true)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 3,
                                    b押された      = false,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[3]  = false;
                                this.bButtonPullUp[3] = true;
                            }
                        }
                        //-----------------------------
                        #endregion
                        #region [ Z軸- ]
                        //-----------------------------
                        if (currentState.Z < -500)
                        {
                            if (this.bButtonState[4] == false)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 4,
                                    b押された      = true,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[4]    = true;
                                this.bButtonPushDown[4] = true;
                            }
                        }
                        else
                        {
                            if (this.bButtonState[4] == true)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 4,
                                    b押された      = false,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[4]  = false;
                                this.bButtonPullUp[4] = true;
                            }
                        }
                        //-----------------------------
                        #endregion
                        #region [ Z軸+ ]
                        //-----------------------------
                        if (currentState.Z > 500)
                        {
                            if (this.bButtonState[5] == false)
                            {
                                STInputEvent ev = new STInputEvent()
                                {
                                    nKey       = 5,
                                    b押された      = true,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(ev);

                                this.bButtonState[5]    = true;
                                this.bButtonPushDown[5] = true;
                            }
                        }
                        else
                        {
                            if (this.bButtonState[5] == true)
                            {
                                STInputEvent event15 = new STInputEvent()
                                {
                                    nKey       = 5,
                                    b押された      = false,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(event15);

                                this.bButtonState[5]  = false;
                                this.bButtonPullUp[5] = true;
                            }
                        }
                        //-----------------------------
                        #endregion
                        #region [ ボタン ]
                        //-----------------------------
                        bool   bIsButtonPressedReleased = false;
                        bool[] buttons = currentState.GetButtons();
                        for (int j = 0; (j < buttons.Length) && (j < 128); j++)
                        {
                            if (this.bButtonState[6 + j] == false && buttons[j])
                            {
                                STInputEvent item = new STInputEvent()
                                {
                                    nKey       = 6 + j,
                                    b押された      = true,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(item);

                                this.bButtonState[6 + j]    = true;
                                this.bButtonPushDown[6 + j] = true;
                                bIsButtonPressedReleased    = true;
                            }
                            else if (this.bButtonState[6 + j] == true && !buttons[j])
                            {
                                STInputEvent item = new STInputEvent()
                                {
                                    nKey       = 6 + j,
                                    b押された      = false,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                    nVelocity  = CInput管理.n通常音量
                                };
                                this.list入力イベント.Add(item);

                                this.bButtonState[6 + j]  = false;
                                this.bButtonPullUp[6 + j] = true;
                                bIsButtonPressedReleased  = true;
                            }
                        }
                        //-----------------------------
                        #endregion
                        // #24341 2011.3.12 yyagi: POV support
                        #region [ POV HAT 4/8way (only single POV switch is supported)]
                        int[] povs = currentState.GetPointOfViewControllers();
                        if (povs != null)
                        {
                            if (povs[0] >= 0)
                            {
                                int nPovDegree = povs[0];
                                int nWay       = (nPovDegree + 2250) / 4500;
                                if (nWay == 8)
                                {
                                    nWay = 0;
                                }

                                if (this.bButtonState[6 + 128 + nWay] == false)
                                {
                                    STInputEvent stevent = new STInputEvent()
                                    {
                                        nKey = 6 + 128 + nWay,
                                        //Debug.WriteLine( "POVS:" + povs[ 0 ].ToString( CultureInfo.CurrentCulture ) + ", " +stevent.nKey );
                                        b押された      = true,
                                        nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                         // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                        nVelocity  = CInput管理.n通常音量
                                    };
                                    this.list入力イベント.Add(stevent);

                                    this.bButtonState[stevent.nKey]    = true;
                                    this.bButtonPushDown[stevent.nKey] = true;
                                }
                            }
                            else if (bIsButtonPressedReleased == false)                                 // #xxxxx 2011.12.3 yyagi 他のボタンが何も押され/離されてない=POVが離された
                            {
                                int nWay = 0;
                                for (int i = 6 + 0x80; i < 6 + 0x80 + 8; i++)
                                {                                                                               // 離されたボタンを調べるために、元々押されていたボタンを探す。
                                    if (this.bButtonState[i] == true)                                           // DirectInputを直接いじるならこんなことしなくて良いのに、あぁ面倒。
                                    {                                                                           // この処理が必要なために、POVを1個しかサポートできない。無念。
                                        nWay = i;
                                        break;
                                    }
                                }
                                if (nWay != 0)
                                {
                                    STInputEvent stevent = new STInputEvent()
                                    {
                                        nKey       = nWay,
                                        b押された      = false,
                                        nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻,                                         // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                        nVelocity  = 0
                                    };
                                    this.list入力イベント.Add(stevent);

                                    this.bButtonState[nWay]  = false;
                                    this.bButtonPullUp[nWay] = true;
                                }
                            }
                        }
                        #endregion
                    }
                    //-----------------------------
                    #endregion
                }
            }
        }
예제 #27
0
        private void updateInput()
        {
            joystick.Poll();
            JoystickState jState = joystick.GetCurrentState();

            buttons = jState.GetButtons();
            dPads   = jState.GetPointOfViewControllers();
            analogs = GetAxes(jState);
            sliders = jState.GetSliders();

            input funcButton = Button;  //assigns a function that checks, whether a button is pressed to the delegate funcButton
            input funcAnalog = Analog;  //same for Analog, DPad and Slider
            input funcDPad   = DPad;
            input funcSlider = Slider;

            input[] funcArray = new input[] { funcButton, funcAnalog, funcDPad, funcSlider };   //assigns the delegates to an array

            byte[] output = new byte[25];
            for (int i = 0; i < 25; i++)
            {
                if (mapping[i * 2] == 255)
                {
                    continue;
                }
                byte subtype = (byte)(mapping[i * 2] & 0x0F);
                byte type    = (byte)((mapping[i * 2] & 0xF0) >> 4);
                byte num     = mapping[(i * 2) + 1];
                output[i] = funcArray[type](subtype, num);  //does the actual check, what value control num of type and subtype has
            }

            cOutput.A = output[0] != 0; //for buttons, the cOutput will be either true or false
            cOutput.B = output[1] != 0;
            cOutput.X = output[2] != 0;
            cOutput.Y = output[3] != 0;

            cOutput.Home  = output[4] != 0;
            cOutput.Start = output[5] != 0;
            cOutput.Back  = output[6] != 0;

            cOutput.DpadUp    = output[7] != 0;
            cOutput.DpadDown  = output[8] != 0;
            cOutput.DpadLeft  = output[9] != 0;
            cOutput.DpadRight = output[10] != 0;

            cOutput.L2 = (byte)(output[12] * 2); //for axes, the cOutput will be the actual value
            cOutput.R2 = (byte)(output[11] * 2);

            cOutput.L1 = output[13] != 0;
            cOutput.R1 = output[14] != 0;

            cOutput.L3 = output[15] != 0;
            cOutput.R3 = output[20] != 0;

            /*
             * cOutput.LY = output[17];
             * cOutput.LX = output[18];
             * cOutput.RY = output[19];
             * cOutput.RX = output[20];
             */

            // experimental for up/down options
            cOutput.LY = (byte)(127 + output[17] - output[16]); //inverted since up is - axis
            cOutput.LX = (byte)(127 + output[18] - output[19]);
            cOutput.RY = (byte)(127 + output[22] - output[21]);
            cOutput.RX = (byte)(127 + output[23] - output[24]);
        }
예제 #28
0
 public double GetValue(JoystickState joystickState, int povIndex)
 {
     // Position is degrees from North.
     return(joystickState.GetPointOfViewControllers()[povIndex] / 100d);
 }
        /// <summary>Converts a joystick state into an XNA game pad state</summary>
        /// <param name="joystickState">Joystick state that will be converted</param>
        /// <returns>The equivalent XNA game pad state</returns>
        internal GamePadState Convert(ref JoystickState joystickState)
        {
            // Read the current states of both thumb sticks
            Vector2 leftThumbstick, rightThumbstick;
            {
                if (this.axisReaders[0] != null)
                {
                    leftThumbstick.X = this.axisReaders[0].GetValue(ref joystickState);
                }
                else
                {
                    leftThumbstick.X = 0.0f;
                }
                if (this.axisReaders[1] != null)
                {
                    leftThumbstick.Y = -this.axisReaders[1].GetValue(ref joystickState);
                }
                else
                {
                    leftThumbstick.Y = 0.0f;
                }

                if (this.axisReaders[12] != null)
                {
                    rightThumbstick.X = this.axisReaders[12].GetValue(ref joystickState);
                }
                else
                {
                    rightThumbstick.X = 0.0f;
                }
                if (this.axisReaders[13] != null)
                {
                    rightThumbstick.Y = -this.axisReaders[13].GetValue(ref joystickState);
                }
                else
                {
                    rightThumbstick.Y = 0.0f;
                }
            }

            // Read the current states of the triggers
            float leftTrigger, rightTrigger;
            {
                if (this.sliderReaders[0] != null)
                {
                    leftTrigger = this.sliderReaders[0].GetValue(ref joystickState);
                }
                else
                {
                    leftTrigger = 0.0f;
                }
                if (this.sliderReaders[1] != null)
                {
                    rightTrigger = this.sliderReaders[1].GetValue(ref joystickState);
                }
                else
                {
                    rightTrigger = 0.0f;
                }
            }

            // Convert the button states
            Buttons buttons = 0;
            {
                Buttons[] buttonOrder   = ExtendedGamePadState.ButtonOrder;
                bool[]    buttonPressed = joystickState.GetButtons();

                int count = Math.Min(buttonOrder.Length, this.buttonCount);
                for (int index = 0; index < count; ++index)
                {
                    if (buttonPressed[index])
                    {
                        buttons |= buttonOrder[index];
                    }
                }
            }

            // Convert the first PoV controller into a directional pad
            GamePadDPad dpad;

            {
                if (this.povCount > 0)
                {
                    int[] povs = joystickState.GetPointOfViewControllers();
                    dpad = ExtendedGamePadState.DpadFromPov(povs[0]);
                }
                else
                {
                    dpad = new GamePadDPad();
                }
            }

            // All informations gathered, construct the game pad state
            return(new GamePadState(
                       new GamePadThumbSticks(leftThumbstick, rightThumbstick),
                       new GamePadTriggers(leftTrigger, rightTrigger),
                       new XnaGamePadButtons(buttons),
                       dpad
                       ));
        }
    /// <summary>
    ///   Initializes a new game pad state from a DirectInput joystick state
    /// </summary>
    /// <param name="converter">DirectInput converter used to fill the state</param>
    /// <param name="joystickState">
    ///   Joystick state from which the game pad state will be built
    /// </param>
    internal GamePadState(
      DirectInputConverter converter, ref JoystickState joystickState
      )
    {
      // Take over the joystick's axes
      {
        this.AvailableAxes = converter.AvailableAxes;
        DirectInputConverter.IAxisReader[] axisReaders = converter.AxisReaders;

        if (axisReaders[0] != null)
        {
          this.X = axisReaders[0].GetValue(ref joystickState);
        }
        else
        {
          this.X = 0.0f;
        }
        if (axisReaders[1] != null)
        {
          this.Y = -axisReaders[1].GetValue(ref joystickState);
        }
        else
        {
          this.Y = 0.0f;
        }
        if (axisReaders[2] != null)
        {
          this.Z = axisReaders[2].GetValue(ref joystickState);
        }
        else
        {
          this.Z = 0.0f;
        }

        if (axisReaders[3] != null)
        {
          this.VelocityX = axisReaders[3].GetValue(ref joystickState);
        }
        else
        {
          this.VelocityX = 0.0f;
        }
        if (axisReaders[4] != null)
        {
          this.VelocityY = -axisReaders[4].GetValue(ref joystickState);
        }
        else
        {
          this.VelocityY = 0.0f;
        }
        if (axisReaders[5] != null)
        {
          this.VelocityZ = axisReaders[5].GetValue(ref joystickState);
        }
        else
        {
          this.VelocityZ = 0.0f;
        }

        if (axisReaders[6] != null)
        {
          this.AccelerationX = axisReaders[6].GetValue(ref joystickState);
        }
        else
        {
          this.AccelerationX = 0.0f;
        }
        if (axisReaders[7] != null)
        {
          this.AccelerationY = -axisReaders[7].GetValue(ref joystickState);
        }
        else
        {
          this.AccelerationY = 0.0f;
        }
        if (axisReaders[8] != null)
        {
          this.AccelerationZ = axisReaders[8].GetValue(ref joystickState);
        }
        else
        {
          this.AccelerationZ = 0.0f;
        }

        if (axisReaders[9] != null)
        {
          this.ForceX = axisReaders[9].GetValue(ref joystickState);
        }
        else
        {
          this.ForceX = 0.0f;
        }
        if (axisReaders[10] != null)
        {
          this.ForceY = -axisReaders[10].GetValue(ref joystickState);
        }
        else
        {
          this.ForceY = 0.0f;
        }
        if (axisReaders[11] != null)
        {
          this.ForceZ = axisReaders[11].GetValue(ref joystickState);
        }
        else
        {
          this.ForceZ = 0.0f;
        }

        if (axisReaders[12] != null)
        {
          this.RotationX = axisReaders[12].GetValue(ref joystickState);
        }
        else
        {
          this.RotationX = 0.0f;
        }
        if (axisReaders[13] != null)
        {
          this.RotationY = -axisReaders[13].GetValue(ref joystickState);
        }
        else
        {
          this.RotationY = 0.0f;
        }
        if (axisReaders[14] != null)
        {
          this.RotationZ = axisReaders[14].GetValue(ref joystickState);
        }
        else
        {
          this.RotationZ = 0.0f;
        }

        if (axisReaders[15] != null)
        {
          this.AngularVelocityX = axisReaders[15].GetValue(ref joystickState);
        }
        else
        {
          this.AngularVelocityX = 0.0f;
        }
        if (axisReaders[16] != null)
        {
          this.AngularVelocityY = -axisReaders[16].GetValue(ref joystickState);
        }
        else
        {
          this.AngularVelocityY = 0.0f;
        }
        if (axisReaders[17] != null)
        {
          this.AngularVelocityZ = axisReaders[17].GetValue(ref joystickState);
        }
        else
        {
          this.AngularVelocityZ = 0.0f;
        }

        if (axisReaders[18] != null)
        {
          this.AngularAccelerationX = axisReaders[18].GetValue(ref joystickState);
        }
        else
        {
          this.AngularAccelerationX = 0.0f;
        }
        if (axisReaders[19] != null)
        {
          this.AngularAccelerationY = -axisReaders[19].GetValue(ref joystickState);
        }
        else
        {
          this.AngularAccelerationY = 0.0f;
        }
        if (axisReaders[20] != null)
        {
          this.AngularAccelerationZ = axisReaders[20].GetValue(ref joystickState);
        }
        else
        {
          this.AngularAccelerationZ = 0.0f;
        }

        if (axisReaders[21] != null)
        {
          this.TorqueX = axisReaders[21].GetValue(ref joystickState);
        }
        else
        {
          this.TorqueX = 0.0f;
        }
        if (axisReaders[22] != null)
        {
          this.TorqueY = -axisReaders[22].GetValue(ref joystickState);
        }
        else
        {
          this.TorqueY = 0.0f;
        }
        if (axisReaders[23] != null)
        {
          this.TorqueZ = axisReaders[23].GetValue(ref joystickState);
        }
        else
        {
          this.TorqueZ = 0.0f;
        }
      }

      // Take over the joystick's buttons
      {
        this.ButtonCount = converter.ButtonCount;
        bool[] buttonPressed = joystickState.GetButtons();

        this.buttonState1 = 0;
        for (int index = 0; index < Math.Min(64, ButtonCount); ++index)
        {
          if (buttonPressed[index])
          {
            this.buttonState1 |= (1UL << index);
          }
        }

        this.buttonState2 = 0;
        for (int index = 0; index < (ButtonCount - 64); ++index)
        {
          if (buttonPressed[index + 64])
          {
            this.buttonState2 |= (1UL << index);
          }
        }
      }

      // Take over the joystick's sliders
      {
        this.AvailableSliders = converter.AvailableSliders;
        DirectInputConverter.ISliderReader[] sliderReaders = converter.SliderReaders;

        if (sliderReaders[0] != null)
        {
          this.Slider1 = sliderReaders[0].GetValue(ref joystickState);
        }
        else
        {
          this.Slider1 = 0.0f;
        }
        if (sliderReaders[1] != null)
        {
          this.Slider2 = sliderReaders[1].GetValue(ref joystickState);
        }
        else
        {
          this.Slider2 = 0.0f;
        }

        if (sliderReaders[2] != null)
        {
          this.VelocitySlider1 = sliderReaders[2].GetValue(ref joystickState);
        }
        else
        {
          this.VelocitySlider1 = 0.0f;
        }
        if (sliderReaders[3] != null)
        {
          this.VelocitySlider2 = sliderReaders[3].GetValue(ref joystickState);
        }
        else
        {
          this.VelocitySlider2 = 0.0f;
        }

        if (sliderReaders[4] != null)
        {
          this.AccelerationSlider1 = sliderReaders[4].GetValue(ref joystickState);
        }
        else
        {
          this.AccelerationSlider1 = 0.0f;
        }
        if (sliderReaders[5] != null)
        {
          this.AccelerationSlider2 = sliderReaders[5].GetValue(ref joystickState);
        }
        else
        {
          this.AccelerationSlider2 = 0.0f;
        }

        if (sliderReaders[6] != null)
        {
          this.ForceSlider1 = sliderReaders[6].GetValue(ref joystickState);
        }
        else
        {
          this.ForceSlider1 = 0.0f;
        }
        if (sliderReaders[7] != null)
        {
          this.ForceSlider2 = sliderReaders[7].GetValue(ref joystickState);
        }
        else
        {
          this.ForceSlider2 = 0.0f;
        }
      }

      // Take over the joystick's Point-of-View controllers
      {
        this.PovCount = converter.PovCount;

        int[] povs = null;
        if (this.PovCount >= 1)
        {
          povs = joystickState.GetPointOfViewControllers();
          this.Pov1 = povs[0];
        }
        else
        {
          this.Pov1 = -1;
        }
        if (this.PovCount >= 2)
        {
          this.Pov2 = povs[1];
        }
        else
        {
          this.Pov2 = -1;
        }
        if (this.PovCount >= 3)
        {
          this.Pov3 = povs[2];
        }
        else
        {
          this.Pov3 = -1;
        }
        if (this.PovCount >= 4)
        {
          this.Pov4 = povs[3];
        }
        else
        {
          this.Pov4 = -1;
        }
      }
    }
예제 #31
0
        private void ComputeInputs()
        {
            // Pull from joystick
            if (joystick != null)
            {
                joystick.Poll();
                state = joystick.GetCurrentState();
                pov_state = (POV_HAT_DIR)state.GetPointOfViewControllers()[0];
                button_state = state.GetButtons();
                control_x = state.X;
                control_y = state.Y;
                control_z = state.RotationZ;
                control_throttle = state.GetSliders()[0];
                if (control_x > 0 && control_x < JOYSTICK_XY_DEADBAND) { control_x = 0; }
                if (control_x < 0 && control_x > -JOYSTICK_XY_DEADBAND) { control_x = 0; }
                if (control_y > 0 && control_y < JOYSTICK_XY_DEADBAND) { control_y = 0; }
                if (control_y < 0 && control_y > -JOYSTICK_XY_DEADBAND) { control_y = 0; }
                if (control_z > 0 && control_z < JOYSTICK_Z_DEADBAND) { control_z = 0; }
                if (control_z < 0 && control_z > -JOYSTICK_Z_DEADBAND) { control_z = 0; }
            }
            else
            {
                state = new JoystickState();
                button_state = new bool[] { false, false, false, false };
                control_x = 0;
                control_y = 0;
                pov_state = POV_HAT_DIR.NONE;
            }

            // Turret
            switch (pov_state)
            {
                case POV_HAT_DIR.NW:
                    turret_vert_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_horiz_fwd = true;// left
                    break;
                case POV_HAT_DIR.N:
                    turret_vert_pwr = TURRET_VERT_SPEED_MED;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = 0;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.NE:
                    turret_vert_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.E:
                    turret_vert_pwr = 0;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = TURRET_VERT_SPEED_MED;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.SE:
                    turret_vert_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_vert_fwd = false;// up
                    turret_horiz_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.S:
                    turret_vert_pwr = TURRET_VERT_SPEED_MED;
                    turret_vert_fwd = false;// up
                    turret_horiz_pwr = 0;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.SW:
                    turret_vert_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_vert_fwd = false;// up
                    turret_horiz_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_horiz_fwd = true;// left
                    break;
                case POV_HAT_DIR.W:
                    turret_vert_pwr = 0;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = TURRET_VERT_SPEED_MED;
                    turret_horiz_fwd = true;// left
                    break;

                default:
                    turret_vert_pwr = 0;
                    turret_horiz_pwr = 0;
                    break;
            }

            // Normal weapons
            /*if (button_state[0])
            {
                weapon1_fwd = true;
                weapon1_pwr = 255;
            }
            else
            {
                weapon1_fwd = true;
                weapon1_pwr = 0;
            }
            if (button_state[1])
            {
                weapon2_fwd = false;
                weapon2_pwr = 255;
            }
            else
            {
                weapon2_fwd = false;
                weapon2_pwr = 0;
            }*/

            // Lighting unit
            int light_power = (int)((-control_throttle + 1000.0) * (255.0 / 2000.0));
            switch (comboBoxLightType.SelectedIndex)
            {
                case 0: // white
                default:
                    weapon1_fwd = false;
                    weapon1_pwr = light_power;
                    weapon2_pwr = 0;
                    break;
                case 1: // IR
                    weapon2_fwd = false;
                    weapon2_pwr = light_power;
                    weapon1_pwr = 0;
                    break;
                case 2: // UV
                    weapon1_fwd = true;
                    weapon1_pwr = light_power;
                    weapon2_pwr = 0;
                    break;
                case 3: // Laser
                    weapon2_fwd = true;
                    weapon2_pwr = light_power;
                    weapon1_pwr = 0;
                    break;
            }

            // Button control (overrides joystick)
            if (DateTime.Now < w_button_effective_until)
            { control_y = -BUTTON_POWER; }
            else if (DateTime.Now < s_button_effective_until)
            { control_y = BUTTON_POWER; }
            if (DateTime.Now < a_button_effective_until)
            { control_x = -BUTTON_POWER; }
            else if (DateTime.Now < d_button_effective_until)
            { control_x = BUTTON_POWER; }
        }
예제 #32
0
        private void InitializeCallbacks()
        {
            const int dzp = 400;
            const int dzn = -400;

            _names.Clear();
            _actions.Clear();
            NumButtons = 0;

            AddItem("AccelerationX+", () => _state.AccelerationX >= dzp);
            AddItem("AccelerationX-", () => _state.AccelerationX <= dzn);
            AddItem("AccelerationY+", () => _state.AccelerationY >= dzp);
            AddItem("AccelerationY-", () => _state.AccelerationY <= dzn);
            AddItem("AccelerationZ+", () => _state.AccelerationZ >= dzp);
            AddItem("AccelerationZ-", () => _state.AccelerationZ <= dzn);
            AddItem("AngularAccelerationX+", () => _state.AngularAccelerationX >= dzp);
            AddItem("AngularAccelerationX-", () => _state.AngularAccelerationX <= dzn);
            AddItem("AngularAccelerationY+", () => _state.AngularAccelerationY >= dzp);
            AddItem("AngularAccelerationY-", () => _state.AngularAccelerationY <= dzn);
            AddItem("AngularAccelerationZ+", () => _state.AngularAccelerationZ >= dzp);
            AddItem("AngularAccelerationZ-", () => _state.AngularAccelerationZ <= dzn);
            AddItem("AngularVelocityX+", () => _state.AngularVelocityX >= dzp);
            AddItem("AngularVelocityX-", () => _state.AngularVelocityX <= dzn);
            AddItem("AngularVelocityY+", () => _state.AngularVelocityY >= dzp);
            AddItem("AngularVelocityY-", () => _state.AngularVelocityY <= dzn);
            AddItem("AngularVelocityZ+", () => _state.AngularVelocityZ >= dzp);
            AddItem("AngularVelocityZ-", () => _state.AngularVelocityZ <= dzn);
            AddItem("ForceX+", () => _state.ForceX >= dzp);
            AddItem("ForceX-", () => _state.ForceX <= dzn);
            AddItem("ForceY+", () => _state.ForceY >= dzp);
            AddItem("ForceY-", () => _state.ForceY <= dzn);
            AddItem("ForceZ+", () => _state.ForceZ >= dzp);
            AddItem("ForceZ-", () => _state.ForceZ <= dzn);
            AddItem("RotationX+", () => _state.RotationX >= dzp);
            AddItem("RotationX-", () => _state.RotationX <= dzn);
            AddItem("RotationY+", () => _state.RotationY >= dzp);
            AddItem("RotationY-", () => _state.RotationY <= dzn);
            AddItem("RotationZ+", () => _state.RotationZ >= dzp);
            AddItem("RotationZ-", () => _state.RotationZ <= dzn);
            AddItem("TorqueX+", () => _state.TorqueX >= dzp);
            AddItem("TorqueX-", () => _state.TorqueX <= dzn);
            AddItem("TorqueY+", () => _state.TorqueY >= dzp);
            AddItem("TorqueY-", () => _state.TorqueY <= dzn);
            AddItem("TorqueZ+", () => _state.TorqueZ >= dzp);
            AddItem("TorqueZ-", () => _state.TorqueZ <= dzn);
            AddItem("VelocityX+", () => _state.VelocityX >= dzp);
            AddItem("VelocityX-", () => _state.VelocityX <= dzn);
            AddItem("VelocityY+", () => _state.VelocityY >= dzp);
            AddItem("VelocityY-", () => _state.VelocityY <= dzn);
            AddItem("VelocityZ+", () => _state.VelocityZ >= dzp);
            AddItem("VelocityZ-", () => _state.VelocityZ <= dzn);
            AddItem("X+", () => _state.X >= dzp);
            AddItem("X-", () => _state.X <= dzn);
            AddItem("Y+", () => _state.Y >= dzp);
            AddItem("Y-", () => _state.Y <= dzn);
            AddItem("Z+", () => _state.Z >= dzp);
            AddItem("Z-", () => _state.Z <= dzn);

            // i don't know what the "Slider"s do, so they're omitted for the moment

            for (int i = 0; i < _state.GetButtons().Length; i++)
            {
                int j = i;
                AddItem($"B{i + 1}", () => _state.IsPressed(j));
            }

            for (int i = 0; i < _state.GetPointOfViewControllers().Length; i++)
            {
                int j = i;
                AddItem($"POV{i + 1}U", () => {
                    var t = _state.GetPointOfViewControllers()[j];
                    return(0.RangeTo(4500).Contains(t) || 31500.RangeToExclusive(36000).Contains(t));
                });
                AddItem($"POV{i + 1}D", () => 13500.RangeTo(22500).Contains(_state.GetPointOfViewControllers()[j]));
                AddItem($"POV{i + 1}L", () => 22500.RangeTo(31500).Contains(_state.GetPointOfViewControllers()[j]));
                AddItem($"POV{i + 1}R", () => 4500.RangeTo(13500).Contains(_state.GetPointOfViewControllers()[j]));
            }
        }
예제 #33
0
        /// <summary>
        ///   Initializes a new extended game pad state from a DirectInput joystick state
        /// </summary>
        /// <param name="converter">DirectInput converter used to fill the state</param>
        /// <param name="joystickState">
        ///   Joystick state from which the extended game pad state will be built
        /// </param>
        internal ExtendedGamePadState(
            DirectInputConverter converter, ref JoystickState joystickState
            )
        {
            // Take over the joystick's axes
            {
                this.AvailableAxes = converter.AvailableAxes;
                DirectInputConverter.IAxisReader[] axisReaders = converter.AxisReaders;

                if (axisReaders[0] != null)
                {
                    this.X = axisReaders[0].GetValue(ref joystickState);
                }
                else
                {
                    this.X = 0.0f;
                }
                if (axisReaders[1] != null)
                {
                    this.Y = -axisReaders[1].GetValue(ref joystickState);
                }
                else
                {
                    this.Y = 0.0f;
                }
                if (axisReaders[2] != null)
                {
                    this.Z = axisReaders[2].GetValue(ref joystickState);
                }
                else
                {
                    this.Z = 0.0f;
                }

                if (axisReaders[3] != null)
                {
                    this.VelocityX = axisReaders[3].GetValue(ref joystickState);
                }
                else
                {
                    this.VelocityX = 0.0f;
                }
                if (axisReaders[4] != null)
                {
                    this.VelocityY = -axisReaders[4].GetValue(ref joystickState);
                }
                else
                {
                    this.VelocityY = 0.0f;
                }
                if (axisReaders[5] != null)
                {
                    this.VelocityZ = axisReaders[5].GetValue(ref joystickState);
                }
                else
                {
                    this.VelocityZ = 0.0f;
                }

                if (axisReaders[6] != null)
                {
                    this.AccelerationX = axisReaders[6].GetValue(ref joystickState);
                }
                else
                {
                    this.AccelerationX = 0.0f;
                }
                if (axisReaders[7] != null)
                {
                    this.AccelerationY = -axisReaders[7].GetValue(ref joystickState);
                }
                else
                {
                    this.AccelerationY = 0.0f;
                }
                if (axisReaders[8] != null)
                {
                    this.AccelerationZ = axisReaders[8].GetValue(ref joystickState);
                }
                else
                {
                    this.AccelerationZ = 0.0f;
                }

                if (axisReaders[9] != null)
                {
                    this.ForceX = axisReaders[9].GetValue(ref joystickState);
                }
                else
                {
                    this.ForceX = 0.0f;
                }
                if (axisReaders[10] != null)
                {
                    this.ForceY = -axisReaders[10].GetValue(ref joystickState);
                }
                else
                {
                    this.ForceY = 0.0f;
                }
                if (axisReaders[11] != null)
                {
                    this.ForceZ = axisReaders[11].GetValue(ref joystickState);
                }
                else
                {
                    this.ForceZ = 0.0f;
                }

                if (axisReaders[12] != null)
                {
                    this.RotationX = axisReaders[12].GetValue(ref joystickState);
                }
                else
                {
                    this.RotationX = 0.0f;
                }
                if (axisReaders[13] != null)
                {
                    this.RotationY = -axisReaders[13].GetValue(ref joystickState);
                }
                else
                {
                    this.RotationY = 0.0f;
                }
                if (axisReaders[14] != null)
                {
                    this.RotationZ = axisReaders[14].GetValue(ref joystickState);
                }
                else
                {
                    this.RotationZ = 0.0f;
                }

                if (axisReaders[15] != null)
                {
                    this.AngularVelocityX = axisReaders[15].GetValue(ref joystickState);
                }
                else
                {
                    this.AngularVelocityX = 0.0f;
                }
                if (axisReaders[16] != null)
                {
                    this.AngularVelocityY = -axisReaders[16].GetValue(ref joystickState);
                }
                else
                {
                    this.AngularVelocityY = 0.0f;
                }
                if (axisReaders[17] != null)
                {
                    this.AngularVelocityZ = axisReaders[17].GetValue(ref joystickState);
                }
                else
                {
                    this.AngularVelocityZ = 0.0f;
                }

                if (axisReaders[18] != null)
                {
                    this.AngularAccelerationX = axisReaders[18].GetValue(ref joystickState);
                }
                else
                {
                    this.AngularAccelerationX = 0.0f;
                }
                if (axisReaders[19] != null)
                {
                    this.AngularAccelerationY = -axisReaders[19].GetValue(ref joystickState);
                }
                else
                {
                    this.AngularAccelerationY = 0.0f;
                }
                if (axisReaders[20] != null)
                {
                    this.AngularAccelerationZ = axisReaders[20].GetValue(ref joystickState);
                }
                else
                {
                    this.AngularAccelerationZ = 0.0f;
                }

                if (axisReaders[21] != null)
                {
                    this.TorqueX = axisReaders[21].GetValue(ref joystickState);
                }
                else
                {
                    this.TorqueX = 0.0f;
                }
                if (axisReaders[22] != null)
                {
                    this.TorqueY = -axisReaders[22].GetValue(ref joystickState);
                }
                else
                {
                    this.TorqueY = 0.0f;
                }
                if (axisReaders[23] != null)
                {
                    this.TorqueZ = axisReaders[23].GetValue(ref joystickState);
                }
                else
                {
                    this.TorqueZ = 0.0f;
                }
            }

            // Take over the joystick's buttons
            {
                this.ButtonCount = converter.ButtonCount;
                bool[] buttonPressed = joystickState.GetButtons();

                this.buttonState1 = 0;
                for (int index = 0; index < Math.Min(64, ButtonCount); ++index)
                {
                    if (buttonPressed[index])
                    {
                        this.buttonState1 |= (1UL << index);
                    }
                }

                this.buttonState2 = 0;
                for (int index = 0; index < (ButtonCount - 64); ++index)
                {
                    if (buttonPressed[index + 64])
                    {
                        this.buttonState2 |= (1UL << index);
                    }
                }
            }

            // Take over the joystick's sliders
            {
                this.AvailableSliders = converter.AvailableSliders;
                DirectInputConverter.ISliderReader[] sliderReaders = converter.SliderReaders;

                if (sliderReaders[0] != null)
                {
                    this.Slider1 = sliderReaders[0].GetValue(ref joystickState);
                }
                else
                {
                    this.Slider1 = 0.0f;
                }
                if (sliderReaders[1] != null)
                {
                    this.Slider2 = sliderReaders[1].GetValue(ref joystickState);
                }
                else
                {
                    this.Slider2 = 0.0f;
                }

                if (sliderReaders[2] != null)
                {
                    this.VelocitySlider1 = sliderReaders[2].GetValue(ref joystickState);
                }
                else
                {
                    this.VelocitySlider1 = 0.0f;
                }
                if (sliderReaders[3] != null)
                {
                    this.VelocitySlider2 = sliderReaders[3].GetValue(ref joystickState);
                }
                else
                {
                    this.VelocitySlider2 = 0.0f;
                }

                if (sliderReaders[4] != null)
                {
                    this.AccelerationSlider1 = sliderReaders[4].GetValue(ref joystickState);
                }
                else
                {
                    this.AccelerationSlider1 = 0.0f;
                }
                if (sliderReaders[5] != null)
                {
                    this.AccelerationSlider2 = sliderReaders[5].GetValue(ref joystickState);
                }
                else
                {
                    this.AccelerationSlider2 = 0.0f;
                }

                if (sliderReaders[6] != null)
                {
                    this.ForceSlider1 = sliderReaders[6].GetValue(ref joystickState);
                }
                else
                {
                    this.ForceSlider1 = 0.0f;
                }
                if (sliderReaders[7] != null)
                {
                    this.ForceSlider2 = sliderReaders[7].GetValue(ref joystickState);
                }
                else
                {
                    this.ForceSlider2 = 0.0f;
                }
            }

            // Take over the joystick's Point-of-View controllers
            {
                this.PovCount = converter.PovCount;

                int[] povs = null;
                if (this.PovCount >= 1)
                {
                    povs      = joystickState.GetPointOfViewControllers();
                    this.Pov1 = povs[0];
                }
                else
                {
                    this.Pov1 = -1;
                }
                if (this.PovCount >= 2)
                {
                    this.Pov2 = povs[1];
                }
                else
                {
                    this.Pov2 = -1;
                }
                if (this.PovCount >= 3)
                {
                    this.Pov3 = povs[2];
                }
                else
                {
                    this.Pov3 = -1;
                }
                if (this.PovCount >= 4)
                {
                    this.Pov4 = povs[3];
                }
                else
                {
                    this.Pov4 = -1;
                }
            }
        }
예제 #34
0
 public double GetValue(JoystickState joystickState, int povIndex)
 {
     // Position is degrees from North.
     return joystickState.GetPointOfViewControllers()[povIndex] / 100d;
 }