Esempio n. 1
0
        // Get absolute value / limits
        public static int GetAbs(int fd, EvdevAxis axis, out InputAbsInfo info)
        {
            info = default(InputAbsInfo);
            unsafe
            {
                fixed(InputAbsInfo *pinfo = &info)
                {
                    // EVIOCGABS(abs) = _IOR('E', 0x40 + (abs), struct input_absinfo)
                    uint ioctl  = IOCreate(DirectionFlags.Read, (int)axis + 0x40, BlittableValueType <InputAbsInfo> .Stride);
                    int  retval = Libc.ioctl(fd, ioctl, new IntPtr(pinfo));

                    return(retval);
                }
            }
        }
        // Get absolute value / limits
        public static int GetAbs(int fd, EvdevAxis axis, out InputAbsInfo info)
        {
            info = default(InputAbsInfo);
            unsafe
            {
                fixed(InputAbsInfo *pinfo = &info)
                {
                    // EVIOCGABS(abs) = _IOR('E', 0x40 + (abs), struct input_absinfo)
                    var ioctl  = IOCreate(DirectionFlags.Read, (int)axis + 0x40, Marshal.SizeOf <InputAbsInfo>());
                    var retval = Libc.ioctl(fd, ioctl, new IntPtr(pinfo));

                    return(retval);
                }
            }
        }
Esempio n. 3
0
        private unsafe static void QueryCapabilities(LinuxJoystickDetails stick,
                                                     byte *axisbit, int axisbytes,
                                                     byte *keybit, int keybytes,
                                                     out int axes, out int buttons, out int hats)
        {
            // Note: since we are trying to be compatible with the SDL2 gamepad database,
            // we have to match SDL2 behavior bug-for-bug. This means:
            // HAT0-HAT3 are all reported as hats (even if the docs say that HAT1 and HAT2 can be analogue triggers)
            // DPAD buttons are reported as buttons, not as hats (unlike Windows and Mac OS X)

            axes = buttons = hats = 0;
            for (EvdevAxis axis = 0; axis < EvdevAxis.CNT && (int)axis < axisbytes * 8; axis++)
            {
                InputAbsInfo info;
                bool         is_valid = true;
                is_valid &= TestBit(axisbit, (int)axis);
                is_valid &= Evdev.GetAbs(stick.FileDescriptor, axis, out info) >= 0;
                if (is_valid)
                {
                    if (axis >= EvdevAxis.HAT0X && axis <= EvdevAxis.HAT3Y)
                    {
                        // Analogue hat
                        stick.AxisMap.Add(axis, new AxisInfo
                        {
                            Axis = (int)(JoystickHat)hats++,
                            Info = info
                        });
                    }
                    else
                    {
                        // Regular axis
                        stick.AxisMap.Add(axis, new AxisInfo
                        {
                            Axis = axes++,
                            Info = info
                        });
                    }
                }
            }

            for (EvdevButton button = 0; button < EvdevButton.Last && (int)button < keybytes * 8; button++)
            {
                if (TestBit(keybit, (int)button))
                {
                    stick.ButtonMap.Add(button, buttons++);
                }
            }
        }
Esempio n. 4
0
 // Get absolute value / limits
 public static int GetAbs(int fd, EvdevAxis axis, out InputAbsInfo info)
 {
     info = default(InputAbsInfo);
     unsafe
     {
         fixed (InputAbsInfo* pinfo = &info)
         {
             // EVIOCGABS(abs) = _IOR('E', 0x40 + (abs), struct input_absinfo)
             uint ioctl = IOCreate(DirectionFlags.Read, (int)axis + 0x40, BlittableValueType<InputAbsInfo>.Stride);
             int retval = Libc.ioctl(fd, ioctl, new IntPtr(pinfo));
             return retval;
         }
     }
 }