~xdavidwu/motion-control

83376f702e65146868ae4e551e324cabd5155fb6 — xdavidwu 2 years ago 85523de
tools: add uinput-pointer
3 files changed, 35 insertions(+), 2 deletions(-)

M .gitignore
M Makefile
A tools/uinput-pointer/main.ha
M .gitignore => .gitignore +1 -0
@@ 1,1 1,2 @@
/evdev-dump-events
/uinput-pointer

M Makefile => Makefile +2 -2
@@ 1,3 1,3 @@
evdev-dump-events:
evdev-dump-events uinput-pointer:
	hare build -levdev -o $@ tools/$@/
.PHONY: evdev-dump-events
.PHONY: evdev-dump-events uinput-pointer

A tools/uinput-pointer/main.ha => tools/uinput-pointer/main.ha +32 -0
@@ 0,0 1,32 @@
use evdev;
use evdev::uinput;
use fmt;
use rt;
use time;

export fn main() void = {
	const evdev = evdev::new();
	defer evdev::destroy(evdev);
	evdev::set_name(evdev, "uinput pointer");
	evdev::enable_event_type(evdev, evdev::EV_REL)!;
	evdev::enable_event_code(evdev, evdev::EV_REL, evdev::REL_X, null)!;
	evdev::enable_event_code(evdev, evdev::EV_REL, evdev::REL_Y, null)!;
	evdev::enable_event_type(evdev, evdev::EV_KEY)!;
	evdev::enable_event_code(evdev, evdev::EV_KEY, evdev::BTN_LEFT, null)!;
	evdev::enable_event_code(evdev, evdev::EV_KEY, evdev::BTN_MIDDLE, null)!;
	evdev::enable_event_code(evdev, evdev::EV_KEY, evdev::BTN_RIGHT, null)!;

	const uinput = match (evdev::uinput::create_from_device(evdev, evdev::uinput::OPEN_MANAGED)) {
	case let uinput: evdev::uinput::uinput =>
		yield uinput;
	case let err: rt::errno =>
		fmt::fatalf("Failed to create uinput dev: {}", rt::strerror(err));
	};
	defer evdev::uinput::destroy(uinput);

	for (let i = 0; i < 100; i += 1) {
		evdev::uinput::write_event(uinput, evdev::EV_REL, evdev::REL_X, 1)!;
		evdev::uinput::write_event(uinput, evdev::EV_SYN, evdev::SYN_REPORT, 0)!;
		time::sleep(10 * time::MILLISECOND);
	};
};