当前位置: 首页>>代码示例>>C++>>正文


C++ EVIOCGNAME函数代码示例

本文整理汇总了C++中EVIOCGNAME函数的典型用法代码示例。如果您正苦于以下问题:C++ EVIOCGNAME函数的具体用法?C++ EVIOCGNAME怎么用?C++ EVIOCGNAME使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了EVIOCGNAME函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char *argv[])
{
  struct input_event ev[64];
  int fd, rd, value, size = sizeof (struct input_event);
  char name[256] = "Unknown";
  const char *device = NULL;
	if(daemon(0,0)){
		printf("Could not start as daemon\n");
		return -1;
	}

    device = "/dev/naga_keyboard";

  //Open Device
  if ((fd = open (device, O_RDONLY)) == -1){
    printf ("%s is not a vaild device.\n", device);
	return -1;
	}
  //Print Device Name
  ioctl (fd, EVIOCGNAME (sizeof (name)), name);
  printf ("Reading From : %s (%s)\n", device, name);
	init();
  while (1){
      if ((rd = read (fd, ev, size * 64)) < size)
          perror_exit ("read()");      

      value = ev[0].value;

      if (value != ' ' && ev[1].value == 1 && ev[1].type == 1){ // Only read the key press event
	   printf ("Code[%d]\n", (ev[1].code));
	   docode(ev[1].code);
      }
  }

  return 0;
}
开发者ID:pzl,项目名称:Razer-Naga-HotKey,代码行数:36,代码来源:nagad.cpp

示例2: main

int main()
{
	int  mouseFD = -1;
        int i;
        char deviceName[64];
        char fullPath[128];
        fprintf(stderr, "Try to find the device ( %s ).\n", TOUCH_PANEL_DEVICE_NAME);
        for(i=0; i<10; i++) {
                memset(deviceName, 0, 64);
                memset(fullPath, 0, 128);
                sprintf(fullPath,"/dev/input/event%d",i);
                mouseFD = open(fullPath,O_RDONLY | O_NDELAY);
                if(mouseFD==-1) continue;
                if(ioctl(mouseFD, EVIOCGNAME(64), deviceName) < 0) {
                        close(mouseFD);
                        continue;
                }
                // Get the device name, matching...
                fprintf(stderr,"Current device -> %s, name -> %s, Result -> ", fullPath, deviceName);
                if(strcasestr(deviceName, TOUCH_PANEL_DEVICE_NAME)) {
                        fprintf(stderr,"Have found touch panal device %s\n",fullPath);
			close(mouseFD);
                        goto findok;
                }
                else {
                        fprintf(stderr,"no touch panel device found!\n");
                        close(mouseFD);
                }
        }
	goto  notfind;
findok:
	printf("%s", fullPath);	
	exit(0);	
notfind:
	exit(1);
}
开发者ID:jamesyan84,项目名称:zbase,代码行数:36,代码来源:zdetecttp.c

示例3: is_gpio_keys

static int
is_gpio_keys(char *path)
{
	char buf[256];
	int fd;
	int ret;

	fd = open(path, O_RDONLY);
	if (fd < 0){
		perror("open");
		return FALSE;
	}

	ret = ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
	close(fd);
	if (ret < 0)
		return FALSE;

	ret = strcmp(buf, sw[sw_index].driver);
	if (ret !=  0)
		return FALSE;

	return TRUE;
}
开发者ID:miettal,项目名称:armadillo420_standard,代码行数:24,代码来源:main.c

示例4: identify

/* another option to this mess (as the hashing thing doesn't seem to work out
 * is to move identification/etc. to another level and just let whatever device
 * node generator is active populate with coherent names. and use a hash of that
 * name as the ID */
static bool identify(int fd, const char* path,
	char* label, size_t label_sz, unsigned short* dnum)
{
	if (-1 == ioctl(fd, EVIOCGNAME(label_sz), label)){
		debug_print("input/identify: bad EVIOCGNAME, setting unknown\n");
		snprintf(label, label_sz, "unknown");
	}
	else
		verbose_print(
			"input/identify(%d): %s name resolved to %s", fd, path, label);

	struct input_id nodeid;
	if (-1 == ioctl(fd, EVIOCGID, &nodeid)){
		debug_print(
			"input/identify(%d): no EVIOCGID, reason:%s", fd, strerror(errno));
		return false;
	}

/*
 * first, check if any other subsystem knows about this one and ignore if so
 */
	if (arcan_led_known(nodeid.vendor, nodeid.product)){
		debug_print(
			"led subsys know %d, %d\n", (int)nodeid.vendor, (int)nodeid.product);
		arcan_led_init();
		return false;
	}

/* didn't find much on how unique eviocguniq actually was, nor common lengths
 * or what not so just mix them in a buffer, hash and let unsigned overflow
 * modulo take us down to 16bit */
	size_t bpl = sizeof(long) * 8;
	size_t nbits = ((EV_MAX)-1) / bpl + 1;

	char buf[12 + nbits * sizeof(long)];
	char bbuf[sizeof(buf)];
	memset(buf, '\0', sizeof(buf));
	memset(bbuf, '\0', sizeof(bbuf));

/* some test devices here answered to the ioctl and returned full empty UNIQs,
 * do something to lower the likelihood of collisions */
	unsigned long hash = 5381;

	if (-1 == ioctl(fd, EVIOCGUNIQ(sizeof(buf)), buf) ||
		memcmp(buf, bbuf, sizeof(buf)) == 0){

		size_t llen = strlen(label);
		for (size_t i = 0; i < llen; i++)
			hash = ((hash << 5) + hash) + label[i];

		llen = strlen(path);
		for (size_t i = 0; i < llen; i++)
			hash  = ((hash << 5) + hash) + path[i];

		buf[11] ^= nodeid.vendor >> 8;
		buf[10] ^= nodeid.vendor;
		buf[9] ^= nodeid.product >> 8;
		buf[8] ^= nodeid.product;
		buf[7] ^= nodeid.version >> 8;
		buf[6] ^= nodeid.version;

/* even this point has a few collisions, particularly some keyboards and mice
 * that don't respond to CGUNIQ and expose multiple- subdevices but with
 * different button/axis count */
		ioctl(fd, EVIOCGBIT(0, EV_MAX), &buf);
	}
开发者ID:letoram,项目名称:arcan,代码行数:70,代码来源:event.c

示例5: ecore_fb_input_device_open

/*
 * Opens an input device
 */
EAPI Ecore_Fb_Input_Device *
ecore_fb_input_device_open(const char *dev)
{
	Ecore_Fb_Input_Device *device;
	unsigned long event_type_bitmask[EV_CNT / 32 + 1];
	int event_type;
	int fd;

	if(!dev) return NULL;
	device = calloc(1, sizeof(Ecore_Fb_Input_Device));
	if(!device) return NULL;

	if((fd = open(dev, O_RDONLY, O_NONBLOCK)) < 0)
	{
		fprintf(stderr, "[ecore_fb_li:device_open] %s %s", dev, strerror(errno));
		goto error_open;
	}
	/* query capabilities */
	if(ioctl(fd, EVIOCGBIT(0, EV_MAX), event_type_bitmask) < 0)
	{
		fprintf(stderr,"[ecore_fb_li:device_open] query capabilities %s %s", dev, strerror(errno));
		goto error_caps;
	}
	/* query name */
	device->info.name = calloc(256, sizeof(char));
	if(ioctl(fd, EVIOCGNAME(sizeof(char) * 256), device->info.name) < 0)
	{
		fprintf(stderr, "[ecore_fb_li:device_open] get name %s %s", dev, strerror(errno));
		strcpy(device->info.name, "Unknown");
	}
	device->fd = fd;
	device->info.dev = strdup(dev);
	/* common */
	device->mouse.threshold = CLICK_THRESHOLD_DEFAULT;

	/* set info */
	for(event_type = 0; event_type < EV_MAX; event_type++)
	{
		if(!test_bit(event_type, event_type_bitmask))
			continue;
		switch(event_type)
		{
			case EV_SYN :
			break;

			case EV_KEY:
			device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_KEYS_OR_BUTTONS;
			break;

			case EV_REL:
			device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_RELATIVE;
			break;

			case EV_ABS:
			device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_ABSOLUTE;
			break;

			case EV_MSC:
			case EV_LED:
			case EV_SND:
			case EV_REP:
			case EV_FF :
			case EV_FF_STATUS:
			case EV_PWR:
			default:
			break;
		}
	}
	_ecore_fb_li_devices = eina_list_append(_ecore_fb_li_devices, device);
	return device;

	error_caps:
	close(fd);
	error_open:
	free(device);
	return NULL;

}
开发者ID:OpenInkpot-archive,项目名称:ecore,代码行数:81,代码来源:ecore_fb_li.c

示例6: main

/* Main function, contains kernel driver event loop */
int main(int argc, char **argv) {

	char* devname = 0;
	int doDaemonize = 1;
	int doWait = 0;
	int clickMode = 2;

	int i;
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--debug") == 0) {
			doDaemonize = 0;
			debugMode = 1;
		} else if (strcmp(argv[i], "--wait") == 0) {
			doWait = 1;
		} else if (strcmp(argv[i], "--click=first") == 0) {
			clickMode = 0;
		} else if (strcmp(argv[i], "--click=second") == 0) {
			clickMode = 1;
		} else if (strcmp(argv[i], "--click=center") == 0) {
			clickMode = 2;
		} else {
			devname = argv[i];
		}

	}

	initGestures(clickMode);



	if (doDaemonize) {
		daemonize();
	}

	if (doWait) {
		/* Wait until all necessary things are loaded */
		sleep(10);
	}


	/* Connect to X server */
	if ((display = XOpenDisplay(NULL)) == NULL) {
		fprintf(stderr, "Couldn't connect to X server\n");
		exit(1);
	}

	/* Read X data */
	screenNum = DefaultScreen(display);

	root = RootWindow(display, screenNum);

//	realDisplayWidth = DisplayWidth(display, screenNum);
//	realDisplayHeight = DisplayHeight(display, screenNum);

	WM_CLASS = XInternAtom(display, "WM_CLASS", 0);

	/* Get notified about new windows */
	XSelectInput(display, root, StructureNotifyMask | SubstructureNotifyMask);

	//TODO load blacklist and profiles from file(s)

	/* Device file name */
	if (devname == 0) {
		devname = "/dev/twofingtouch";
	}

	/* Try to read from device file */
	int fileDesc;
	if ((fileDesc = open(devname, O_RDONLY)) < 0) {
		perror("twofing");
		return 1;
	}

	fd_set fileDescSet;
	FD_ZERO(&fileDescSet);

	int eventQueueDesc = XConnectionNumber(display);	

	while (1) {
		/* Perform initialization at beginning and after module has been re-loaded */
		int rd, i;
		struct input_event ev[64];

		char name[256] = "Unknown";

		/* Read device name */
		ioctl(fileDesc, EVIOCGNAME(sizeof(name)), name);
		printf("Input device name: \"%s\"\n", name);

		//TODO activate again?
		//XSetErrorHandler(invalidWindowHandler);


		int opcode, event, error;
		if (!XQueryExtension(display, "RANDR", &opcode, &event,
				&error)) {
			printf("X RANDR extension not available.\n");
			XCloseDisplay(display);
			exit(1);
//.........这里部分代码省略.........
开发者ID:sanyaade-embedded-systems,项目名称:twofing,代码行数:101,代码来源:twofingemu.c

示例7: vk_init

static int vk_init(struct ev *e)
{
    char vk_path[PATH_MAX] = "/sys/board_properties/virtualkeys.";
    char vks[2048], *ts = NULL;
    ssize_t len;
    int vk_fd;
    int i;

    e->vk_count = 0;

    len = strlen(vk_path);
    len = ioctl(e->fd->fd, EVIOCGNAME(sizeof(e->deviceName)), e->deviceName);
    if (len <= 0)
    {
        printf("Unable to query event object.\n");
        return -1;
    }
#ifdef _EVENT_LOGGING
    printf("Event object: %s\n", e->deviceName);
#endif

    // Blacklist these "input" devices
    if (strcmp(e->deviceName, "bma250") == 0 || strcmp(e->deviceName, "bma150") == 0 || strcmp(e->deviceName, "accelerometer") == 0)
    {
        e->ignored = 1;
    }

    strcat(vk_path, e->deviceName);

    // Some devices split the keys from the touchscreen
    e->vk_count = 0;
    vk_fd = open(vk_path, O_RDONLY);
    if (vk_fd >= 0)
    {
        len = read(vk_fd, vks, sizeof(vks)-1);
        close(vk_fd);
        if (len <= 0)
            return -1;

        vks[len] = '\0';

        /* Parse a line like:
            keytype:keycode:centerx:centery:width:height:keytype2:keycode2:centerx2:...
        */
        for (ts = vks, e->vk_count = 1; *ts; ++ts) {
            if (*ts == ':')
                ++e->vk_count;
        }

        if (e->vk_count % 6) {
            printf("minui: %s is %d %% 6\n", vk_path, e->vk_count % 6);
        }
        e->vk_count /= 6;
        if (e->vk_count <= 0)
            return -1;

        e->down = DOWN_NOT;
    }

    ioctl(e->fd->fd, EVIOCGABS(ABS_X), &e->p.xi);
    ioctl(e->fd->fd, EVIOCGABS(ABS_Y), &e->p.yi);
    e->p.synced = 0;
#ifdef _EVENT_LOGGING
    printf("EV: ST minX: %d  maxX: %d  minY: %d  maxY: %d\n", e->p.xi.minimum, e->p.xi.maximum, e->p.yi.minimum, e->p.yi.maximum);
#endif

    ioctl(e->fd->fd, EVIOCGABS(ABS_MT_POSITION_X), &e->mt_p.xi);
    ioctl(e->fd->fd, EVIOCGABS(ABS_MT_POSITION_Y), &e->mt_p.yi);
    e->mt_p.synced = 0;
#ifdef _EVENT_LOGGING
    printf("EV: MT minX: %d  maxX: %d  minY: %d  maxY: %d\n", e->mt_p.xi.minimum, e->mt_p.xi.maximum, e->mt_p.yi.minimum, e->mt_p.yi.maximum);
#endif

    e->vks = malloc(sizeof(*e->vks) * e->vk_count);

    for (i = 0; i < e->vk_count; ++i) {
        char *token[6];
        int j;

        for (j = 0; j < 6; ++j) {
            token[j] = vk_strtok_r((i||j)?NULL:vks, ":", &ts);
        }

        if (strcmp(token[0], "0x01") != 0) {
            /* Java does string compare, so we do too. */
            printf("minui: %s: ignoring unknown virtual key type %s\n", vk_path, token[0]);
            continue;
        }

        e->vks[i].scancode = strtol(token[1], NULL, 0);
        e->vks[i].centerx = strtol(token[2], NULL, 0);
        e->vks[i].centery = strtol(token[3], NULL, 0);
        e->vks[i].width = strtol(token[4], NULL, 0);
        e->vks[i].height = strtol(token[5], NULL, 0);
    }

    return 0;
}
开发者ID:Abhinav1997,项目名称:Team-Win-Recovery-Project,代码行数:98,代码来源:events.c

示例8: list_input_devices

/*
 *	list_input_devices - Show a human-readable list of all input devices
 *	the current user has permissions to read from.
 *	Add info wether this probably can be "muted" in X11 if requested
 */
int	list_input_devices ()
{
	int	i, fd;
	char	buf[sizeof(EVDEVNAME)+8];
	struct input_id device_info;
	char	namebuf[256];
	char	*xinlist;
	FILE	*pf;
	char	*p, *q;
	char	x11 = 0;
	if ( NULL == ( xinlist = malloc ( 4096 ) ) )
	{
		printf ( "Memory alloc error\n" );
		return	1;
	}
	bzero ( xinlist, 4096 );
	if ( NULL != ( pf = popen ("xinput --list --name-only", "r" ) ) )
	{
		if ( 1 > fread ( xinlist, 1, 4095, pf ) )
		{
			printf ( "\tx11-mutable information not available.\n" );
		}
		fclose ( pf );
	}
	printf ( "List of available input devices:\n");
	printf ( "num\tVendor/Product, Name, -x compatible (x/-)\n" );
	for ( i = 0; i < MAXEVDEVS; ++i )
	{
		sprintf ( buf, EVDEVNAME, i );
		fd = open ( buf, O_RDONLY );
		if ( fd < 0 )
		{
			if ( errno == ENOENT ) { i = MAXEVDEVS ; break; }
			if ( errno == EACCES )
			{
				printf ( "%2d:\t[permission denied]\n", i );
			}
			continue;
		}
		if ( ioctl ( fd, EVIOCGID, &device_info ) < 0 )
		{
			close(fd); continue;
		}
		if ( ioctl ( fd, EVIOCGNAME(sizeof(namebuf)-4), namebuf+2) < 0 )
		{
			close(fd); continue;
		}
		namebuf[sizeof(namebuf)-4] = 0;
		x11 = 0;
		p = xinlist;
		while ( ( p != NULL ) && ( *p != 0 ) )
		{
			if ( NULL == ( q = strchr ( p, 0x0a ) ) ) { break; }
			*q = 0;
			if ( strcmp ( p, namebuf + 2 ) == 0 ) { x11 = 1; }
			*q = 0x0a;
			while ( (*q > 0) && (*q <= 0x20 ) ) { ++q; }
			p = q;
		}
		printf("%2d\t[%04hx:%04hx.%04hx] '%s' (%s)", i,
			device_info.vendor, device_info.product,
			device_info.version, namebuf + 2, x11 ? "+" : "-");
		printf("\n");
		close ( fd );
	}
	free ( xinlist );
	return	0;
}
开发者ID:AlexandreTK,项目名称:hidclient,代码行数:73,代码来源:hidclient.c

示例9: initevents

/*
 * 	initevents () - opens all required event files
 * 	or only the ones specified by evdevmask, if evdevmask != 0
 *	try to disable in X11 if mutex11 is set to 1
 * 	returns number of successfully opened event file nodes, or <1 for error
 */
int	initevents ( unsigned int evdevmask, int mutex11 )
{
	int	i, j, k;
	char	buf[sizeof(EVDEVNAME)+8];
	char	*xinlist = NULL;
	FILE	*pf;
	char	*p, *q;
	if ( mutex11 )
	{
		if ( NULL == ( xinlist = malloc ( 4096 ) ) )
		{
			printf ( "Memory alloc error\n" );
			return 0;
		}
		bzero ( xinlist, 4096 );
		if ( NULL != ( pf = popen ("xinput --list --short", "r" ) ) )
		{
			if ( 1 > fread ( xinlist, 1, 3800, pf ) )
			{
				printf ( "\tx11-mutable information not available.\n" );
				free ( xinlist );
				xinlist = NULL;
			}
		}
		fclose ( pf );
	}
	for ( i = 0; i < MAXEVDEVS; ++i )
	{
		eventdevs[i] = -1;
		x11handles[i] = -1;
	}
	for ( i = j = 0; j < MAXEVDEVS; ++j )
	{
		if ( ( evdevmask != 0 ) && ( ( evdevmask & ( 1 << j ) ) == 0 ) ) { continue; }
		sprintf ( buf, EVDEVNAME, j );
		eventdevs[i] = open ( buf, O_RDONLY );
		if ( 0 <= eventdevs[i] )
		{
			fprintf ( stdout, "Opened %s as event device [counter %d]\n", buf, i );
			if ( ( mutex11 > 0 ) && ( xinlist != NULL ) )
			{
				k = -1;
				xinlist[3801] = 0;
				if ( ioctl(eventdevs[i], EVIOCGNAME(256),xinlist+3801) >= 0 )
				{
					p = xinlist;
					xinlist[4056] = 0;
					if ( strlen(xinlist+3801) < 4 ) // min lenght for name
						p = xinlist + 4056;
					while ( (*p != 0) &&
						( NULL != ( p = strstr ( p, xinlist+3801 ) ) ) )
					{
						q = p + strlen(xinlist+3801);
						while ( *q == ' ' ) ++q;
						if ( strncmp ( q, "\tid=", 4 ) == 0 )
						{
							k = atoi ( q + 4 );
							p = xinlist + 4056;
						} else {
							p = q;
						}
					}
				}
				if ( k >= 0 ) {
					sprintf ( xinlist+3801, "xinput set-int-prop %d \"Device "\
						"Enabled\" 8 0", k );
					if ( system ( xinlist + 3801 ) )
					{
						fprintf ( stderr, "Failed to x11-mute.\n" );
					}
					x11handles[i] = k;
				}
			}
			++i;
		}
	}
	if ( xinlist != NULL ) { free ( xinlist ); }
	return	i;
}
开发者ID:AlexandreTK,项目名称:hidclient,代码行数:85,代码来源:hidclient.c

示例10: close

void CRCInput::open()
{
	close();

	fd_tdt_rc_event_driver = -1;

	for (int i = 0; i < NUMBER_OF_EVENT_DEVICES; i++)
	{
		if ((fd_rc[i] = ::open(RC_EVENT_DEVICE[i], O_RDONLY)) == -1)
			perror(RC_EVENT_DEVICE[i]);
		else
		{
			char name[80];
			ioctl(fd_rc[i], EVIOCGNAME(sizeof(name)), name);
			if(!strcmp("TDT RC event driver", name))
				fd_tdt_rc_event_driver = fd_rc[i];
			fcntl(fd_rc[i], F_SETFL, O_NONBLOCK);
		}
	}
	if (fd_tdt_rc_event_driver < 0)
		fd_tdt_rc_event_driver = fd_rc[0];

	//+++++++++++++++++++++++++++++++++++++++
#ifdef KEYBOARD_INSTEAD_OF_REMOTE_CONTROL
	fd_keyb = STDIN_FILENO;
	fd_tdt_rc_event_driver = STDIN_FILENO;
#else
	fd_keyb = 0;
#endif /* KEYBOARD_INSTEAD_OF_REMOTE_CONTROL */
	/*
	   ::open("/dev/dbox/rc0", O_RDONLY);
	   if (fd_keyb<0)
	   {
	   perror("/dev/stdin");
	   exit(-1);
	   }
	   */
#ifdef KEYBOARD_INSTEAD_OF_REMOTE_CONTROL
	::fcntl(fd_keyb, F_SETFL, O_NONBLOCK);

	struct termio new_termio;

	::ioctl(STDIN_FILENO, TCGETA, &orig_termio);

	saved_orig_termio      = true;

	new_termio             = orig_termio;
	new_termio.c_lflag    &= ~ICANON;
	//	new_termio.c_lflag    &= ~(ICANON|ECHO);
	new_termio.c_cc[VMIN ] = 1;
	new_termio.c_cc[VTIME] = 0;

	::ioctl(STDIN_FILENO, TCSETA, &new_termio);

#else
	//fcntl(fd_keyb, F_SETFL, O_NONBLOCK );

	//+++++++++++++++++++++++++++++++++++++++
#endif /* KEYBOARD_INSTEAD_OF_REMOTE_CONTROL */

	open_click();
	calculateMaxFd();
}
开发者ID:FFTEAM,项目名称:evolux-spark-sh4,代码行数:63,代码来源:rcinput.cpp

示例11: print_info

void print_info(int fd)
{
    char buf[100];
    int version;
    struct input_id id;
    char evtype[(EV_MAX+7)/8];
    int i;
    
    if(ioctl(fd, EVIOCGNAME(100), buf) == -1)
    {
        if(errno == ENOTTY) // sim
            return;
        perror("Failed to get device name");
    }
    else
        printf("Device: %s\n", buf);
    if(ioctl(fd, EVIOCGID, &id) == -1)
        perror("Failed to get device id");
    else
    {
        switch(id.bustype)
        {
        case BUS_PCI: printf("Bustype PCI "); break;
        case BUS_ISAPNP: printf("Bustype ISAPNP "); break;
        case BUS_USB: printf("Bustype USB "); break;
        case BUS_HIL: printf("Bustype HIL "); break;
        case BUS_BLUETOOTH: printf("Bustype BLUETOOTH "); break;
        case BUS_VIRTUAL: printf("Bustype VIRTUAL "); break;
        case BUS_ISA: printf("Bustype ISA "); break;
        case BUS_I8042: printf("Bustype I8042 "); break;
        case BUS_XTKBD: printf("Bustype XTKBD "); break;
        case BUS_RS232: printf("Bustype RS232 "); break;
        case BUS_GAMEPORT: printf("Bustype GAMEPORT "); break;
        case BUS_PARPORT: printf("Bustype PARPORT "); break;
        case BUS_AMIGA: printf("Bustype AMIGA "); break;
        case BUS_ADB: printf("Bustype ADB "); break;
        case BUS_I2C: printf("Bustype I2C "); break;
        case BUS_HOST: printf("Bustype HOST "); break;
        case BUS_GSC: printf("Bustype GSC "); break;
        case BUS_ATARI: printf("Bustype ATARI "); break;
        case BUS_SPI: printf("Bustype SPI "); break;
        default: printf("Bustype unknown(%04hx) ", id.bustype);
        }
        printf("Vendor %04hx ", id.vendor);
        printf("Product %04hx ", id.product);
        printf("Version %04hx\n", id.version);
    }
    if(ioctl(fd, EVIOCGVERSION, &version) == -1)
        perror("Failed to get driver version");
    else
        printf("Driver: %i.%i.%i\n", version>>16,
            (version>>8) & 0xff, version & 0xff);
    if(ioctl(fd, EVIOCGBIT(0, EV_MAX), &evtype) == -1)
        perror("Failed to get event types");
    else
    {
        printf("Events: ");
        for(i=0; i<EV_MAX; i++)
            if(evtype[i/8] & (1<<(i%8)))
                printf("%s ", strevent(i));
        printf("\n");
    }
}
开发者ID:Yomin,项目名称:neobox,代码行数:63,代码来源:iod.c

示例12: read_devinfo


//.........这里部分代码省略.........
  /* switches */

  if (TEST_ARRAY_BIT(devinfo->evbit, EV_SW)) {
    if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof(devinfo->swbit)), devinfo->swbit) < 0) {
      fprintf(stderr, "ioctl(EVIOCGBIT(EV_SW)): %s\n", strerror(errno));
      goto err_ioctl;
    }

    /* switch state */

    if (TEST_ARRAY_BIT(devinfo->evbit, EV_SW)) {
      if (ioctl(fd, EVIOCGSW(sizeof(devinfo->sw)), devinfo->sw) < 0) {
        fprintf(stderr, "ioctl(EVIOCGSW(%zu)): %s\n",
                sizeof(buf), strerror(errno));
        goto err_ioctl;
      }
    }
  }

  /* auto repeat */

  if (TEST_ARRAY_BIT(devinfo->evbit, EV_REP)) {
    if (ioctl(fd, EVIOCGREP, devinfo->rep) < 0) {
      fprintf(stderr, "ioctl(EVIOCGREP): %s\n", strerror(errno));
      goto err_ioctl;
    }
  }

  /* name */

  memset(buf, 0, sizeof(buf));

  do {
    res = ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
  } while ((res < 0) && (errno == EINTR));

  if (res >= 0) {
    devinfo->name = strndup(buf, sizeof(buf)-1);

    if (!devinfo->name) {
      fprintf(stderr, "strdup: %s\n", strerror(errno));
      goto err_strdup_name;
    }
  } else if (errno != ENOENT) {
    fprintf(stderr, "ioctl(EVIOCGPHYS(%lu)): %s\n",
            (unsigned long)sizeof(buf), strerror(errno));
    goto err_ioctl;
  }

  /* physical location */

  memset(buf, 0, sizeof(buf));

  do {
    res = ioctl(fd, EVIOCGPHYS(sizeof(buf)), buf);
  } while ((res < 0) && (errno == EINTR));

  if (res >= 0) {
    devinfo->phys = strndup(buf, sizeof(buf)-1);

    if (!devinfo->phys) {
      fprintf(stderr, "strdup: %s\n", strerror(errno));
      goto err_strdup_phys;
    }
  } else if (errno != ENOENT) {
    fprintf(stderr, "ioctl(EVIOCGPHYS(%lu)): %s\n",
开发者ID:AlanHuang,项目名称:orangutan,代码行数:67,代码来源:mkdevinfo.c

示例13: remoteControlThread

/****************************************************************************
 *
 * @brief
 * Fukncija koja se treba kreirati kao poseban thread, a predstavlja beskonacnu petlju koja se vrti, 
 * i u slucaju pritiska dugmeta na daljinskom upravljacu aktivira se odgovarajuca callback funkcija.
 *
 *
 *
 *
 *****************************************************************************/
void* remoteControlThread(void* nn)
{
    const char* dev = "/dev/input/event0";
    char deviceName[20];
    struct input_event* eventBuf;
    uint32_t eventCnt;
    uint32_t i;
    uint32_t service_number = 1;
    uint32_t tmp_number;
    uint32_t tmp_number2;
    inputFileDesc = open(dev, O_RDWR);
    if (inputFileDesc == -1)
    {
        printf("Error while opening device (%s) !", strerror(errno));
        return;
    }
    ioctl(inputFileDesc, EVIOCGNAME(sizeof (deviceName)), deviceName);
    printf("RC device opened succesfully [%s]\n", deviceName);

    eventBuf = malloc(NUM_EVENTS * sizeof (struct input_event));
    if (!eventBuf)
    {
        printf("Error allocating memory !");
        return;
    }
    tmp_number = service_number;

    while (NON_STOP)
    {
        if (getKeys(NUM_EVENTS, (uint8_t*) eventBuf, &eventCnt))
        {
            printf("Error while reading input events !");
            return;
        }

        for (i = 0; i < eventCnt; i++)
        {
            if (eventBuf[i].value == 1 && eventBuf[i].type == 1)
            {
                tmp_number2 = service_number;
                switch (eventBuf[i].code)
                {
                case REMOTE_BTN_PROGRAM_PLUS:
                    if (sectionNumberCallback(service_number + 1) == NO_ERROR)
                    {
                        service_number++;
                    }
                    break;
                case REMOTE_BTN_PROGRAM_MINUS:

                    if (sectionNumberCallback(service_number - 1) == NO_ERROR)
                    {
                        service_number--;
                    }
                    break;
                case REMOTE_BTN_VOLUME_PLUS:
                    if (volumeCallback != NULL)
                    {
                        volumeCallback(VOLUME_PLUS);
                    }
                    break;
                case REMOTE_BTN_VOLUME_MINUS:
                    if (volumeCallback != NULL)
                    {
                        volumeCallback(VOLUME_MINUS);
                    }
                    break;
                case REMOTE_BTN_MUTE:
                    printf(" MUTE\n");
                    if (volumeCallback != NULL)
                    {
                        volumeCallback(VOLUME_MUTE);
                    }
                    break;
                case REMOTE_BTN_INFO:
                    if (infoCallback != NULL)
                    {
                        infoCallback(1);
                    }
                    break;
                case REMOTE_BTN_EXIT:
                    free(eventBuf);
                    return;
                default:
                    tmp_number = remoteCheckServiceNumberCode(eventBuf[i].code);
                    if (tmp_number != -1)
                    {
                        //  printf("****Service number: %d tmp_number\n", service_number);
                        if (sectionNumberCallback(tmp_number) == NO_ERROR)
                        {
//.........这里部分代码省略.........
开发者ID:RockLegend93,项目名称:DTV_zapper,代码行数:101,代码来源:remote.c

示例14: main

int main(int argc,char* argv[])
{
	
	int fd;
  	int read_num = 0, opt = 0;
  	

	fprintf(stderr,"input device test v0.1\n");
	fprintf(stderr,"This program was compiled at %s %s\n",__DATE__,__TIME__);
	fprintf(stderr,"Author: [email protected]\n");

	   
   while ((opt = getopt(argc, argv, "hr:")) != -1) {
       switch (opt) {
       case 'r':
       		read_num = atoi(optarg);
       		break;
       case 'h':
       default:
           usage(argv[0]);
           return 0;
       }
   }
	
	if (optind >= argc) {
		  usage(argv[0]);
          return -1;
    }
    
	char devpath[256] = "\0";
	if(argv[optind][0] != '/'){
		strcpy(devpath,"/dev/input/");
	}
	strcat(devpath,argv[optind]);
	printf("event driver: %s\n", devpath);

// if((file = open(str, O_RDWR|O_NONBLOCK)) < 0)
	if((fd = open(devpath, O_RDWR)) < 0)
	{
		perror("device can not open");
		return -2;
	}

	
	//Listing 1. Sample EVIOCGVERSION Function
	/* ioctl() accesses the underlying driver */
	int version = 0;
	if (ioctl(fd, EVIOCGVERSION, &version)) {
	    perror("EVIOCGVERSION");
	}
	
	/* the EVIOCGVERSION ioctl() returns an int */
	/* so we unpack it and display it */
	printf("\tversion is %d.%d.%d\n",
	       version >> 16, (version >> 8) & 0xff,
	       version & 0xff);

	
	//Listing 3. Sample EVIOCGID ioctl 
	/* suck out some device information */
	struct input_id device_info;
	if(ioctl(fd, EVIOCGID, &device_info)) {
	    perror("EVIOCGVERSION");
	}
	
	/* the EVIOCGID ioctl() returns input_devinfo
	 * structure - see <linux/input.h>
	 * So we work through the various elements,
	 * displaying each of them
	 */
	printf("\tvendor %04hx product %04hx version %04hx",
	       device_info.vendor, device_info.product,
	       device_info.version);
	switch ( device_info.bustype)
	{
	 case BUS_PCI :
	     printf(" is on a PCI bus\n");
	     break;
	 case BUS_USB :
	     printf(" is on a Universal Serial Bus\n");
	     break;
	 case BUS_I2C :
	     printf(" is on BUS_I2C\n");
	     break;	     
	default:
		printf(" is on an unknow bus %x\n",(unsigned int)device_info.bustype);
		break;	     
	}

	//Listing 4. get name 
	char name[256]= "Unknown";
	if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) {
	    perror("EVIOCGNAME");
	}
	printf("\tname is %s\n", name);
	
	//Listing 5. Using EVIOCGPHYS for Topology Information
	char phys[256]= "\0";
	if(ioctl(fd, EVIOCGPHYS(sizeof(phys)), phys) < 0) {
	    //perror("EVIOCGPHYS ");
//.........这里部分代码省略.........
开发者ID:largeriver,项目名称:tests,代码行数:101,代码来源:main.c

示例15: Gamepad_detectDevices

void Gamepad_detectDevices() {
    unsigned int numPaths;
    char ** gamepadPaths;
    bool duplicate;
    unsigned int pathIndex, gamepadIndex;
    struct stat statBuf;
    struct Gamepad_device * deviceRecord;
    struct Gamepad_devicePrivate * deviceRecordPrivate;
    int fd;
    char name[128];
    char * description;
    int evKeyBits[(KEY_CNT - 1) / sizeof(int) * 8 + 1];
    int evAbsBits[(ABS_CNT - 1) / sizeof(int) * 8 + 1];
    int bit;
    struct input_id id;

    if (!inited) {
        return;
    }

    gamepadPaths = findGamepadPaths(&numPaths);

    pthread_mutex_lock(&devicesMutex);
    for (pathIndex = 0; pathIndex < numPaths; pathIndex++) {
        duplicate = false;
        for (gamepadIndex = 0; gamepadIndex < numDevices; gamepadIndex++) {
            if (!strcmp(((struct Gamepad_devicePrivate *) devices[gamepadIndex]->privateData)->path, gamepadPaths[pathIndex])) {
                duplicate = true;
                break;
            }
        }
        if (duplicate) {
            free(gamepadPaths[pathIndex]);
            continue;
        }

        if (!stat(gamepadPaths[pathIndex], &statBuf)) {
            deviceRecord = (Gamepad_device*)malloc(sizeof(struct Gamepad_device));
            deviceRecord->deviceID = nextDeviceID++;
            deviceRecord->eventDispatcher = EventDispatcher_create(deviceRecord);
            devices = (Gamepad_device**)realloc(devices, sizeof(struct Gamepad_device *) * (numDevices + 1));
            devices[numDevices++] = deviceRecord;

            fd = open(gamepadPaths[pathIndex], O_RDONLY, 0);

            deviceRecordPrivate = (Gamepad_devicePrivate*)malloc(sizeof(struct Gamepad_devicePrivate));
            deviceRecordPrivate->fd = fd;
            deviceRecordPrivate->path = gamepadPaths[pathIndex];
            memset(deviceRecordPrivate->buttonMap, 0xFF, sizeof(deviceRecordPrivate->buttonMap));
            memset(deviceRecordPrivate->axisMap, 0xFF, sizeof(deviceRecordPrivate->axisMap));
            deviceRecord->privateData = deviceRecordPrivate;

            if (ioctl(fd, EVIOCGNAME(sizeof(name)), name) > 0) {
                description = (char*)malloc(strlen(name + 1));
                strcpy(description, name);
            } else {
                description = (char*)malloc(strlen(gamepadPaths[pathIndex] + 1));
                strcpy(description, gamepadPaths[pathIndex]);
            }
            deviceRecord->description = description;

            if (!ioctl(fd, EVIOCGID, &id)) {
                deviceRecord->vendorID = id.vendor;
                deviceRecord->productID = id.product;
            } else {
                deviceRecord->vendorID = deviceRecord->productID = 0;
            }

            memset(evKeyBits, 0, sizeof(evKeyBits));
            memset(evAbsBits, 0, sizeof(evAbsBits));
            ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(evKeyBits)), evKeyBits);
            ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(evAbsBits)), evAbsBits);

            deviceRecord->numAxes = 0;
            for (bit = 0; bit < ABS_CNT; bit++) {
                if (test_bit(bit, evAbsBits)) {
                    if (ioctl(fd, EVIOCGABS(bit), &deviceRecordPrivate->axisInfo[bit]) < 0 ||
                            deviceRecordPrivate->axisInfo[bit].minimum == deviceRecordPrivate->axisInfo[bit].maximum) {
                        continue;
                    }
                    deviceRecordPrivate->axisMap[bit] = deviceRecord->numAxes;
                    deviceRecord->numAxes++;
                }
            }
            deviceRecord->numButtons = 0;
            for (bit = BTN_MISC; bit < KEY_CNT; bit++) {
                if (test_bit(bit, evKeyBits)) {
                    deviceRecordPrivate->buttonMap[bit - BTN_MISC] = deviceRecord->numButtons;
                    deviceRecord->numButtons++;
                }
            }

            deviceRecord->axisStates = (float*)calloc(sizeof(float), deviceRecord->numAxes);
            deviceRecord->buttonStates = (bool*)calloc(sizeof(bool), deviceRecord->numButtons);

            Gamepad_eventDispatcher()->dispatchEvent(Gamepad_eventDispatcher(), GAMEPAD_EVENT_DEVICE_ATTACHED, deviceRecord);

            pthread_create(&deviceRecordPrivate->thread, NULL, deviceThread, deviceRecord);
        }
    }
//.........这里部分代码省略.........
开发者ID:Algomorph,项目名称:HAL,代码行数:101,代码来源:Gamepad_linux.cpp


注:本文中的EVIOCGNAME函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。