From 332b10f47dba755a91d9b7a8f1f30d0ffa1a14b4 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 15 Aug 2022 09:44:37 +0100 Subject: [PATCH] initial working version --- Makefile | 7 +++++ adb-forward-touch.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ build.nix | 1 + default.nix | 6 ++++ 4 files changed, 86 insertions(+) create mode 100644 Makefile create mode 100644 adb-forward-touch.c create mode 100644 build.nix create mode 100644 default.nix diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9154687 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +PROGRAM=adb-forward-touch +default: $(PROGRAM) +PREFIX ?= /usr/local + +install: + mkdir -p $(PREFIX)/bin + cp $(PROGRAM) $(PREFIX)/bin diff --git a/adb-forward-touch.c b/adb-forward-touch.c new file mode 100644 index 0000000..5273f16 --- /dev/null +++ b/adb-forward-touch.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include + + + + +void set_axis(int fd, unsigned short code, int max) +{ + struct uinput_abs_setup abs_setup; + memset(&abs_setup, 0, sizeof abs_setup); + abs_setup.code = code; + abs_setup.absinfo.maximum = max; + ioctl(fd, UI_SET_ABSBIT, code); + ioctl(fd, UI_ABS_SETUP, &abs_setup); +} + +int main(void) +{ + struct uinput_setup usetup; + int i = 50; + + FILE *from_android = popen("adb exec-out getevent /dev/input/event2", "r"); + + int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); + + ioctl(fd, UI_SET_EVBIT, EV_KEY); + ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH); + + ioctl(fd, UI_SET_EVBIT, EV_ABS); + + set_axis(fd, ABS_X, 1079); + set_axis(fd, ABS_Y, 1919); + set_axis(fd, ABS_PRESSURE, 255); + set_axis(fd, ABS_MT_SLOT, 9); + set_axis(fd, ABS_MT_TOUCH_MAJOR, 15); + set_axis(fd, ABS_MT_TOUCH_MINOR, 15); + set_axis(fd, ABS_MT_ORIENTATION, 1); + set_axis(fd, ABS_MT_POSITION_X, 1079); + set_axis(fd, ABS_MT_POSITION_Y, 1919); + set_axis(fd, ABS_MT_TRACKING_ID, 65535); + set_axis(fd, ABS_MT_TOOL_TYPE, 15); + set_axis(fd, ABS_MT_PRESSURE, 255); + + ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT); + + memset(&usetup, 0, sizeof(usetup)); + usetup.id.bustype = BUS_USB; + usetup.id.vendor = 0x06cb; + usetup.id.product = 0x0af9; + strcpy(usetup.name, "Synaptics s3203b"); + ioctl(fd, UI_DEV_SETUP, &usetup); + + ioctl(fd, UI_DEV_CREATE); + + while (true) { + struct input_event ie; + if(fscanf(from_android, "%hx %hx %x", + &ie.type, &ie.code, &ie.value) == EOF) + break; + if(write(fd, &ie, sizeof(ie)) < 0) + break; + } + + ioctl(fd, UI_DEV_DESTROY); + close(fd); + + return 0; +} diff --git a/build.nix b/build.nix new file mode 100644 index 0000000..a760f25 --- /dev/null +++ b/build.nix @@ -0,0 +1 @@ +with import {} ; callPackage ./. {} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..81be89a --- /dev/null +++ b/default.nix @@ -0,0 +1,6 @@ +{ stdenv }: stdenv.mkDerivation { + name = "adb-forward-touch"; + version = "0.5"; + src = ./.; + makeFlags = [ "PREFIX=$$out" ]; +}