Esempio n. 1
0
        //public static Capabilities DevCaps;

        public static void Initialize()
        {
            if (dinput == null)
            {
                dinput = new DirectInput();
            }

            Devices = new List <GamePad>();

            DIAxisInfo = new List <di_axis_info>();

            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                Console.WriteLine("joydevice: {0} `{1}`", device.InstanceGuid, device.ProductName);

                if (device.ProductName.Contains("XBOX 360"))
                {
                    continue; // Don't input XBOX 360 controllers into here; we'll process them via XInput (there are limitations in some trigger axes when xbox pads go over xinput)
                }
                var joystick = new Joystick(dinput, device.InstanceGuid);
                //joystick.SetCooperativeLevel(GlobalWin.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);


                int count = 0;
                foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
                {
                    if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    {
                        joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                    }

                    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 = count;
                        dai.maximum           = max;
                        dai.minimum           = min;
                        DIAxisInfo.Add(dai);
                    }
                    count++;
                }
                joystick.Acquire();


                GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick, DIAxisInfo);
                Devices.Add(p);
            }
        }
Esempio n. 2
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++;
                }
            }
        }