Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
0002 .. c:namespace:: RC
0003 
0004 .. _lirc-write:
0005 
0006 ************
0007 LIRC write()
0008 ************
0009 
0010 Name
0011 ====
0012 
0013 lirc-write - Write to a LIRC device
0014 
0015 Synopsis
0016 ========
0017 
0018 .. code-block:: c
0019 
0020     #include <unistd.h>
0021 
0022 .. c:function:: ssize_t write( 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 with data to be written
0032 
0033 ``count``
0034     Number of bytes at the buffer
0035 
0036 Description
0037 ===========
0038 
0039 :c:func:`write()` writes up to ``count`` bytes to the device
0040 referenced by the file descriptor ``fd`` from the buffer starting at
0041 ``buf``.
0042 
0043 The exact format of the data depends on what mode a driver is in, use
0044 :ref:`lirc_get_features` to get the supported modes and use
0045 :ref:`lirc_set_send_mode` set the mode.
0046 
0047 When in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to
0048 the chardev is a pulse/space sequence of integer values. Pulses and spaces
0049 are only marked implicitly by their position. The data must start and end
0050 with a pulse, therefore, the data must always include an uneven number of
0051 samples. The write function blocks until the data has been transmitted
0052 by the hardware. If more data is provided than the hardware can send, the
0053 driver returns ``EINVAL``.
0054 
0055 When in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one
0056 ``struct lirc_scancode`` must be written to the chardev at a time, else
0057 ``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,
0058 and the :ref:`IR protocol <Remote_controllers_Protocols>` in the
0059 :c:type:`rc_proto`: member. All other members must be
0060 set to 0, else ``EINVAL`` is returned. If there is no protocol encoder
0061 for the protocol or the scancode is not valid for the specified protocol,
0062 ``EINVAL`` is returned. The write function blocks until the scancode
0063 is transmitted by the hardware.
0064 
0065 Return Value
0066 ============
0067 
0068 On success, the number of bytes written is returned. It is not an error if
0069 this number is smaller than the number of bytes requested, or the amount
0070 of data required for one frame.  On error, -1 is returned, and the ``errno``
0071 variable is set appropriately. The generic error codes are described at the
0072 :ref:`Generic Error Codes <gen-errors>` chapter.