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


C++ EVIOCGBIT函数代码示例

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


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

示例1: evdev_is_suitable

int evdev_is_suitable(int fd)
{
	long evtype_bitmask[(EV_MAX/BITS_PER_LONG) + 1];

	/* Clean evtype_bitmask structure */
	memset(evtype_bitmask, 0, sizeof(evtype_bitmask));

	/* Ask device features */
	if (ioctl(fd, EVIOCGBIT(0, EV_MAX), evtype_bitmask) < 0) {
		log_msg(lg, "+ can't get evdev features: %s", ERRMSG);
		return 0;
	}

#ifdef DEBUG
	int yalv;
	for (yalv = 0; yalv < EV_MAX; yalv++) {
		if (test_bit(yalv, evtype_bitmask)) {
			/* this means that the bit is set in the event types list */
			switch (yalv) {
			case EV_SYN:
				log_msg(lg, " + Sync");
				break;
			case EV_KEY:
				log_msg(lg, " + Keys or Buttons");
				break;
			case EV_REL:
				log_msg(lg, " + Relative Axes");
				break;
			case EV_ABS:
				log_msg(lg, " + Absolute Axes");
				break;
			case EV_MSC:
				log_msg(lg, " + Something miscellaneous");
				break;
			case EV_SW:
				log_msg(lg, " + Switch");
				break;
			case EV_LED:
				log_msg(lg, " + LEDs");
				break;
			case EV_SND:
				log_msg(lg, " + Sounds");
				break;
			case EV_REP:
				log_msg(lg, " + Repeat");
				break;
			case EV_FF:
				log_msg(lg, " + Force Feedback");
				break;
			case EV_PWR:
				log_msg(lg, " + Power");
				break;
			case EV_FF_STATUS:
				log_msg(lg, " + Force Feedback Status");
				break;
			default:
				log_msg(lg, " + Unknown event type: 0x%04hx", yalv);
				break;
			}
		}
	}
#endif

	/* Check that we have EV_KEY bit set */
	if (test_bit(EV_KEY, evtype_bitmask)) return 1;

	/* device is not suitable */
	log_msg(lg, "+ evdev have no EV_KEY bit, skipped");
	return 0;
}
开发者ID:zeldin,项目名称:kexecboot,代码行数:70,代码来源:evdevs.c

示例2: CalcOldStyleID

      compat_hat_offs = ev_abs_count;
     ev_hat_count++;
    }
    ev_abs_count++;
   }
  }
  //printf("%u\n", compat_hat_offs);
  CalcOldStyleID(ev_abs_count - ev_hat_count, 0, ev_hat_count / 2, num_buttons);
 }

#if 0
  uint8 keybits[(KEY_CNT + 7) / 8];
  unsigned ev_button_count = 0;
  
  memset(keybits, 0, sizeof(keybits));
  ioctl(evdev_fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
  hashie.update(keybits, sizeof(keybits));

  for(unsigned kbt = 0; kbt < KEY_CNT; kbt++)
  {
   if(keybits[kbt >> 3] & (1 << (kbt & 0x7)))
   {
    ev_button_count++;
   }
  }
  printf("moo: %u\n", ev_button_count);
 }
#endif

 rumble_supported = false;
 rumble_used = false;
开发者ID:gameblabla,项目名称:mednafen-gcw,代码行数:31,代码来源:Joystick_Linux.cpp

示例3: lightgun_event_abs_init

void lightgun_event_abs_init(void)
{
	int i;

	for (i = 0; i < GUN_MAX; i++) {
		char name[256] = "Unknown";
		uint8_t abs_bitmask[ABS_MAX/8 + 1];
		struct input_absinfo abs_features;

		if (!lg_devices[i].device)
			continue;

		if ((lg_devices[i].fd = open(lg_devices[i].device, O_RDONLY)) < 0) {
			fprintf(stderr_file, "Lightgun%d: %s[open]: %s",
				i + 1, lg_devices[i].device, strerror(errno));
			continue;
		}

		if (ioctl(lg_devices[i].fd, EVIOCGNAME(sizeof(name)), name) < 0) {
			fprintf(stderr_file, "Lightgun%d: %s[ioctl/EVIOCGNAME]: %s\n",
				i + 1, lg_devices[i].device, strerror(errno));
			lg_devices[i].device = NULL;
			continue;
		}

		memset(abs_bitmask, 0, sizeof(abs_bitmask));
		if (ioctl(lg_devices[i].fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) < 0) {
			fprintf(stderr_file, "Lightgun%d: %s[ioctl/EVIOCGNAME]: %s\n",
				i + 1, lg_devices[i].device, strerror(errno));
			lg_devices[i].device = NULL;
			continue;
		}

		/* Make sure we have an X and Y axis. Not much good
		 * without it. */
		if (!test_bit(ABS_X, abs_bitmask) || !test_bit(ABS_Y, abs_bitmask)) {
			fprintf(stderr_file, "Lightgun%d: %s: Does not contain both X and Y axis, "
				"ignoring\n", i + 1, lg_devices[i].device);
			lg_devices[i].device = NULL;
			continue;
		}

		if (ioctl(lg_devices[i].fd, EVIOCGABS(ABS_X), &abs_features)) {
			fprintf(stderr_file, "Lightgun%d: %s[ioctl/EVIOCGABS(ABX_X)]: %s\n",
				i + 1, lg_devices[i].device, strerror(errno));
			lg_devices[i].device = NULL;
			continue;
		}

		lg_devices[i].min[LG_X_AXIS] = abs_features.minimum;
		lg_devices[i].range[LG_X_AXIS] = abs_features.maximum - abs_features.minimum;

		if (ioctl(lg_devices[i].fd, EVIOCGABS(ABS_Y), &abs_features)) {
			fprintf(stderr_file, "Lightgun%d: %s[ioctl/EVIOCGABS(ABX_Y)]: %s\n",
				i + 1, lg_devices[i].device, strerror(errno));
			lg_devices[i].device = NULL;
			continue;
		}

		lg_devices[i].min[LG_Y_AXIS] = abs_features.minimum;
		lg_devices[i].range[LG_Y_AXIS] = abs_features.maximum - abs_features.minimum;

		fprintf(stderr_file, "Lightgun%d: %s\n", i + 1, name);
		fprintf(stderr_file, "           X axis:  min[%d]  range[%d]\n",
			lg_devices[i].min[LG_X_AXIS], lg_devices[i].range[LG_X_AXIS]);
		fprintf(stderr_file, "           Y axis:  min[%d]  range[%d]\n",
			lg_devices[i].min[LG_Y_AXIS], lg_devices[i].range[LG_Y_AXIS]);
	}
}
开发者ID:CrouchingLlama,项目名称:openlase-mame,代码行数:69,代码来源:lightgun_abs_event.c

示例4: bzero

/*
 * Fill device information.
 * Queries the input device and tries to classify it.
 */
void CLinuxInputDevice::GetInfo(int fd)
{
  unsigned int num_keys = 0;
  unsigned int num_ext_keys = 0;
  unsigned int num_buttons = 0;
  unsigned int num_rels = 0;
  unsigned int num_abs = 0;

  unsigned long evbit[NBITS(EV_CNT)];
  unsigned long keybit[NBITS(KEY_CNT)];

  /* get device name */
  bzero(m_deviceName, sizeof(m_deviceName));
  ioctl(fd, EVIOCGNAME(sizeof(m_deviceName)-1), m_deviceName);

  if (strncmp(m_deviceName, "D-Link Boxee D-Link Boxee Receiver", strlen("D-Link Boxee D-Link Boxee Receiver")) == 0)
  {
    m_bSkipNonKeyEvents = true;
  }
  else
  {
    m_bSkipNonKeyEvents = false;
  }
  CLog::Log(LOGINFO, "opened device '%s' (file name %s), m_bSkipNonKeyEvents %d\n", m_deviceName, m_fileName.c_str(), m_bSkipNonKeyEvents);

  /* get event type bits */
  ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit);

  if (test_bit( EV_KEY, evbit ))
  {
    int i;

    /* get keyboard bits */
    ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit);

    /**  count typical keyboard keys only */
    for (i = KEY_Q; i <= KEY_M; i++)
      if (test_bit( i, keybit ))
        num_keys++;

    for (i = KEY_OK; i < KEY_CNT; i++)
      if (test_bit( i, keybit ))
        num_ext_keys++;

    for (i = BTN_MOUSE; i < BTN_JOYSTICK; i++)
      if (test_bit( i, keybit ))
        num_buttons++;
  }

#ifndef HAS_INTELCE
  unsigned long relbit[NBITS(REL_CNT)];
  unsigned long absbit[NBITS(ABS_CNT)];

  if (test_bit( EV_REL, evbit ))
  {
    int i;

    /* get bits for relative axes */
    ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit);

    for (i = 0; i < REL_CNT; i++)
      if (test_bit( i, relbit ))
        num_rels++;
  }

  if (test_bit( EV_ABS, evbit ))
  {
    int i;

    /* get bits for absolute axes */
    ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit);

    for (i = 0; i < ABS_PRESSURE; i++)
      if (test_bit( i, absbit ))
        num_abs++;
  }

  /* Mouse, Touchscreen or Smartpad ? */
  if ((test_bit( EV_KEY, evbit ) && (test_bit( BTN_TOUCH, keybit )
      || test_bit( BTN_TOOL_FINGER, keybit ))) || ((num_rels >= 2
      && num_buttons) || (num_abs == 2 && (num_buttons == 1))))
    m_deviceType |= LI_DEVICE_MOUSE;
  else if (num_abs && num_buttons) /* Or a Joystick? */
    m_deviceType |= LI_DEVICE_JOYSTICK;
#endif

  /* A Keyboard, do we have at least some letters? */
  if (num_keys > 20)
  {
    m_deviceType |= LI_DEVICE_KEYBOARD;
    m_deviceCaps |= LI_CAPS_KEYS;

    m_deviceMinKeyCode = 0;
    m_deviceMaxKeyCode = 127;
  }

//.........这里部分代码省略.........
开发者ID:AFFLUENTSOCIETY,项目名称:SPMC,代码行数:101,代码来源:LinuxInputDevices.cpp

示例5: main

int main(int argc, char ** argv)
{
	int fd;
	unsigned long *evtype_b = malloc(sizeof(int));
	int yalv;

	if ((fd = open(argv[1], O_RDONLY)) < 0) {
		perror("evdev open");
		exit(1);
	}

	memset(evtype_b, 0, sizeof(evtype_b));

	if (ioctl(fd, EVIOCGBIT(0, EV_MAX), evtype_b) < 0) {
		perror("evdev ioctl");
	}

	printf("Supported event types:\n");

	for (yalv = 0; yalv < EV_MAX; yalv++) {
		if (test_bit(yalv, evtype_b)) {
			/* the bit is set in the event types list */
			printf(" Event type 0x%02x ", yalv);

			switch (yalv) {
				case EV_SYN :
					printf(" (Synch Events)\n");
					break;
				case EV_KEY :
					printf(" (Keys or Buttons)\n");
					break;
				case EV_REL :
					printf(" (Relative Axes)\n");
					break;
				case EV_ABS :
					printf(" (Absolute Axes)\n");
					break;
				case EV_MSC :
					printf(" (Miscellaneous)\n");
					break;
				case EV_LED :
					printf(" (LEDs)\n");
					break;
				case EV_SND :
					printf(" (Sounds)\n");
					break;
				case EV_REP :
					printf(" (Repeat)\n");
					break;
				case EV_FF :
				case EV_FF_STATUS:
					printf(" (Force Feedback)\n");
					break;
				case EV_PWR:
					printf(" (Power Management)\n");
					break;
				default:
					printf(" (Unknown: 0x%04hx)\n", yalv);
			}
		}
	}
	close(fd);
}
开发者ID:xxha,项目名称:sclib,代码行数:63,代码来源:test_event0.c

示例6: evdev_handle_device

static int
evdev_handle_device(struct evdev_device *device)
{
	struct input_absinfo absinfo;
	unsigned long ev_bits[NBITS(EV_MAX)];
	unsigned long abs_bits[NBITS(ABS_MAX)];
	unsigned long rel_bits[NBITS(REL_MAX)];
	unsigned long key_bits[NBITS(KEY_MAX)];
	int has_key, has_abs;
	unsigned int i;

	has_key = 0;
	has_abs = 0;
	device->caps = 0;

	ioctl(device->fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits);
	if (TEST_BIT(ev_bits, EV_ABS)) {
		has_abs = 1;

		ioctl(device->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)),
		      abs_bits);
		if (TEST_BIT(abs_bits, ABS_X)) {
			ioctl(device->fd, EVIOCGABS(ABS_X), &absinfo);
			device->abs.min_x = absinfo.minimum;
			device->abs.max_x = absinfo.maximum;
			device->caps |= EVDEV_MOTION_ABS;
		}
		if (TEST_BIT(abs_bits, ABS_Y)) {
			ioctl(device->fd, EVIOCGABS(ABS_Y), &absinfo);
			device->abs.min_y = absinfo.minimum;
			device->abs.max_y = absinfo.maximum;
			device->caps |= EVDEV_MOTION_ABS;
		}
		if (TEST_BIT(abs_bits, ABS_MT_SLOT)) {
			ioctl(device->fd, EVIOCGABS(ABS_MT_POSITION_X),
			      &absinfo);
			device->abs.min_x = absinfo.minimum;
			device->abs.max_x = absinfo.maximum;
			ioctl(device->fd, EVIOCGABS(ABS_MT_POSITION_Y),
			      &absinfo);
			device->abs.min_y = absinfo.minimum;
			device->abs.max_y = absinfo.maximum;
			device->is_mt = 1;
			device->mt.slot = 0;
			device->caps |= EVDEV_TOUCH;
		}
	}
	if (TEST_BIT(ev_bits, EV_REL)) {
		ioctl(device->fd, EVIOCGBIT(EV_REL, sizeof(rel_bits)),
		      rel_bits);
		if (TEST_BIT(rel_bits, REL_X) || TEST_BIT(rel_bits, REL_Y))
			device->caps |= EVDEV_MOTION_REL;
	}
	if (TEST_BIT(ev_bits, EV_KEY)) {
		has_key = 1;
		ioctl(device->fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)),
		      key_bits);
		if (TEST_BIT(key_bits, BTN_TOOL_FINGER) &&
		    !TEST_BIT(key_bits, BTN_TOOL_PEN) &&
		    has_abs)
			device->dispatch = evdev_touchpad_create(device);
		for (i = KEY_ESC; i < KEY_MAX; i++) {
			if (i >= BTN_MISC && i < KEY_OK)
				continue;
			if (TEST_BIT(key_bits, i)) {
				device->caps |= EVDEV_KEYBOARD;
				break;
			}
		}
		for (i = BTN_MISC; i < KEY_OK; i++) {
			if (TEST_BIT(key_bits, i)) {
				device->caps |= EVDEV_BUTTON;
				break;
			}
		}
	}
	if (TEST_BIT(ev_bits, EV_LED)) {
		device->caps |= EVDEV_KEYBOARD;
	}

	/* This rule tries to catch accelerometer devices and opt out. We may
	 * want to adjust the protocol later adding a proper event for dealing
	 * with accelerometers and implement here accordingly */
	if (has_abs && !has_key && !device->is_mt) {
		weston_log("input device %s, %s "
			   "ignored: unsupported device type\n",
			   device->devname, device->devnode);
		return 0;
	}

	return 1;
}
开发者ID:anderco,项目名称:weston,代码行数:92,代码来源:evdev.c

示例7: ConfigJoystick

static void
ConfigJoystick(SDL_Joystick * joystick, int fd)
{
    int i, t;
    unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
    unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
    unsigned long relbit[NBITS(REL_MAX)] = { 0 };

    /* See if this device uses the new unified event API */
    if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
        (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) &&
        (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)) {

        /* Get the number of buttons, axes, and other thingamajigs */
        for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
            if (test_bit(i, keybit)) {
#ifdef DEBUG_INPUT_EVENTS
                printf("Joystick has button: 0x%x\n", i);
#endif
                joystick->hwdata->key_map[i] = joystick->nbuttons;
                ++joystick->nbuttons;
            }
        }
        for (i = 0; i < BTN_JOYSTICK; ++i) {
            if (test_bit(i, keybit)) {
#ifdef DEBUG_INPUT_EVENTS
                printf("Joystick has button: 0x%x\n", i);
#endif
                joystick->hwdata->key_map[i] = joystick->nbuttons;
                ++joystick->nbuttons;
            }
        }
        for (i = 0; i < ABS_MAX; ++i) {
            /* Skip hats */
            if (i == ABS_HAT0X) {
                i = ABS_HAT3Y;
                continue;
            }
            if (test_bit(i, absbit)) {
                struct input_absinfo absinfo;

                if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
                    continue;
                }
#ifdef DEBUG_INPUT_EVENTS
                printf("Joystick has absolute axis: 0x%.2x\n", i);
                printf("Values = { %d, %d, %d, %d, %d }\n",
                       absinfo.value, absinfo.minimum, absinfo.maximum,
                       absinfo.fuzz, absinfo.flat);
#endif /* DEBUG_INPUT_EVENTS */
                joystick->hwdata->abs_map[i] = joystick->naxes;
                if (absinfo.minimum == absinfo.maximum) {
                    joystick->hwdata->abs_correct[i].used = 0;
                } else {
                    joystick->hwdata->abs_correct[i].used = 1;
                    joystick->hwdata->abs_correct[i].coef[0] =
                        (absinfo.maximum + absinfo.minimum) - 2 * absinfo.flat;
                    joystick->hwdata->abs_correct[i].coef[1] =
                        (absinfo.maximum + absinfo.minimum) + 2 * absinfo.flat;
                    t = ((absinfo.maximum - absinfo.minimum) - 4 * absinfo.flat);
                    if (t != 0) {
                        joystick->hwdata->abs_correct[i].coef[2] =
                            (1 << 28) / t;
                    } else {
                        joystick->hwdata->abs_correct[i].coef[2] = 0;
                    }
                }
                ++joystick->naxes;
            }
        }
        for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) {
            if (test_bit(i, absbit) || test_bit(i + 1, absbit)) {
                struct input_absinfo absinfo;

                if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
                    continue;
                }
#ifdef DEBUG_INPUT_EVENTS
                printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2);
                printf("Values = { %d, %d, %d, %d, %d }\n",
                       absinfo.value, absinfo.minimum, absinfo.maximum,
                       absinfo.fuzz, absinfo.flat);
#endif /* DEBUG_INPUT_EVENTS */
                ++joystick->nhats;
            }
        }
        if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) {
            ++joystick->nballs;
        }

        /* Allocate data to keep track of these thingamajigs */
        if (joystick->nhats > 0) {
            if (allocate_hatdata(joystick) < 0) {
                joystick->nhats = 0;
            }
        }
        if (joystick->nballs > 0) {
            if (allocate_balldata(joystick) < 0) {
                joystick->nballs = 0;
            }
//.........这里部分代码省略.........
开发者ID:vroad,项目名称:sdl,代码行数:101,代码来源:SDL_sysjoystick.c

示例8: get_free_joy_slot

void joystick_linux::open_joystick(const char *p_path) {

    int joy_num = get_free_joy_slot();
    int fd = open(p_path, O_RDONLY | O_NONBLOCK);
    if (fd != -1 && joy_num != -1) {

        unsigned long evbit[NBITS(EV_MAX)] = { 0 };
        unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
        unsigned long absbit[NBITS(ABS_MAX)] = { 0 };

        if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
                (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
                (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
            close(fd);
            return;
        }

        //check if the device supports basic gamepad events, prevents certain keyboards from
        //being detected as joysticks
        if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
                (test_bit(ABS_X, absbit) || test_bit(ABS_Y, absbit) || test_bit(ABS_HAT0X, absbit) ||
                 test_bit(ABS_GAS, absbit) || test_bit(ABS_RUDDER, absbit)) &&
                (test_bit(BTN_A, keybit) || test_bit(BTN_THUMBL, keybit) ||
                 test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_1, keybit)))) {
            close(fd);
            return;
        }

        char uid[128];
        char namebuf[128];
        String name = "";
        input_id inpid;
        if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) >= 0) {
            name = namebuf;
        }

        if (ioctl(fd, EVIOCGID, &inpid) < 0) {
            close(fd);
            return;
        }

        joysticks[joy_num].reset();

        Joystick &joy = joysticks[joy_num];
        joy.fd = fd;
        joy.devpath = String(p_path);
        setup_joystick_properties(joy_num);
        sprintf(uid, "%04x%04x", __bswap_16(inpid.bustype), 0);
        if (inpid.vendor && inpid.product && inpid.version) {

            uint16_t vendor = __bswap_16(inpid.vendor);
            uint16_t product = __bswap_16(inpid.product);
            uint16_t version = __bswap_16(inpid.version);

            sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor,0,product,0,version,0);
            input->joy_connection_changed(joy_num, true, name, uid);
        }
        else {
            String uidname = uid;
            int uidlen = MIN(name.length(), 11);
            for (int i=0; i<uidlen; i++) {

                uidname = uidname + _hex_str(name[i]);
            }
            uidname += "00";
            input->joy_connection_changed(joy_num, true, name, uidname);
        }
    }
}
开发者ID:francogarcia,项目名称:godot,代码行数:69,代码来源:joystick_linux.cpp

示例9: pa__init

int pa__init(pa_module*m) {

    pa_modargs *ma = NULL;
    struct userdata *u;
    int version;
    struct input_id input_id;
    char name[256];
    uint8_t evtype_bitmask[EV_MAX/8 + 1];
    pa_volume_t volume_limit = PA_VOLUME_NORM*3/2;
    pa_volume_t volume_step = PA_VOLUME_NORM/20;

    pa_assert(m);

    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
        pa_log("Failed to parse module arguments");
        goto fail;
    }

    if (pa_modargs_get_value_u32(ma, "volume_limit", &volume_limit) < 0) {
        pa_log("Failed to parse volume limit");
        goto fail;
    }

    if (pa_modargs_get_value_u32(ma, "volume_step", &volume_step) < 0) {
        pa_log("Failed to parse volume step");
        goto fail;
    }

    m->userdata = u = pa_xnew(struct userdata, 1);
    u->module = m;
    u->io = NULL;
    u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
    u->fd = -1;
    u->fd_type = 0;
    u->volume_limit = PA_CLAMP_VOLUME(volume_limit);
    u->volume_step = PA_CLAMP_VOLUME(volume_step);

    if ((u->fd = pa_open_cloexec(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), O_RDONLY, 0)) < 0) {
        pa_log("Failed to open evdev device: %s", pa_cstrerror(errno));
        goto fail;
    }

    if (ioctl(u->fd, EVIOCGVERSION, &version) < 0) {
        pa_log("EVIOCGVERSION failed: %s", pa_cstrerror(errno));
        goto fail;
    }

    pa_log_info("evdev driver version %i.%i.%i", version >> 16, (version >> 8) & 0xff, version & 0xff);

    if (ioctl(u->fd, EVIOCGID, &input_id)) {
        pa_log("EVIOCGID failed: %s", pa_cstrerror(errno));
        goto fail;
    }

    pa_log_info("evdev vendor 0x%04hx product 0x%04hx version 0x%04hx bustype %u",
                input_id.vendor, input_id.product, input_id.version, input_id.bustype);

    memset(name, 0, sizeof(name));
    if (ioctl(u->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
        pa_log("EVIOCGNAME failed: %s", pa_cstrerror(errno));
        goto fail;
    }

    pa_log_info("evdev device name: %s", name);

    memset(evtype_bitmask, 0, sizeof(evtype_bitmask));
    if (ioctl(u->fd, EVIOCGBIT(0, EV_MAX), evtype_bitmask) < 0) {
        pa_log("EVIOCGBIT failed: %s", pa_cstrerror(errno));
        goto fail;
    }

    if (!test_bit(EV_KEY, evtype_bitmask)) {
        pa_log("Device has no keys.");
        goto fail;
    }

    u->io = m->core->mainloop->io_new(m->core->mainloop, u->fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u);

    pa_modargs_free(ma);

    return 0;

fail:

    if (ma)
        pa_modargs_free(ma);

    pa__done(m);
    return -1;
}
开发者ID:DryakhlyyZlodey,项目名称:pulseaudio,代码行数:90,代码来源:module-mmkbd-evdev.c

示例10: evtest_test

void evtest_test(const char* filename)
{
    int fd, rd, i, j, k;
    struct input_event ev[64];
    int version;
    unsigned short id[4];
    unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
    char name[256] = "Unknown";
    int abs[5];

    if ((fd = open(filename, O_RDONLY)) < 0) {
        perror("evtest");
        exit(1);
    }

    if (ioctl(fd, EVIOCGVERSION, &version)) {
        perror("evtest: can't get version");
        exit(1);
    }

    printf("Input driver version is %d.%d.%d\n",
           version >> 16, (version >> 8) & 0xff, version & 0xff);

    ioctl(fd, EVIOCGID, id);
    printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
           id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]);

    ioctl(fd, EVIOCGNAME(sizeof(name)), name);
    printf("Input device name: \"%s\"\n", name);

    memset(bit, 0, sizeof(bit));
    ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);
    printf("Supported events:\n");

    for (i = 0; i < EV_MAX; i++)
        if (test_bit(i, bit[0])) {
            printf("  Event type %d (%s)\n", i, events[i] ? events[i] : "?");
            ioctl(fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
            for (j = 0; j < KEY_MAX; j++)
                if (test_bit(j, bit[i])) {
                    printf("    Event code %d (%s)\n", j, names[i] ? (names[i][j] ? names[i][j] : "?") : "?");
                    if (i == EV_ABS) {
                        ioctl(fd, EVIOCGABS(j), abs);
                        for (k = 0; k < 5; k++)
                            if ((k < 3) || abs[k])
                                printf("      %s %6d\n", absval[k], abs[k]);
                    }
                }
        }


    printf("Testing ... (interrupt to exit)\n");

    while (1) {
        rd = read(fd, ev, sizeof(struct input_event) * 64);

        if (rd < (int) sizeof(struct input_event)) {
            printf("yyy\n");
            perror("\nevtest: error reading");
            exit (1);
        }

        for (i = 0; i < rd / sizeof(struct input_event); i++)
            printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %d\n",
                   ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
                   events[ev[i].type] ? events[ev[i].type] : "?",
                   ev[i].code,
                   names[ev[i].type] ? (names[ev[i].type][ev[i].code] ? names[ev[i].type][ev[i].code] : "?") : "?",
                   ev[i].value);

    }
}
开发者ID:qunge12345,项目名称:ubuntu,代码行数:72,代码来源:evtest.c

示例11: evtest_info

void evtest_info(const char* filename, int verbose)
{
    int fd;
    unsigned short id[4];
    char name[256] = "Unknown";

    if ((fd = open(filename, O_RDONLY)) < 0)
    {
        perror(filename);
    }
    else
    {
        int i, j, k;

        int version;
        if (ioctl(fd, EVIOCGVERSION, &version)) {
            perror("evtest: can't get version");
            exit(1);
        }


        unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
        ioctl(fd, EVIOCGID, id);
        ioctl(fd, EVIOCGNAME(sizeof(name)), name);
        memset(bit, 0, sizeof(bit));
        ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);

        if (!verbose)
        {
            printf("%s\t\"%s\"\n", filename, name);
        }
        else
        {
            printf("Input device file: %s\n", filename);
            printf("Input device name: \"%s\"\n", name);

            printf("Input driver version is %d.%d.%d\n",
                   version >> 16, (version >> 8) & 0xff, version & 0xff);

            printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
                   id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]);

            printf("Supported events:\n");

            for (i = 0; i < EV_MAX; i++)
                if (test_bit(i, bit[0])) {
                    printf("  Event type %d (%s)\n", i, events[i] ? events[i] : "?");
                    ioctl(fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
                    for (j = 0; j < KEY_MAX; j++)
                        if (test_bit(j, bit[i])) {
                            printf("    Event code %d (%s)\n", j, names[i] ? (names[i][j] ? names[i][j] : "?") : "?");
                            if (i == EV_ABS) {
                                int abs[5];
                                ioctl(fd, EVIOCGABS(j), abs);
                                for (k = 0; k < 5; k++)
                                    if ((k < 3) || abs[k])
                                        printf("      %s %6d\n", absval[k], abs[k]);
                            }
                        }
                }

            putchar('\n');
        }
    }
}
开发者ID:qunge12345,项目名称:ubuntu,代码行数:65,代码来源:evtest.c

示例12: PIGU_detect_device

int PIGU_detect_device(const char *device, PIGU_device_info_t *info)
{
   uint32_t types[EV_MAX];
   uint32_t events[(KEY_MAX-1)/32+1];
   
   int fd = open(device, O_RDONLY | O_NONBLOCK);

   if(fd<0)
      return -1;

   memset(info, 0, sizeof(PIGU_device_info_t));
   info->fd = fd;
   
   // get device name
   ioctl(fd, EVIOCGNAME(sizeof(info->name)), info->name);

   // query supported event types
   memset(types, 0, sizeof(types));
   ioctl(fd, EVIOCGBIT(0, EV_MAX), types);

   int key_count = 0;
   int mouse_button_count = 0;
   int joystick_button_count = 0;
   int gamepad_button_count = 0;
   PIGU_axis_data_t axes;
   PIGU_init_axis_data(&axes);
   PIGU_button_data_t buttons;
   PIGU_init_button_data(&buttons);

   if(PIGU_get_bit(types, EV_KEY))
   {
      // count events
      memset(events, 0, sizeof(events));
      ioctl(fd, EVIOCGBIT(EV_KEY, KEY_MAX), events);
      int j = 0;
      for(;j<BTN_MISC;++j)
	 if(PIGU_get_bit(events, j))
	    key_count++;

      j = BTN_MOUSE; // skip misc buttons
      
      for(;j<BTN_JOYSTICK;++j)
	 if(PIGU_get_bit(events, j))
	 {
	    mouse_button_count++;
	    if(j-BTN_MOUSE>=16)
	       continue;
	    buttons.map[buttons.count] = j-BTN_MOUSE;
	    buttons.count++;
	 }

      for(;j<BTN_GAMEPAD;++j)
	 if(PIGU_get_bit(events, j))
	 {
	    joystick_button_count++;
	    if(j-BTN_JOYSTICK>=16)
	       continue;
	    buttons.map[buttons.count] = j-BTN_JOYSTICK;
	    buttons.count++;
	 }

      for(;j<BTN_DIGI;++j)
	 if(PIGU_get_bit(events, j))
	 {
	    gamepad_button_count++;
	    if(j-BTN_GAMEPAD>=16)
	       continue;
	    buttons.map[buttons.count] = j-BTN_GAMEPAD;
	    buttons.count++;
	 }
   }


   if(PIGU_get_bit(types, EV_ABS))
   {
      struct input_absinfo abs;
      memset(events, 0, sizeof(events));
      ioctl(fd, EVIOCGBIT(EV_ABS, KEY_MAX), events);
      
      int j = 0;
      for(;j<32;++j)
	 if(PIGU_get_bit(events, j))
	 {
	    axes.map[axes.count] = j;
	    ioctl(fd, EVIOCGABS(j), &abs);

	    axes.position[j] = abs.value;
	    axes.min[j] = abs.minimum;
	    axes.max[j] = abs.maximum;
	    axes.count++;
	 }
   }

   // we simply assume that a device that reports gamepad events
   // is actually a gamepad... a device that reports different types
   // of events will simply detected according to the order of this
   // if chain here.
   info->type = PIGU_UNKNOWN;
   if(gamepad_button_count > 0)
   {
//.........这里部分代码省略.........
开发者ID:Rexhunter99,项目名称:pigu,代码行数:101,代码来源:input.c

示例13: builtin_keyboard

static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], bool test) {
        struct udev_list_entry *entry;
        unsigned release[1024];
        unsigned release_count = 0;
        _cleanup_close_ int fd = -1;
        const char *node;
        int has_abs = -1;

        node = udev_device_get_devnode(dev);
        if (!node) {
                log_error("No device node for \"%s\"", udev_device_get_syspath(dev));
                return EXIT_FAILURE;
        }

        udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(dev)) {
                const char *key;
                char *endptr;

                key = udev_list_entry_get_name(entry);
                if (startswith(key, "KEYBOARD_KEY_")) {
                        const char *keycode;
                        unsigned scancode;

                        /* KEYBOARD_KEY_<hex scan code>=<key identifier string> */
                        scancode = strtoul(key + 13, &endptr, 16);
                        if (endptr[0] != '\0') {
                                log_warning("Unable to parse scan code from \"%s\"", key);
                                continue;
                        }

                        keycode = udev_list_entry_get_value(entry);

                        /* a leading '!' needs a force-release entry */
                        if (keycode[0] == '!') {
                                keycode++;

                                release[release_count] = scancode;
                                if (release_count <  ELEMENTSOF(release)-1)
                                        release_count++;

                                if (keycode[0] == '\0')
                                        continue;
                        }

                        if (fd == -1) {
                                fd = open_device(node);
                                if (fd < 0)
                                        return EXIT_FAILURE;
                        }

                        map_keycode(fd, node, scancode, keycode);
                } else if (startswith(key, "EVDEV_ABS_")) {
                        unsigned evcode;

                        /* EVDEV_ABS_<EV_ABS code>=<min>:<max>:<res>:<fuzz>:<flat> */
                        evcode = strtoul(key + 10, &endptr, 16);
                        if (endptr[0] != '\0') {
                                log_warning("Unable to parse EV_ABS code from \"%s\"", key);
                                continue;
                        }

                        if (fd == -1) {
                                fd = open_device(node);
                                if (fd < 0)
                                        return EXIT_FAILURE;
                        }

                        if (has_abs == -1) {
                                unsigned long bits;
                                int rc;

                                rc = ioctl(fd, EVIOCGBIT(0, sizeof(bits)), &bits);
                                if (rc < 0) {
                                        log_error_errno(errno, "Unable to EVIOCGBIT device \"%s\"", node);
                                        return EXIT_FAILURE;
                                }

                                has_abs = !!(bits & (1 << EV_ABS));
                                if (!has_abs)
                                        log_warning("EVDEV_ABS override set but no EV_ABS present on device \"%s\"", node);
                        }

                        if (!has_abs)
                                continue;

                        override_abs(fd, node, evcode, udev_list_entry_get_value(entry));
                } else if (streq(key, "POINTINGSTICK_SENSITIVITY"))
                        set_trackpoint_sensitivity(dev, udev_list_entry_get_value(entry));
        }

        /* install list of force-release codes */
        if (release_count > 0)
                install_force_release(dev, release, release_count);

        return EXIT_SUCCESS;
}
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:96,代码来源:udev-builtin-keyboard.c

示例14: open_dev_usb

int open_dev_usb(struct device *dev)
{
	int i;
	struct input_absinfo absinfo;
	unsigned char evtype_mask[(EV_MAX + 7) / 8];

	if((dev->fd = open(dev->path, O_RDWR)) == -1) {
		if((dev->fd = open(dev->path, O_RDONLY)) == -1) {
			perror("failed to open device");
			return -1;
		}
		fprintf(stderr, "opened device read-only, LEDs won't work\n");
	}

	if(ioctl(dev->fd, EVIOCGNAME(sizeof dev->name), dev->name) == -1) {
		perror("EVIOCGNAME ioctl failed");
		strcpy(dev->name, "unknown");
	}
	printf("device name: %s\n", dev->name);

	/* get number of axes */
	dev->num_axes = 6;	/* default to regular 6dof controller axis count */
	if(ioctl(dev->fd, EVIOCGBIT(EV_ABS, sizeof evtype_mask), evtype_mask) == 0) {
		dev->num_axes = 0;
		for(i=0; i<ABS_CNT; i++) {
			int idx = i / 8;
			int bit = i % 8;

			if(evtype_mask[idx] & (1 << bit)) {
				dev->num_axes++;
			} else {
				break;
			}
		}
	}
	if(verbose) {
		printf("  Number of axes: %d\n", dev->num_axes);
	}

	dev->minval = malloc(dev->num_axes * sizeof *dev->minval);
	dev->maxval = malloc(dev->num_axes * sizeof *dev->maxval);
	dev->fuzz = malloc(dev->num_axes * sizeof *dev->fuzz);

	if(!dev->minval || !dev->maxval || !dev->fuzz) {
		perror("failed to allocate memory");
		return -1;
	}

	/* if the device is an absolute device, find the minimum and maximum axis values */
	for(i=0; i<dev->num_axes; i++) {
		dev->minval[i] = DEF_MINVAL;
		dev->maxval[i] = DEF_MAXVAL;
		dev->fuzz[i] = 0;

		if(ioctl(dev->fd, EVIOCGABS(i), &absinfo) == 0) {
			dev->minval[i] = absinfo.minimum;
			dev->maxval[i] = absinfo.maximum;
			dev->fuzz[i] = absinfo.fuzz;

			if(verbose) {
				printf("  Axis %d value range: %d - %d (fuzz: %d)\n", i, dev->minval[i], dev->maxval[i], dev->fuzz[i]);
			}
		}
	}

	/*if(ioctl(dev->fd, EVIOCGBIT(0, sizeof(evtype_mask)), evtype_mask) == -1) {
		perror("EVIOCGBIT ioctl failed\n");
		close(dev->fd);
		return -1;
	}*/

	if(cfg.grab_device) {
		int grab = 1;
		/* try to grab the device */
		if(ioctl(dev->fd, EVIOCGRAB, &grab) == -1) {
			perror("failed to grab the device");
		}
	}

	/* set non-blocking */
	fcntl(dev->fd, F_SETFL, fcntl(dev->fd, F_GETFL) | O_NONBLOCK);

	if(cfg.led) {
		set_led_evdev(dev, 1);
	}

	/* fill the device function pointers */
	dev->close = close_evdev;
	dev->read = read_evdev;
	dev->set_led = set_led_evdev;

	return 0;
}
开发者ID:5263,项目名称:spacenav,代码行数:93,代码来源:dev_usb_linux.c

示例15: I_NOSTATE

    I_NOSTATE(USBDEVFS_RESETEP, success),
    I_NOSTATE(USBDEVFS_GETDRIVER, enodata),
    I_NOSTATE(USBDEVFS_IOCTL, enotty),

    I_NOSTATE(EVIOCGRAB, success),

    /* evdev */
    I_SIMPLE_STRUCT_IN(EVIOCGVERSION, 0, ioctl_insertion_parent_stateless),
    I_SIMPLE_STRUCT_IN(EVIOCGID, 0, ioctl_insertion_parent_stateless),
    I_SIMPLE_STRUCT_IN(EVIOCGREP, 0, ioctl_insertion_parent_stateless),
    I_SIMPLE_STRUCT_IN(EVIOCGKEYCODE, 0, ioctl_insertion_parent_stateless),
    I_SIMPLE_STRUCT_IN(EVIOCGKEYCODE_V2, 0, ioctl_insertion_parent_stateless),
    I_SIMPLE_STRUCT_IN(EVIOCGEFFECTS, 0, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGABS(0), "EVIOCGABS", ABS_MAX, ioctl_insertion_parent_stateless),
    /* we define these with len==32, but they apply to any len */
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGBIT(0, 32), "EVIOCGBIT", EV_MAX, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGNAME(32), "EVIOCGNAME", 0, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGPHYS(32), "EVIOCGPHYS", 0, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGUNIQ(32), "EVIOCGUNIQ", 0, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGPROP(32), "EVIOCGPROP", 0, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGKEY(32), "EVIOCGKEY", 0, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGLED(32), "EVIOCGLED", 0, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGSND(32), "EVIOCGSND", 0, ioctl_insertion_parent_stateless),
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGSW(32), "EVIOCGSW", 0, ioctl_insertion_parent_stateless),

    /* this was introduced not too long ago */
#ifdef EVIOCGMTSLOTS
    I_NAMED_SIMPLE_STRUCT_IN(EVIOCGMTSLOTS(32), "EVIOCGMTSLOTS", 0, ioctl_insertion_parent_stateless),
#endif

    /* terminator */
开发者ID:APokorny,项目名称:umockdev,代码行数:31,代码来源:ioctl_tree.c


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