0001 .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
0002 .. c:namespace:: RC
0003
0004 .. _lirc-read:
0005
0006 ***********
0007 LIRC read()
0008 ***********
0009
0010 Name
0011 ====
0012
0013 lirc-read - Read from a LIRC device
0014
0015 Synopsis
0016 ========
0017
0018 .. code-block:: c
0019
0020 #include <unistd.h>
0021
0022 .. c:function:: ssize_t read( int fd, void *buf, size_t count )
0023
0024 Arguments
0025 =========
0026
0027 ``fd``
0028 File descriptor returned by ``open()``.
0029
0030 ``buf``
0031 Buffer to be filled
0032
0033 ``count``
0034 Max number of bytes to read
0035
0036 Description
0037 ===========
0038
0039 :c:func:`read()` attempts to read up to ``count`` bytes from file
0040 descriptor ``fd`` into the buffer starting at ``buf``. If ``count`` is zero,
0041 :c:func:`read()` returns zero and has no other results. If ``count``
0042 is greater than ``SSIZE_MAX``, the result is unspecified.
0043
0044 The exact format of the data depends on what :ref:`lirc_modes` a driver
0045 uses. Use :ref:`lirc_get_features` to get the supported mode, and use
0046 :ref:`lirc_set_rec_mode` set the current active mode.
0047
0048 The mode :ref:`LIRC_MODE_MODE2 <lirc-mode-mode2>` is for raw IR,
0049 in which packets containing an unsigned int value describing an IR signal are
0050 read from the chardev.
0051
0052 Alternatively, :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` can be available,
0053 in this mode scancodes which are either decoded by software decoders, or
0054 by hardware decoders. The :c:type:`rc_proto` member is set to the
0055 :ref:`IR protocol <Remote_controllers_Protocols>`
0056 used for transmission, and ``scancode`` to the decoded scancode,
0057 and the ``keycode`` set to the keycode or ``KEY_RESERVED``.
0058
0059 Return Value
0060 ============
0061
0062 On success, the number of bytes read is returned. It is not an error if
0063 this number is smaller than the number of bytes requested, or the amount
0064 of data required for one frame. On error, -1 is returned, and the ``errno``
0065 variable is set appropriately.