~xdavidwu/motion-control

56cfac068f9576789f2c48f2edc93e25878efcb4 — xdavidwu 2 years ago 4c9628d
pointerd: support button events
2 files changed, 27 insertions(+), 0 deletions(-)

M cmd/pointerd/main.ha
M proto/control/types.ha
M cmd/pointerd/main.ha => cmd/pointerd/main.ha +19 -0
@@ 17,6 17,17 @@ fn sigint(sig: int, info: *signal::siginfo, ucontext: *void) void = {
	exit = true;
};

fn protocol_key_to_event_code(key: u8) u16 = {
	switch (key) {
	case control::key::BTN_LEFT =>
		return evdev::BTN_LEFT;
	case control::key::BTN_RIGHT =>
		return evdev::BTN_RIGHT;
	case =>
		fmt::fatalf("Invalid key code {}", key);
	};
};

export fn main() void = {
	const evdev = evdev::new();
	defer evdev::destroy(evdev);


@@ 67,6 78,14 @@ export fn main() void = {
			uinput::write_event(uinput, evdev::EV_REL, evdev::REL_X, buf.x)!;
			uinput::write_event(uinput, evdev::EV_REL, evdev::REL_Y, buf.y)!;
			uinput::write_event(uinput, evdev::EV_SYN, evdev::SYN_REPORT, 0)!;
		case control::code::KEY_PRESSED =>
			const code = protocol_key_to_event_code(buf.key);
			uinput::write_event(uinput, evdev::EV_KEY, code, 1)!;
			uinput::write_event(uinput, evdev::EV_SYN, evdev::SYN_REPORT, 0)!;
		case control::code::KEY_RELEASED =>
			const code = protocol_key_to_event_code(buf.key);
			uinput::write_event(uinput, evdev::EV_KEY, code, 0)!;
			uinput::write_event(uinput, evdev::EV_SYN, evdev::SYN_REPORT, 0)!;
		case =>
			fmt::errorfln("Unrecognized control code: {}", buf.code)!;
		};

M proto/control/types.ha => proto/control/types.ha +8 -0
@@ 2,6 2,13 @@ export def DEFAULT_PORT: u16	= 0x519;

export type code = enum u8 {
	RELATIVE_MOVEMENT	= 0,
	KEY_PRESSED	= 1,
	KEY_RELEASED	= 2,
};

export type key = enum u8 {
	BTN_LEFT	= 0,
	BTN_RIGHT	= 1,
};

export type request = union {


@@ 12,6 19,7 @@ export type request = union {
				x: i8,
				y: i8,
			},
			key: u8,
		},
	},
	bytes: [3]u8,