From ff3476b277f9765bd4fab9d396498b6770a7f436 Mon Sep 17 00:00:00 2001 From: bruceperens Date: Fri, 18 Apr 2014 00:57:39 +0000 Subject: [PATCH] Add first test program for Linux event interface. This is not yet a full driver, it's just pieces we would need for a driver. git-svn-id: https://svn.code.sf.net/p/freetel/code@1498 01035d8c-6547-0410-b346-abe4f91aad63 --- .../source/platform/linux/test_evdev.c | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 freedv-server/source/platform/linux/test_evdev.c diff --git a/freedv-server/source/platform/linux/test_evdev.c b/freedv-server/source/platform/linux/test_evdev.c new file mode 100644 index 00000000..1409ae25 --- /dev/null +++ b/freedv-server/source/platform/linux/test_evdev.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BITS_PER_LONG (sizeof(long) * 8) +#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) +#define OFF(x) ((x)%BITS_PER_LONG) +#define BIT(x) (1UL<> OFF(bit)) & 1) + +process_device(const char * device_name, int fd) +{ + char name[256]; + char address[256]; + uint8_t event_bits[(EV_MAX + 7) / 8]; + int length; + + if ( ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0 + || ioctl(fd, EVIOCGPHYS(sizeof(address)), address) < 0 + || ioctl(fd, EVIOCGBIT(0, sizeof(event_bits)), event_bits) < 0 ) { + perror(device_name); + } + else { + char unique[256]; + int got_unique = ioctl(fd, EVIOCGUNIQ(sizeof(unique)), unique) >= 0; + + char * s = name; + while ( *s != 0 ) { + if ( *s == ' ' && s[1] == ' ' ) { + s++; + char * end = s; + while ( *end == ' ' ) + end++; + memmove(s, end, strlen(end) + 1); + } + s++; + } + length = strlen(name); + + if ( length > 1 && name[length - 1] == ' ' ) + name[length - 1] = '\0'; + + if ( test_bit(EV_KEY, event_bits) ) { + printf("\"evdev:%s", name); + if ( got_unique && unique[0] != '\0' && unique[0] != ' ' ) + printf(" %s", unique); + printf(" at %s\"\n", address); + } + } +} + +int +main(int argc, char * * argv) +{ + int i; + for ( i = 0; i < 1024; i++ ) { + char name[100]; + + sprintf(name, "/dev/input/event%d", i); + + int fd = open(name, O_RDONLY); + if ( fd >= 0 ) { + process_device(name, fd); + close(fd); + } + } + return 0; +} -- 2.25.1