// Get supported event bits public static int GetBit(int fd, EvdevType ev, int length, IntPtr data) { // EVIOCGBIT = _IOC(_IOC_READ, 'E', 0x20 + (ev), len) uint ioctl = IOCreate(DirectionFlags.Read, (int)ev + 0x20, length); int retval = Libc.ioctl(fd, ioctl, data); return(retval); }
bool SetupTTY(int stdin) { // Ensure that we are using a real terminal, // rather than some short of file redirection.thing. if (!Terminal.IsTerminal(stdin)) { Debug.Print("[Linux] Terminal.IsTerminal({0}) returned false.", stdin); return(false); } //original_stdin = Libc.dup(stdin); int ret = Terminal.GetAttributes(stdin, out original_state); if (ret < 0) { Debug.Print("[Linux] Terminal.GetAttributes({0}) failed. Error: {1}", stdin, ret); return(false); } // Retrieve current keyboard mode ret = Libc.ioctl(stdin, KeyboardIoctlCode.GetMode, ref original_mode); if (ret != 0) { Debug.Print("[Linux] Libc.ioctl({0}, KeyboardIoctlCode.GetMode) failed. Error: {1}", stdin, ret); return(false); } // Update terminal state current_state = original_state; current_state.LocalMode &= ~(/*LocalFlags.ECHO |*/ LocalFlags.ICANON | LocalFlags.ISIG); current_state.InputMode &= ~( InputFlags.ISTRIP | InputFlags.IGNCR | InputFlags.ICRNL | InputFlags.INLCR | InputFlags.IXOFF | InputFlags.IXON); current_state.ControlCharacters.VMIN = 0; current_state.ControlCharacters.VTIME = 0; Terminal.SetAttributes(stdin, OptionalActions.FLUSH, ref current_state); // Request keycodes int mode = 0x02; // K_MEDIUMRAW ret = Libc.ioctl(stdin, KeyboardIoctlCode.SetMode, mode); if (ret != 0) { Debug.Print("[Linux] Libc.ioctl({0}, KeyboardIoctlCode.SetMode, {1}) failed. Error: {2}", stdin, mode, ret); ExitTTY(this, EventArgs.Empty); return(false); } // Ensure we reset the original keyboard/terminal state on exit, // even if we crash. HookEvents(); return(true); }
public static int GetName(int fd, out string name) { unsafe { sbyte *pname = stackalloc sbyte[129]; int ret = Libc.ioctl(fd, EvdevIoctl.Name128, new IntPtr(pname)); name = new string(pname); return(ret); } }
public static int GetId(int fd, out EvdevInputId id) { id = default(EvdevInputId); unsafe { fixed(EvdevInputId *pid = &id) { return(Libc.ioctl(fd, EvdevIoctl.Id, new IntPtr(pid))); } } }
void ExitTTY(object sender, EventArgs e) { if (original_mode != new IntPtr(-1)) { Debug.Print("[Linux] Exiting TTY keyboard input."); Libc.ioctl(stdin, KeyboardIoctlCode.SetMode, ref original_mode); Terminal.SetAttributes(stdin, OptionalActions.FLUSH, ref original_state); original_mode = new IntPtr(-1); UnhookEvents(); } }
// 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); } } }
JoystickDevice <LinuxJoyDetails> OpenJoystick(string path) { JoystickDevice <LinuxJoyDetails> stick = null; int number = GetJoystickNumber(Path.GetFileName(path)); if (number >= 0) { int fd = -1; try { fd = Libc.open(path, OpenFlags.NonBlock); if (fd == -1) { return(null); } // Check joystick driver version (must be 1.0+) int driver_version = 0x00000800; Libc.ioctl(fd, JoystickIoctlCode.Version, ref driver_version); if (driver_version < 0x00010000) { return(null); } // Get number of joystick axes int axes = 0; Libc.ioctl(fd, JoystickIoctlCode.Axes, ref axes); // Get number of joystick buttons int buttons = 0; Libc.ioctl(fd, JoystickIoctlCode.Buttons, ref buttons); stick = new JoystickDevice <LinuxJoyDetails>(number, axes, buttons); StringBuilder sb = new StringBuilder(128); Libc.ioctl(fd, JoystickIoctlCode.Name128, sb); stick.Description = sb.ToString(); stick.Details.FileDescriptor = fd; stick.Details.State.SetIsConnected(true); stick.Details.Guid = CreateGuid(stick, path, number); // Find the first disconnected joystick (if any) int i; for (i = 0; i < sticks.Count; i++) { if (!sticks[i].Details.State.IsConnected) { break; } } // If no disconnected joystick exists, append a new slot if (i == sticks.Count) { sticks.Add(stick); } else { sticks[i] = stick; } // Map player index to joystick index_to_stick.Add(index_to_stick.Count, i); Debug.Print("Found joystick on path {0}", path); } finally { if (stick == null && fd != -1) { Libc.close(fd); } } } return(stick); }