~xdavidwu/motion-control

e3036ba170e8a4ae82bc083352a65e8f555c6220 — xdavidwu 2 years ago afa0569
evdev: create some bindings for device modification
3 files changed, 58 insertions(+), 1 deletions(-)

A evdev/codes.ha
M evdev/libevdev.ha
M evdev/types.ha
A evdev/codes.ha => evdev/codes.ha +29 -0
@@ 0,0 1,29 @@
export def EV_SYN: u16	= 0x00;
export def EV_KEY: u16	= 0x01;
export def EV_REL: u16	= 0x02;
export def EV_ABS: u16	= 0x03;
export def EV_MSC: u16	= 0x04;
export def EV_SW: u16	= 0x05;
export def EV_LED: u16	= 0x11;
export def EV_SND: u16	= 0x12;
export def EV_REP: u16	= 0x14;
export def EV_FF: u16	= 0x15;
export def EV_PWR: u16	= 0x16;
export def EV_FF_STATUS: u16	= 0x17;
export def EV_MAX: u16	= 0x1f;
export def EV_CNT: u16	= EV_MAX + 1;

export def SYN_REPORT: u16	= 0;
export def SYN_CONFIG: u16	= 1;
export def SYN_MT_REPORT: u16	= 2;
export def SYN_DROPPED: u16	= 3;
export def SYN_MAX: u16	= 0xf;
export def SYN_CNT: u16	= SYN_MAX + 1;

export def BTN_LEFT: u16	= 0x110;
export def BTN_RIGHT: u16	= 0x111;
export def BTN_MIDDLE: u16	= 0x112;

export def REL_X: u16	= 0x00;
export def REL_Y: u16	= 0x01;
export def REL_Z: u16	= 0x02;

M evdev/libevdev.ha => evdev/libevdev.ha +27 -1
@@ 15,6 15,12 @@ export fn get_name(dev: libevdev) const str = {
	return strings::fromc(c_libevdev_get_name(dev));
};

export fn set_name(dev: libevdev, name: str) void = {
	const cstr = strings::to_c(name);
	defer free(cstr);
	c_libevdev_set_name(dev, cstr);
};

export fn next_event(dev: libevdev, flags: uint) (rt::errno | input_event) = {
	let ev = input_event { ... };
	const r = c_libevdev_next_event(dev, flags, &ev);


@@ 24,6 30,26 @@ export fn next_event(dev: libevdev, flags: uint) (rt::errno | input_event) = {
	return ev;
};

export fn enable_event_type(dev: libevdev, event_type: uint) (void | unknown_error) = {
	return if (c_libevdev_enable_event_type(dev, event_type) != 0) unknown_error else void;
};

export fn enable_event_code(dev: libevdev, event_type: uint, code: uint,
		data: nullable *void) (void | unknown_error) = {
	// TODO: wrap data with tagged union?
	return if (c_libevdev_enable_event_code(dev, event_type, code, data) != 0)
		unknown_error else void;
};

export @symbol("libevdev_new") fn new() libevdev;
export @symbol("libevdev_free") fn destroy(dev: libevdev) void;

@symbol("libevdev_new_from_fd") fn c_libevdev_new_from_fd(fd: int, dev: *libevdev) int;
@symbol("libevdev_get_name") fn c_libevdev_get_name(dev: libevdev) *const char;
@symbol("libevdev_next_event") fn c_libevdev_next_event(dev: libevdev, flags: uint, ev: *input_event) int;
@symbol("libevdev_set_name") fn c_libevdev_set_name(dev: libevdev, name: *const char) void;
@symbol("libevdev_next_event") fn c_libevdev_next_event(dev: libevdev,
	flags: uint, ev: *input_event) int;
@symbol("libevdev_enable_event_type") fn c_libevdev_enable_event_type(
	dev: libevdev, etype: uint) int;
@symbol("libevdev_enable_event_code") fn c_libevdev_enable_event_code(
	dev: libevdev, etype: uint, code: uint, data: nullable *void) int;

M evdev/types.ha => evdev/types.ha +2 -0
@@ 9,4 9,6 @@ export type input_event = struct {
	value:	i32,
};

export type unknown_error = !void;

export def READ_FLAG_NORMAL: uint	= 2;