162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci.. c:namespace:: RC
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci.. _lirc-write:
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci************
762306a36Sopenharmony_ciLIRC write()
862306a36Sopenharmony_ci************
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciName
1162306a36Sopenharmony_ci====
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cilirc-write - Write to a LIRC device
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciSynopsis
1662306a36Sopenharmony_ci========
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci.. code-block:: c
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci    #include <unistd.h>
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci.. c:function:: ssize_t write( int fd, void *buf, size_t count )
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciArguments
2562306a36Sopenharmony_ci=========
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci``fd``
2862306a36Sopenharmony_ci    File descriptor returned by ``open()``.
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci``buf``
3162306a36Sopenharmony_ci    Buffer with data to be written
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci``count``
3462306a36Sopenharmony_ci    Number of bytes at the buffer
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciDescription
3762306a36Sopenharmony_ci===========
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci:c:func:`write()` writes up to ``count`` bytes to the device
4062306a36Sopenharmony_cireferenced by the file descriptor ``fd`` from the buffer starting at
4162306a36Sopenharmony_ci``buf``.
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ciThe exact format of the data depends on what mode a driver is in, use
4462306a36Sopenharmony_ci:ref:`lirc_get_features` to get the supported modes and use
4562306a36Sopenharmony_ci:ref:`lirc_set_send_mode` set the mode.
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ciWhen in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to
4862306a36Sopenharmony_cithe chardev is a pulse/space sequence of integer values. Pulses and spaces
4962306a36Sopenharmony_ciare only marked implicitly by their position. The data must start and end
5062306a36Sopenharmony_ciwith a pulse, therefore, the data must always include an uneven number of
5162306a36Sopenharmony_cisamples. The write function blocks until the data has been transmitted
5262306a36Sopenharmony_ciby the hardware. If more data is provided than the hardware can send, the
5362306a36Sopenharmony_cidriver returns ``EINVAL``.
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciWhen in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one
5662306a36Sopenharmony_ci``struct lirc_scancode`` must be written to the chardev at a time, else
5762306a36Sopenharmony_ci``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,
5862306a36Sopenharmony_ciand the :ref:`IR protocol <Remote_controllers_Protocols>` in the
5962306a36Sopenharmony_ci:c:type:`rc_proto`: member. All other members must be
6062306a36Sopenharmony_ciset to 0, else ``EINVAL`` is returned. If there is no protocol encoder
6162306a36Sopenharmony_cifor the protocol or the scancode is not valid for the specified protocol,
6262306a36Sopenharmony_ci``EINVAL`` is returned. The write function blocks until the scancode
6362306a36Sopenharmony_ciis transmitted by the hardware.
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciReturn Value
6662306a36Sopenharmony_ci============
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ciOn success, the number of bytes written is returned. It is not an error if
6962306a36Sopenharmony_cithis number is smaller than the number of bytes requested, or the amount
7062306a36Sopenharmony_ciof data required for one frame.  On error, -1 is returned, and the ``errno``
7162306a36Sopenharmony_civariable is set appropriately. The generic error codes are described at the
7262306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
73