LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2014, 03:02 AM   #1
magnus.therning
LQ Newbie
 
Registered: Jul 2006
Location: Gothenburg
Posts: 21

Rep: Reputation: 0
uinput: any complete example?


On a system running embedded linux I have a device connected to a rotary encoded (/dev/input/rotary). Now I'm trying to mimick such a device on a desktop by using uinput, but I'm having trouble with the most basic test.

My writer of events looks like this (with error handling removed):

Code:
int main(int ac, char **av)
{
    int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
    int ret = ioctl(fd, UI_SET_EVBIT, EV_ABS);
    ret = ioctl(fd, UI_SET_ABSBIT, ABS_X);

    struct uinput_user_dev uidev = {0};
    snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-rotary");
    uidev.absmin[ABS_X] = 0;
    uidev.absmax[ABS_X] = 255;
    ret = write(fd, &uidev, sizeof(uidev));
    ret = ioctl(fd, UI_DEV_CREATE);

    struct input_event ev = {0};
    ev.type = EV_ABS;
    ev.code = ABS_X;
    ev.value = 42;

    ret = write(fd, &ev, sizeof(ev));

    getchar();

    ret = ioctl(fd, UI_DEV_DESTROY);
    return EXIT_SUCCESS;
}
The reader of events looks this (also with error handling removed):
Code:
int main(int ac, char **av)
{
    int fd = open(av[1], O_RDONLY);

    char name[256] = "unknown";
    ioctl(fd, EVIOCGNAME(sizeof(name)), name);
    printf("reading from %s\n", name);

    struct input_event ev = {0};
    int ret = read(fd, &ev, sizeof(ev));
    printf("Read an event! %i\n", ret);
    printf("ev.time.tv_sec: %li\n", ev.time.tv_sec);
    printf("ev.time.tv_usec: %li\n", ev.time.tv_usec);
    printf("ev.type: %hi\n", ev.type);
    printf("ev.code: %hi\n", ev.code);
    printf("ev.value: %li\n", ev.value);

    return EXIT_SUCCESS;
}
The output from the reader is not at all what I expected:

Code:
% ./reader /dev/input/js0
reading from unknown
Read an event! 8
ev.time.tv_sec: 36732490196071166
ev.time.tv_usec: 0
ev.type: 0
ev.code: 0
ev.value: 0
The reader seems to work on other inputs, I've tried it on the keyboard:

Code:
% sudo ./reader /dev/input/by-path/platform-i8042-serio-0-event-kbd
reading from AT Translated Set 2 keyboard
Yay! Read an event! 24
ev.time.tv_sec: 1414918317
ev.time.tv_usec: 328181
ev.type: 4
ev.code: 4
ev.value: 28
So, what am I missing in my usage of uinput?
 
  


Reply

Tags
event, input, linux



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to use /dev/uinput to turn on integrated webcam vomv1988 Linux - Software 1 04-07-2013 10:33 PM
uInput device with keyboard and mouse capabilities seems stuck Viniesta Linux - General 0 10-25-2012 03:34 AM
uinput help echo36 Programming 1 11-30-2009 11:55 PM
Issues with a kernel mod (UINPUT) monkiidansu Linux - Software 2 08-12-2007 02:16 PM
Bad news for uinput (2.6.x) users (horribly arcane issue) evilDagmar Slackware 6 12-23-2006 11:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration