~xdavidwu/motion-control

a1994fca99cfaf8da51a11951dd4f20ffbd3692c — xdavidwu 2 years ago f28dcab
evdev::next_event: return status
3 files changed, 23 insertions(+), 8 deletions(-)

M evdev/libevdev.ha
M evdev/types.ha
M tools/evdev-dump-events/main.ha
M evdev/libevdev.ha => evdev/libevdev.ha +3 -4
@@ 22,13 22,12 @@ export fn set_name(dev: libevdev, name: str) void = {
	c_libevdev_set_name(dev, cstr);
};

export fn next_event(dev: libevdev, flags: uint) (errors::error | input_event) = {
	let ev = input_event { ... };
	const r = c_libevdev_next_event(dev, flags, &ev);
export fn next_event(dev: libevdev, flags: uint, ev: *input_event) (errors::error | read_status) = {
	const r = c_libevdev_next_event(dev, flags, ev);
	if (r < 0) {
		return errors::errno(-r);
	};
	return ev;
	return r: read_status;
};

export fn enable_event_type(dev: libevdev, event_type: uint) (void | unknown_error) = {

M evdev/types.ha => evdev/types.ha +11 -1
@@ 11,4 11,14 @@ export type input_event = struct {

export type unknown_error = !void;

export def READ_FLAG_NORMAL: uint	= 2;
export type read_status = enum int {
	SUCCESS	= 0,
	SYNC	= 1,
};

export type read_flag = enum uint {
	SYNC	= 1,
	NORMAL	= 2,
	FORCE_SYNC	= 4,
	BLOCKING	= 8,
};

M tools/evdev-dump-events/main.ha => tools/evdev-dump-events/main.ha +9 -3
@@ 27,9 27,15 @@ export fn main() void = {
	fmt::printfln("Input device name: {}", evdev::get_name(evdev))!;

	for (true) {
		let ev = match (evdev::next_event(evdev, evdev::READ_FLAG_NORMAL)) {
		case let ev: evdev::input_event =>
			yield ev;
		let ev = evdev::input_event {...};
		match (evdev::next_event(evdev, evdev::read_flag::NORMAL, &ev)) {
		case let r: evdev::read_status =>
			switch (r) {
			case evdev::read_status::SUCCESS =>
				yield;
			case evdev::read_status::SYNC =>
				continue;
			};
		case let err: errors::error =>
			match (err) {
			case errors::again =>