本文整理汇总了C++中NBITS函数的典型用法代码示例。如果您正苦于以下问题:C++ NBITS函数的具体用法?C++ NBITS怎么用?C++ NBITS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NBITS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: builtin_input_id
static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], bool test)
{
struct udev_device *pdev;
unsigned long bitmask_ev[NBITS(EV_MAX)];
unsigned long bitmask_abs[NBITS(ABS_MAX)];
unsigned long bitmask_key[NBITS(KEY_MAX)];
unsigned long bitmask_rel[NBITS(REL_MAX)];
/* walk up the parental chain until we find the real input device; the
* argument is very likely a subdevice of this, like eventN */
pdev = dev;
while (pdev != NULL && udev_device_get_sysattr_value(pdev, "capabilities/ev") == NULL)
pdev = udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
/* not an "input" class device */
if (pdev == NULL)
return EXIT_SUCCESS;
/* Use this as a flag that input devices were detected, so that this
* program doesn't need to be called more than once per device */
udev_builtin_add_property(dev, test, "ID_INPUT", "1");
get_cap_mask(dev, pdev, "capabilities/ev", bitmask_ev, sizeof(bitmask_ev), test);
get_cap_mask(dev, pdev, "capabilities/abs", bitmask_abs, sizeof(bitmask_abs), test);
get_cap_mask(dev, pdev, "capabilities/rel", bitmask_rel, sizeof(bitmask_rel), test);
get_cap_mask(dev, pdev, "capabilities/key", bitmask_key, sizeof(bitmask_key), test);
test_pointers(dev, bitmask_ev, bitmask_abs, bitmask_key, bitmask_rel, test);
test_key(dev, bitmask_ev, bitmask_key, test);
return EXIT_SUCCESS;
}
示例2: IsJoystick
static int
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
{
struct input_id inpid;
Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);
#if !SDL_USE_LIBUDEV
/* When udev is enabled we only get joystick devices here, so there's no need to test them */
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)) {
return (0);
}
if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) {
return 0;
}
#endif
if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
return 0;
}
if (ioctl(fd, EVIOCGID, &inpid) < 0) {
return 0;
}
#ifdef DEBUG_JOYSTICK
printf("Joystick: %s, bustype = %d, vendor = 0x%x, product = 0x%x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
#endif
SDL_memset(guid->data, 0, sizeof(guid->data));
/* We only need 16 bits for each of these; space them out to fill 128. */
/* Byteswap so devices get same GUID on little/big endian platforms. */
*(guid16++) = SDL_SwapLE16(inpid.bustype);
*(guid16++) = 0;
if (inpid.vendor && inpid.product && inpid.version) {
*(guid16++) = SDL_SwapLE16(inpid.vendor);
*(guid16++) = 0;
*(guid16++) = SDL_SwapLE16(inpid.product);
*(guid16++) = 0;
*(guid16++) = SDL_SwapLE16(inpid.version);
*(guid16++) = 0;
} else {
SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4);
}
return 1;
}
示例3: EVIOCGBIT
void JoypadLinux::setup_joypad_properties(int p_id) {
Joypad *joy = &joypads[p_id];
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
int num_buttons = 0;
int num_axes = 0;
if ((ioctl(joy->fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
(ioctl(joy->fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
return;
}
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
if (test_bit(i, keybit)) {
joy->key_map[i] = num_buttons++;
}
}
for (int i = BTN_MISC; i < BTN_JOYSTICK; ++i) {
if (test_bit(i, keybit)) {
joy->key_map[i] = num_buttons++;
}
}
for (int i = 0; i < ABS_MISC; ++i) {
/* Skip hats */
if (i == ABS_HAT0X) {
i = ABS_HAT3Y;
continue;
}
if (test_bit(i, absbit)) {
joy->abs_map[i] = num_axes++;
joy->abs_info[i] = memnew(input_absinfo);
if (ioctl(joy->fd, EVIOCGABS(i), joy->abs_info[i]) < 0) {
memdelete(joy->abs_info[i]);
joy->abs_info[i] = NULL;
}
}
}
joy->force_feedback = false;
joy->ff_effect_timestamp = 0;
unsigned long ffbit[NBITS(FF_CNT)];
if (ioctl(joy->fd, EVIOCGBIT(EV_FF, sizeof(ffbit)), ffbit) != -1) {
if (test_bit(FF_RUMBLE, ffbit)) {
joy->force_feedback = true;
}
}
}
示例4: main
int main (int argc, char** argv)
{
struct udev *udev;
struct udev_device *dev;
char devpath[PATH_MAX];
unsigned long bitmask_ev[NBITS(EV_MAX)];
unsigned long bitmask_abs[NBITS(ABS_MAX)];
unsigned long bitmask_key[NBITS(KEY_MAX)];
unsigned long bitmask_rel[NBITS(REL_MAX)];
if (argc != 2) {
fprintf(stderr, "Usage: %s <device path (without /sys)>\n", argv[0]);
exit(1);
}
/* get the device */
udev = udev_new();
if (udev == NULL)
return 1;
snprintf(devpath, sizeof(devpath), "%s/%s", udev_get_sys_path(udev), argv[1]);
dev = udev_device_new_from_syspath(udev, devpath);
if (dev == NULL) {
fprintf(stderr, "unable to access '%s'\n", devpath);
return 1;
}
/* walk up the parental chain until we find the real input device; the
* argument is very likely a subdevice of this, like eventN */
while (dev != NULL && udev_device_get_sysattr_value(dev, "capabilities/ev") == NULL)
dev = udev_device_get_parent_with_subsystem_devtype(dev, "input", NULL);
/* not an "input" class device */
if (dev == NULL)
return 0;
/* Use this as a flag that input devices were detected, so that this
* program doesn't need to be called more than once per device */
puts("ID_INPUT=1");
get_cap_mask (dev, "capabilities/ev", bitmask_ev, sizeof (bitmask_ev));
get_cap_mask (dev, "capabilities/abs", bitmask_abs, sizeof (bitmask_abs));
get_cap_mask (dev, "capabilities/rel", bitmask_rel, sizeof (bitmask_rel));
get_cap_mask (dev, "capabilities/key", bitmask_key, sizeof (bitmask_key));
test_pointers(bitmask_ev, bitmask_abs, bitmask_key, bitmask_rel);
test_key(bitmask_ev, bitmask_key);
return 0;
}
示例5: chantodepth
int
chantodepth(ulong c)
{
int n;
for(n=0; c; c>>=8){
if(TYPE(c) >= NChan || NBITS(c) > 8 || NBITS(c) <= 0)
return 0;
n += NBITS(c);
}
if(n==0 || (n>8 && n%8) || (n<8 && 8%n))
return 0;
return n;
}
示例6: builtin_input_id
static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], bool test) {
struct udev_device *pdev;
unsigned long bitmask_ev[NBITS(EV_MAX)];
unsigned long bitmask_abs[NBITS(ABS_MAX)];
unsigned long bitmask_key[NBITS(KEY_MAX)];
unsigned long bitmask_rel[NBITS(REL_MAX)];
unsigned long bitmask_props[NBITS(INPUT_PROP_MAX)];
const char *sysname, *devnode;
bool is_pointer;
bool is_key;
assert(dev);
/* walk up the parental chain until we find the real input device; the
* argument is very likely a subdevice of this, like eventN */
pdev = dev;
while (pdev != NULL && udev_device_get_sysattr_value(pdev, "capabilities/ev") == NULL)
pdev = udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
if (pdev) {
/* Use this as a flag that input devices were detected, so that this
* program doesn't need to be called more than once per device */
udev_builtin_add_property(dev, test, "ID_INPUT", "1");
get_cap_mask(dev, pdev, "capabilities/ev", bitmask_ev, sizeof(bitmask_ev), test);
get_cap_mask(dev, pdev, "capabilities/abs", bitmask_abs, sizeof(bitmask_abs), test);
get_cap_mask(dev, pdev, "capabilities/rel", bitmask_rel, sizeof(bitmask_rel), test);
get_cap_mask(dev, pdev, "capabilities/key", bitmask_key, sizeof(bitmask_key), test);
get_cap_mask(dev, pdev, "properties", bitmask_props, sizeof(bitmask_props), test);
is_pointer = test_pointers(dev, bitmask_ev, bitmask_abs,
bitmask_key, bitmask_rel,
bitmask_props, test);
is_key = test_key(dev, bitmask_ev, bitmask_key, test);
/* Some evdev nodes have only a scrollwheel */
if (!is_pointer && !is_key && test_bit(EV_REL, bitmask_ev) &&
(test_bit(REL_WHEEL, bitmask_rel) || test_bit(REL_HWHEEL, bitmask_rel)))
udev_builtin_add_property(dev, test, "ID_INPUT_KEY", "1");
if (test_bit(EV_SW, bitmask_ev))
udev_builtin_add_property(dev, test, "ID_INPUT_SWITCH", "1");
}
devnode = udev_device_get_devnode(dev);
sysname = udev_device_get_sysname(dev);
if (devnode && sysname && startswith(sysname, "event"))
extract_info(dev, devnode, test);
return EXIT_SUCCESS;
}
示例7: chantostr
char*
chantostr(char *buf, ulong cc)
{
ulong c, rc;
char *p;
if(chantodepth(cc) == 0)
return nil;
/* reverse the channel descriptor so we can easily generate the string in the right order */
rc = 0;
for(c=cc; c; c>>=8){
rc <<= 8;
rc |= c&0xFF;
}
p = buf;
for(c=rc; c; c>>=8) {
*p++ = channames[TYPE(c)];
*p++ = '0'+NBITS(c);
}
*p = 0;
return buf;
}
示例8: check_mouse
// Check for EV_REL (REL_X and REL_Y) and, because touchscreens can have those too,
// check also for EV_KEY (BTN_LEFT and BTN_RIGHT)
static void check_mouse(int fd)
{
if (has_mouse) {
return;
}
unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
memset(bit, 0, sizeof(bit));
ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);
if (!test_bit(EV_REL, bit[0]) || !test_bit(EV_KEY, bit[0])) {
return;
}
ioctl(fd, EVIOCGBIT(EV_REL, KEY_MAX), bit[EV_REL]);
if (!test_bit(REL_X, bit[EV_REL]) || !test_bit(REL_Y, bit[EV_REL])) {
return;
}
ioctl(fd, EVIOCGBIT(EV_KEY, KEY_MAX), bit[EV_KEY]);
if (!test_bit(BTN_LEFT, bit[EV_KEY]) || !test_bit(BTN_RIGHT, bit[EV_KEY])) {
return;
}
has_mouse = 1;
}
示例9: getTouchBounds
void InputEventSystem::getTouchBounds(int fd)
{
unsigned long bits[NBITS(KEY_MAX)];
struct input_absinfo abs;
ioctl (fd, EVIOCGBIT (EV_ABS, KEY_MAX), bits);
if (!(test_bit (ABS_MT_POSITION_X, bits) &&
test_bit (ABS_MT_POSITION_Y, bits)))
{
DOUT("absolute events");
ioctl (fd, EVIOCGABS (ABS_X), &abs);
minX = abs.minimum;
maxX = abs.maximum;
ioctl (fd, EVIOCGABS (ABS_Y), &abs);
minY = abs.minimum;
maxY = abs.maximum;
DOUT("NO multitouch");
}
else
{
DOUT("absolute multitouch events");
ioctl (fd, EVIOCGABS (ABS_MT_POSITION_X), &abs);
minX = abs.minimum;
maxX = abs.maximum;
ioctl (fd, EVIOCGABS (ABS_MT_POSITION_Y), &abs);
minY = abs.minimum;
maxY = abs.maximum;
DOUT("HAS multitouch");
}
dx = maxX - minX;
dy = maxY - minY;
}
示例10: openfd
int openfd(void)
{
int fd;
const char *dirname = "/dev/input";
DIR *dir;
if ((dir = opendir(dirname))) {
struct dirent *de;
unsigned long caps[NBITS(SW_TABLET_MODE+1)];
while ((de = readdir(dir))) {
if (de->d_name[0] != 'e') // eventX
continue;
char name[PATH_MAX];
snprintf(name, PATH_MAX, "%s/%s", dirname, de->d_name);
fd = open(name, O_RDONLY);
if (fd < 0) {
ALOGE("could not open %s, %s", name, strerror(errno));
continue;
}
memset(caps, 0, sizeof(caps));
if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof(caps)), caps) < 1) {
ALOGE("could not get device caps for %s, %s\n", name, strerror(errno));
continue;
}
if (test_bit(SW_TABLET_MODE, caps)) {
ALOGI("open %s(%s) ok", de->d_name, name);
return fd;
}
close(fd);
}
closedir(dir);
}
return -1;
}
示例11: set_resolution_params
/*
* set_resolution_params()
*
* Due to usage of multiple display related APIs resolution data is located in
* more than one place. This function updates them all.
*/
static void set_resolution_params(int x, int y)
{
panel_cfg.lcd_size = PANEL_LCD_SIZE(x, y);
panel_info.vl_col = x;
panel_info.vl_row = y;
lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
}
示例12: EV_IsJoystick
static int EV_IsJoystick(int fd)
{
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) ) {
return(0);
}
if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit) &&
(test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_A, keybit) || test_bit(BTN_1, keybit)))) return 0;
return(1);
}
示例13: print_device_info
static int print_device_info(int fd) {
int i, j;
int version;
unsigned short id[4];
unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
if (ioctl(fd, EVIOCGVERSION, &version)) {
perror("can't get version");
return 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]);
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\n", i);
if (!i) continue;
ioctl(fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
for (j = 0; j < KEY_MAX; j++) {
if (test_bit(j, bit[i])) {
printf("%d, ", j);
}
}
printf("\n");
}
}
return 0;
}
示例14: pxafb_init_mem
static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid)
{
u_long palette_mem_size;
struct pxafb_info *fbi = &vid->pxa;
int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8;
fbi->screen = (u_long)lcdbase;
fbi->palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
palette_mem_size = fbi->palette_size * sizeof(u16);
debug("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
/* locate palette and descs at end of page following fb */
fbi->palette = (u_long)lcdbase + fb_size + PAGE_SIZE - palette_mem_size;
return 0;
}
示例15: epdc_ctrl_init
int epdc_ctrl_init(void *lcdbase)
{
/*
* We rely on lcdbase being a physical address, i.e., either MMU off,
* or 1-to-1 mapping. Might want to add some virt2phys here.
*/
if (!lcdbase)
return -1;
eink_color_fg = 0xFF;
eink_color_bg = 0xFF;
/* Reset */
REG_SET(EPDC_BASE, EPDC_CTRL, EPDC_CTRL_SFTRST);
while (!(REG_RD(EPDC_BASE, EPDC_CTRL) & EPDC_CTRL_CLKGATE))
;
REG_CLR(EPDC_BASE, EPDC_CTRL, EPDC_CTRL_SFTRST);
/* Enable clock gating (clear to enable) */
REG_CLR(EPDC_BASE, EPDC_CTRL, EPDC_CTRL_CLKGATE);
while (REG_RD(EPDC_BASE, EPDC_CTRL) &
(EPDC_CTRL_SFTRST | EPDC_CTRL_CLKGATE))
;
debug("resolution %dx%d, bpp %d\n", (int)panel_info.vl_col,
(int)panel_info.vl_row, NBITS(panel_info.vl_bpix));
/* Set framebuffer pointer */
REG_WR(EPDC_BASE, EPDC_UPD_ADDR, (u32)lcdbase);
#if 0
/* Set Working Buffer pointer */
REG_WR(EPDC_BASE, EPDC_WB_ADDR, panel_info.epdc_data.working_buf_addr);
/* Set Waveform Buffer pointer */
REG_WR(EPDC_BASE, EPDC_WVADDR, panel_info.epdc_data.waveform_buf_addr);
#endif
/* Set waveform and working buffer, they will be changed later */
REG_WR(EPDC_BASE, EPDC_WVADDR, (unsigned long)CONFIG_TEMP_INIT_WAVEFORM_ADDR);
REG_WR(EPDC_BASE, EPDC_WB_ADDR, (unsigned long)CONFIG_WORKING_BUF_ADDR);
#if 0
/* Get waveform data address and offset */
int data_offs = setup_waveform_file();
if(data_offs == -1) {
printf("Can't load waveform data!\n");
return -1;
}
#endif
/* Initialize EPDC, passing pointer to EPDC registers */
epdc_init_settings();
epdc_initialized = 1;
return;
}