xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/rc/lirc-read.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2*4882a593Smuzhiyun.. c:namespace:: RC
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun.. _lirc-read:
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun***********
7*4882a593SmuzhiyunLIRC read()
8*4882a593Smuzhiyun***********
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunName
11*4882a593Smuzhiyun====
12*4882a593Smuzhiyun
13*4882a593Smuzhiyunlirc-read - Read from a LIRC device
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSynopsis
16*4882a593Smuzhiyun========
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun.. code-block:: c
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun    #include <unistd.h>
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun.. c:function:: ssize_t read( int fd, void *buf, size_t count )
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunArguments
25*4882a593Smuzhiyun=========
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun``fd``
28*4882a593Smuzhiyun    File descriptor returned by ``open()``.
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun``buf``
31*4882a593Smuzhiyun   Buffer to be filled
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun``count``
34*4882a593Smuzhiyun   Max number of bytes to read
35*4882a593Smuzhiyun
36*4882a593SmuzhiyunDescription
37*4882a593Smuzhiyun===========
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun:c:func:`read()` attempts to read up to ``count`` bytes from file
40*4882a593Smuzhiyundescriptor ``fd`` into the buffer starting at ``buf``.  If ``count`` is zero,
41*4882a593Smuzhiyun:c:func:`read()` returns zero and has no other results. If ``count``
42*4882a593Smuzhiyunis greater than ``SSIZE_MAX``, the result is unspecified.
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunThe exact format of the data depends on what :ref:`lirc_modes` a driver
45*4882a593Smuzhiyunuses. Use :ref:`lirc_get_features` to get the supported mode, and use
46*4882a593Smuzhiyun:ref:`lirc_set_rec_mode` set the current active mode.
47*4882a593Smuzhiyun
48*4882a593SmuzhiyunThe mode :ref:`LIRC_MODE_MODE2 <lirc-mode-mode2>` is for raw IR,
49*4882a593Smuzhiyunin which packets containing an unsigned int value describing an IR signal are
50*4882a593Smuzhiyunread from the chardev.
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunAlternatively, :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` can be available,
53*4882a593Smuzhiyunin this mode scancodes which are either decoded by software decoders, or
54*4882a593Smuzhiyunby hardware decoders. The :c:type:`rc_proto` member is set to the
55*4882a593Smuzhiyun:ref:`IR protocol <Remote_controllers_Protocols>`
56*4882a593Smuzhiyunused for transmission, and ``scancode`` to the decoded scancode,
57*4882a593Smuzhiyunand the ``keycode`` set to the keycode or ``KEY_RESERVED``.
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunReturn Value
60*4882a593Smuzhiyun============
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunOn success, the number of bytes read is returned. It is not an error if
63*4882a593Smuzhiyunthis number is smaller than the number of bytes requested, or the amount
64*4882a593Smuzhiyunof data required for one frame.  On error, -1 is returned, and the ``errno``
65*4882a593Smuzhiyunvariable is set appropriately.
66