73 lines · plain
1.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later2.. c:namespace:: RC3 4.. _lirc-write:5 6************7LIRC write()8************9 10Name11====12 13lirc-write - Write to a LIRC device14 15Synopsis16========17 18.. code-block:: c19 20 #include <unistd.h>21 22.. c:function:: ssize_t write( int fd, void *buf, size_t count )23 24Arguments25=========26 27``fd``28 File descriptor returned by ``open()``.29 30``buf``31 Buffer with data to be written32 33``count``34 Number of bytes at the buffer35 36Description37===========38 39:c:func:`write()` writes up to ``count`` bytes to the device40referenced by the file descriptor ``fd`` from the buffer starting at41``buf``.42 43The exact format of the data depends on what mode a driver is in, use44:ref:`lirc_get_features` to get the supported modes and use45:ref:`lirc_set_send_mode` set the mode.46 47When in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to48the chardev is a pulse/space sequence of integer values. Pulses and spaces49are only marked implicitly by their position. The data must start and end50with a pulse, therefore, the data must always include an uneven number of51samples. The write function blocks until the data has been transmitted52by the hardware. If more data is provided than the hardware can send, the53driver returns ``EINVAL``.54 55When in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one56``struct lirc_scancode`` must be written to the chardev at a time, else57``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,58and the :ref:`IR protocol <Remote_controllers_Protocols>` in the59:c:type:`rc_proto`: member. All other members must be60set to 0, else ``EINVAL`` is returned. If there is no protocol encoder61for the protocol or the scancode is not valid for the specified protocol,62``EINVAL`` is returned. The write function blocks until the scancode63is transmitted by the hardware.64 65Return Value66============67 68On success, the number of bytes written is returned. It is not an error if69this number is smaller than the number of bytes requested, or the amount70of data required for one frame. On error, -1 is returned, and the ``errno``71variable is set appropriately. The generic error codes are described at the72:ref:`Generic Error Codes <gen-errors>` chapter.73