diff --git a/capture.c b/capture.c new file mode 100644 index 0000000..f41f5d7 --- /dev/null +++ b/capture.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include + +void dump_event(struct timespec* start, struct input_event* event); +int stream_events(char* device_path); + +static inline void timespec_diff(struct timespec* a, struct timespec* b, struct timespec* result) { + result->tv_sec = a->tv_sec - b->tv_sec; + result->tv_nsec = a->tv_nsec - b->tv_nsec; + if (result->tv_nsec < 0) { + --result->tv_sec; + result->tv_nsec += 1000000000L; + } +} + +void dump_event(struct timespec* start, struct input_event* event) { + unsigned char button, bLeft, bMiddle, bRight; + unsigned char *ptr = (unsigned char*)event; + int i; + char x, y; + struct timespec now; + struct timespec diff; + + clock_gettime(CLOCK_MONOTONIC, &now); + timespec_diff(&now, start, &diff); + + button = ptr[0]; + bLeft = button & 0x1; + bMiddle = ( button & 0x4 ) > 0; + bRight = ( button & 0x2 ) > 0; + x=(char) ptr[1];y=(char) ptr[2]; + printf("%ld.%ld,m,l%d,m%d,r%d,x%d,y%d\n", + diff.tv_sec, + diff.tv_nsec, + bLeft, bMiddle, bRight, x, y); + + // + // comment to disable the display of raw event structure datas + // + // for(i=0; i