linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aniroop Mathur <aniroop.mathur@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "linux-input@vger.kernel.org" <linux-input@vger.kernel.org>
Subject: Re: [Question: Drivers/input/evdev.c] What is the use of write function in evdev_fops?
Date: Thu, 14 Aug 2014 00:58:46 +0530	[thread overview]
Message-ID: <CADYu308G3_50JTEfwOnRy4U4x8U_FTpuxqLhHqmqWiCAwAYH7w@mail.gmail.com> (raw)
In-Reply-To: <a3bd7d64-136e-42ea-98ca-e7992b48cc01@email.android.com>

On Thu, Aug 14, 2014 at 12:50 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On August 13, 2014 12:10:16 PM PDT, Aniroop Mathur <aniroop.mathur@gmail.com> wrote:
>>On Thu, Aug 14, 2014 at 12:28 AM, Dmitry Torokhov
>><dmitry.torokhov@gmail.com> wrote:
>>> On Wed, Aug 13, 2014 at 11:41:20PM +0530, Aniroop Mathur wrote:
>>>> Hello Mr. Torokhov :)
>>>>
>>>> On Wed, Aug 13, 2014 at 10:36 PM, Dmitry Torokhov
>>>> <dmitry.torokhov@gmail.com> wrote:
>>>> > Hi Aniroop,
>>>> >
>>>> > On Wed, Aug 13, 2014 at 10:16:34PM +0530, Aniroop Mathur wrote:
>>>> >> Dear Mr. Torokhov and Linux-Input Community,
>>>> >> Greetings of the day !! :)
>>>> >>
>>>> >> I have not seen some good use of write function in input
>>subsystem.
>>>> >> I am trying find the good uses of write function in Input
>>subsystem,
>>>> >> but could not find the solution over internet.
>>>> >> Can you please help in answering my query below:
>>>> >>
>>>> >> As you know, in evdev.c file, fops is defined as below
>>>> >> struct file_operations evdev_fops = {
>>>> >> .read           = evdev_read,
>>>> >> .write          = evdev_write,
>>>> >> ...
>>>> >> }
>>>> >>
>>>> >> So in what cases, evdev_write function is used ?
>>>> >> One case I can think of is that, it can be used in input device
>>simulator
>>>> >> to write the recorded data back into buffer.
>>>> >
>>>> > You are right, majority of times you are reading from the buffer.
>>Still,
>>>> > sometimes you want to control hardware state, for example, toggle
>>keyboard LED.
>>>> > That can be achieved by writing appropriate event to the event
>>device.
>>>> >
>>>>
>>>> Okay. :)
>>>> So it means application upon receiving some key value,
>>>> it can write EV_LED type of event to keyboard input device node
>>>> and if  dev->event function is defined in driver, driver can request
>>>> hardware to toggle led.
>>>> Similarly, it can be done for cases like sound (EV_SND, force
>>>> feedback(EV_FF), etc
>>>> Right ?
>>>
>>> Yes.
>>>
>>>>
>>>> > For simulators I think uinput is suited the best.
>>>> >
>>>>
>>>> As i know, in case of uinput, there is only one device node
>>>> /dev/uinput or /dev/input/uinput.
>>>> and to distinguish the events, we can use event type and code.
>>>>
>>>> But, if we are simulating multiple devices together like
>>>> accelerometer, gyro, mag, light, compass, etc
>>>> then any two devices can have same event type and code.
>>>> Like accel and gyro can both have EV_REL and REL_X/Y/Z.
>>>> In such a case, we won't be able to distinguish between accel and
>>gyro events.
>>>>
>>>> Instead if we use accel and gyro separate device nodes,
>>>> there is no such problem because device nodes itself are different.
>>:)
>>>> So for such case, I think simulation through proper device node is
>>better.
>>>
>>> Even though there is only one /dev/input/uinput every user (an entity
>>> opening that device node) will end up creating it's very own and
>>> separate input device, with separate bitmasks, events, etc, etc.
>>>
>>
>>How to use bitmasks to distinguish between two events ?
>>In below code, I can only see type and code as
>>identification variables.
>>Can we use bitmask too here ?
>>
>>fd = open("/dev/uinput", O_RDWR);
>>
>
> You need to open 2 separate file descriptors.
>

2 separate file descriptors like below ?
int fd1 = open("/dev/uinput", O_RDWR);
int fd2 = open("/dev/uinput", O_RDWR);

But my reading data will still come in struct input_event as mentioned above.
It has only time, type, code and value.
So, how we can use bitmask here ?

struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
 };

  reply	other threads:[~2014-08-13 19:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-13 16:46 [Question: Drivers/input/evdev.c] What is the use of write function in evdev_fops? Aniroop Mathur
2014-08-13 17:06 ` Dmitry Torokhov
2014-08-13 18:11   ` Aniroop Mathur
2014-08-13 18:58     ` Dmitry Torokhov
2014-08-13 19:10       ` Aniroop Mathur
2014-08-13 19:20         ` Dmitry Torokhov
2014-08-13 19:28           ` Aniroop Mathur [this message]
2014-08-13 19:42             ` Dmitry Torokhov
2014-08-13 20:03               ` Aniroop Mathur
2014-08-14 19:25               ` Aniroop Mathur
2014-08-14 20:19                 ` Dmitry Torokhov
2014-08-14 20:31                   ` Aniroop Mathur
2014-08-18  1:57                     ` Peter Hutterer
2014-08-18 16:04                       ` Aniroop Mathur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADYu308G3_50JTEfwOnRy4U4x8U_FTpuxqLhHqmqWiCAwAYH7w@mail.gmail.com \
    --to=aniroop.mathur@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).